-
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
Add symlink info to file metadata #153
Conversation
go/pkg/filemetadata/filemetadata.go
Outdated
// SymlinkMetadata contains details if the given path is a symlink. | ||
type SymlinkMetadata struct { | ||
Target string | ||
IsInvalid bool |
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.
nit: IsDangling is a more informative name, now that I think about it.
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.
Done
func TestComputeSymlinks(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
target interface{} // If unspecified, this is an invalid symlink |
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.
Some cleaner options for doing this:
- What we usually do is make the test struct a union of the test parameters. There is nothing wrong with having an IsDirectory option, or an IsExecutable option that only applies to files and not directories.
- If you really want to have a single field of variable type, the golang pattern is to create a common interface (say, CreateSymlink) and have your types implement it.
I slightly prefer option 2 in this case, because I suspect that if your createSymlink is split into two or three functions (you can create a different type for a dangling symlink), it will look much simpler.
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.
Ah, actually i split this into three tests now. Sorry for mixing the logic before, hopefully it now gets simpler?
What we usually do is make the test struct a union of the test parameters.
Ack. I created testFileParams
mostly because symlink tests also need this. But now it seems that we can get rid of it and flatten the test struct again. Let me know which way do you prefer!
BTW, I prepended all the test structs with test
, in order to prevent it from being accidentally used in the non-test part of the package. Is this too verbose?
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.
I think flattening things out will be simplest. Also, I don't think the rest of the package can use the test code, at least not if compiled with Bazel (not sure how go build works), so no need to prefix with test.
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.
Ack, removed testFileParams
target string | ||
} | ||
|
||
func (sc *testSymlinkCreationResult) cleanup() { |
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.
If everything's under temp, why do you need to clean it up?
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.
This is actually to follow
defer os.RemoveAll(filename) |
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.
Not sure I follow... Do you mean in the next patch? I meant to simplify as instead of cleaning up manually, create everything under a TempDir directory -- pass this directory to everything that creates files or symlinks if you need to reuse it.
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.
Sorry about the confusion. My point is that the existing file tests are doing this clean up manually (even if those filenames are temporary and unique), therefore I followed that for consistency.
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.
Hmm, right, now I wonder why I did that :-) But sure, let's keep it, then.
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.
Oops, i actually removed the Clean()
method..
t.Helper() | ||
|
||
randBytes := make([]byte, 16) | ||
rand.Read(randBytes) |
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.
Simplifying: pass the symlink name as a parameter, so you don't need to create it and return it. You can base it on the name of the test case, if you don't want to add another variable. That way, you don't need the testSymlinkCreationResult at all, you just return the file name.
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.
Thx! Fixed
target string | ||
} | ||
|
||
func (sc *testSymlinkCreationResult) cleanup() { |
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.
Not sure I follow... Do you mean in the next patch? I meant to simplify as instead of cleaning up manually, create everything under a TempDir directory -- pass this directory to everything that creates files or symlinks if you need to reuse it.
Hi Ola, I just had a team meeting and it seems that supporting only files and directories would cover the major use cases for us. I'm still happy to polish this specific PR and get it merged, if you think it's useful. But otherwise, I'll lower the priority of #146 and come back to this later (maybe we can have a meeting some time to talk about how to support it, if you don't have a plan already..). |
Glad to hear that, because supporting symlinks properly would be a lot of
work. I have a plan in mind, would be good if I wrote it down some time --
if I do, I'll share it with you.
Yes, I think this PR is a good start, and we should get it merged. All I
had is a few simplifying nits, so should be easy. Thank you for doing this!
…On Thu, Jul 9, 2020 at 1:57 AM Ye Kuang ***@***.***> wrote:
Hi Ola,
I just had a team meeting and it seems that supporting only files and
directories would cover the major use cases for us. I'm still happy to
polish this specific PR and get it merged, if you think it's useful. But
otherwise, I'll lower the priority of #146
<#146> and come back
to this later (maybe we can have a meeting some time to talk about how to
support it, if you don't have a plan already..).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#153 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGFAVOERRFKS3N2KKNZM6JLR2VL3ZANCNFSM4OSRYV7A>
.
|
Thanks! I don't see new comments since last around of review, will wait for more suggestions :) |
Sorry for disappearing, I was off for a few days! |
This PR just exposes the symlink information to
filemeta.Metadata
, without changing how the upper-level modules use it.Digest
,IsExecutable
are still set.IsInvalid
will be set totrue
, withTarget
being empty.Issue: #146