-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement symlink functionality with filepath.EvalSymlinks() #55
Conversation
We are using filepath.EvalSymlinks() here, because it will give us the last element in a symlink chain. Therefore we don't need to worry about stack size or recursion cycles.
mh ok this is weird.. when I run these tests locally they work...:
is this again some Windows related stuff? |
mhh looks like an error in path translation between Linux paths and Windows paths?!
I have also no idea where this |
Doesn't windows support SymLinks? EDIT: no.. then the symlink wouldn't work at all.. right now it's calculating the hash correct |
I think I fixed the file path matching via using: |
Mh I think I will add 1-2 more tests to the symlink code. I am not convinced yet, that it's secure without a max recursion parameter -> draft |
I knew it.. looks like we are running in a cycle, so we really need a recursion counter or some sort of history where we log visited files?
I've added a test for this PR.. seems I were wrong and filepath.EvalSym() can not detect symlinks. :S I could re-implement the recursion counter from the other PR or create a history or something. |
We also introduce our first custom error called "SymCycleErr". If we detect a symlink cycle, we are now failing completely. Symlink cycles should not exist.
@lukpueh Can you have a look on this PR, too? I have reimplemented most of the PR #37. |
@lukpueh I have also added our first custom error. The error handling got some nice changes in go 1.13, we can use these changes and return our own library specific errors instead. This makes developers life easier, because they don't need to compare strings anymore. if err == errors.Is(err, OurCustomErr){ ..} |
Shall I squash this PR into one commit? would make it easier, if we encounter problems to revert it. |
Many thanks for the great work, @shibumi. I left a few minor suggestions and questions. |
We need to follow our style guide and use 80 as max length for non-GoDocs comments.
move global variables to the top for better visibility
Our former method of symlink detection has been with recursion depth. The new method introduces a symlink history with a hashset. This should has a better performance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for coming up with and implementing this new approach, @shibumi! It looks a lot better than what we had before. Will this also work if we called RecordArtifacts
twice? I think you need to reset visitedSymlinks
at some point.
Thanks for addressing my review comment regarding line width. Is there a reason why you now sometimes wrap quite a bit before 80 chars? IMO you can use the full 80 chars for code comments.
I will squash the last 2 nonsense commits from github UI to one 'refactor comments' commit. Shouldn't use github for applying changes directly .. sigh |
We could pass a set as argument, that way we could control the passed set and on recursion depth 0 devs would need to pass an empty set as initialization. It's the only solution I come up with, but I will think about this till Friday afternoon. |
💯 Thanks, that's what I usually do. I like the feature from a reviewer's perspective, but I also think there should be no "Update XYZ" commits. |
Sounds like a good idea. Or we add a wrapper like so:
|
I like the wrapper variant. This is better than passing a map. We could do it like the other big Golang libraries and just write |
1a7d28c
to
4e877f7
Compare
We need to make sure to initialize + tear down our global variable. Therefore we move the RecordArtifacts functionality to recordArtifacts and build a wrapper around it called RecordArtifacts. Moreover we do not need to reimplement the set, we can just the set from util.Set
@lukpueh I am not sure if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for implementing the wrapper approach and for adding extensive testing. I have one question left (inline). Let me know what you think.
@lukpueh I've fixed the nil check for the visitedSymlinks hashset. Ping me if you find something else :) |
97d0ad2
to
2a845b1
Compare
@lukpueh checks passed, ready to merge. When merged, I will use the current master as base for the intoto-run implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quality contribution, @shibumi!
Symlink walk support in RecordArtifacts was kindly added by @shibumi in in-toto#55, fixing in-toto#32. This commit removes the note that it is not yet supported.
Please fill in the fields below to submit a pull request. The more
information that is provided, the better.
Fixes issue #:
#32
as well as PR #37
Description of pull request:
We are using filepath.EvalSymlinks() here, because it will
give us the last element in a symlink chain.
Therefore we don't need to worry about stack size
or recursion cycles.
Please verify and check that the pull request fulfills the following
requirements: