Skip to content

resolve symlinks before reading solution files#356

Merged
kytrinyx merged 1 commit intomasterfrom
follow_symlinks
Nov 28, 2016
Merged

resolve symlinks before reading solution files#356
kytrinyx merged 1 commit intomasterfrom
follow_symlinks

Conversation

@lcowell
Copy link
Copy Markdown
Contributor

@lcowell lcowell commented Nov 8, 2016

Resolves symlinks before reading file contents in. This should be OS
independent as I'm using the filepath package to resolve the symlink.

Fixes #354

@Tonkpils
Copy link
Copy Markdown
Contributor

Tonkpils commented Nov 8, 2016

I thought we were doing this already somewhere. However, from my understanding of #354, the issue was that the name of the file we were using to submit was the one of the original file rather than the one from the symlink. Does this correct that issue?

@lcowell
Copy link
Copy Markdown
Contributor Author

lcowell commented Nov 8, 2016

Yeah, it looks like ioutil.Readfile may be resolving symlinks already.

I misunderstood the original issue. Let me take another look at this.

@lcowell
Copy link
Copy Markdown
Contributor Author

lcowell commented Nov 12, 2016

@Insti @Tonkpils I've pushed up a test to verify the name. It looks like the CLI is already doing the right thing and is using the name of the symlink. This test passes with or without the code I added.

Can someone see what I've done wrong? Is this a non-issue?

@kytrinyx
Copy link
Copy Markdown
Member

Can someone see what I've done wrong?

I can't.

Is this a non-issue?

Maybe?

@Insti would you weigh in here, since you reported the original issue? I think we may have a gap in our understanding of the problem.

@Tonkpils
Copy link
Copy Markdown
Contributor

Tonkpils commented Nov 12, 2016

The original issue was this:

Original file name: foo_awesome.rb
Symlink name: foo_link.rb -> foo_awesome.rb

$ exercism submit foo_link.rb

The submitted file name is foo_awesome.rb instead of foo_link.rb.

What @Insti was referring to is that he expected the argument passed to submit to be the name of the file rather than the file linked to.

@Insti
Copy link
Copy Markdown

Insti commented Nov 12, 2016

@Tonkpils has summarised the issue correctly.

@Insti
Copy link
Copy Markdown

Insti commented Nov 12, 2016

I suspect the problem is here:

https://github.com/exercism/cli/blob/follow_symlinks/cmd/submit.go#L78-L85

The symlink is resolved, but the original name is not kept.

Given that the new TestFollowSymlink shows that NewIteration does what is expected and follows symlinks correctly, can we just delete lines 78-85 in submit.go and have it all work?

I don't currently have a Go development environment set up to check this myself.

@Tonkpils
Copy link
Copy Markdown
Contributor

Given that the new TestFollowSymlink shows that NewIteration does what is expected and follows symlinks correctly, can we just delete lines 78-85 in submit.go and have it all work?

Ah, so we're EvalSymlink twice, once in submit.go and once in iteration.go. I think it'd be safe to do what you suggested, we can still maintain the symlink for the debug output purpose but send the original filename. We should also rename that variable file to filename to be more clear that it's the name of the file and not the contents of it.

Preserves filename of symlink rather than replacing filename with what the
symlink links to.

Fixes #354
@lcowell
Copy link
Copy Markdown
Contributor Author

lcowell commented Nov 13, 2016

Thanks @Insti I didn't even think to check that the outer loop would be resolving the symlinks.

I've squashed the commits down to what really needed to happen. I didn't change any code in iteration.go, but I've left the test in there because it documents the desired behaviour. Let me know if you think that should be removed.

@Insti
Copy link
Copy Markdown

Insti commented Nov 13, 2016

Great.

I'm usually in favour of more tests, but is the test actually testing anything that is not already tested? (Other than if ioutil.ReadFile(filename) is doing the right thing following symlinks? Which isn't our job to test.)

I'd rather see a test that detected the original bug(?) in submit.go prematurely resolving symlinks, which was then fixed by deleting the relevant lines.

(I really appreciate the work you're putting into this @lcowell ! ❤️)

Edit:

I'd rather see a test that detected the original bug(?) in submit.go

This may be way easier said than done, given that it is a huge method with no existing tests. 😢

@Insti
Copy link
Copy Markdown

Insti commented Nov 28, 2016

This is ready to be merged.

@kytrinyx
Copy link
Copy Markdown
Member

Thanks @Insti, for checking back on this. And thanks @lcowell for getting this fixed! Merging now.

@kytrinyx kytrinyx merged commit 1c67c7d into master Nov 28, 2016
@kytrinyx kytrinyx deleted the follow_symlinks branch November 28, 2016 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

submit: Doesn't respect symbolic links.

4 participants