Skip to content
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

Merged
merged 13 commits into from
Jul 14, 2020
Merged

Add symlink info to file metadata #153

merged 13 commits into from
Jul 14, 2020

Conversation

k-ye
Copy link
Contributor

@k-ye k-ye commented Jul 7, 2020

This PR just exposes the symlink information to filemeta.Metadata, without changing how the upper-level modules use it.

  • If the symlink is valid, it will fall through to the part of handling a normal file. This way, Digest, IsExecutable are still set.
  • Otherwise, symlink metadata's IsInvalid will be set to true, with Target being empty.

Issue: #146

@googlebot googlebot added the cla: yes The author signed a CLA label Jul 7, 2020
// SymlinkMetadata contains details if the given path is a symlink.
type SymlinkMetadata struct {
Target string
IsInvalid bool
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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:

  1. 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.
  2. 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.

Copy link
Contributor Author

@k-ye k-ye Jul 8, 2020

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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..

@k-ye k-ye requested a review from ola-rozenfeld July 8, 2020 02:33
t.Helper()

randBytes := make([]byte, 16)
rand.Read(randBytes)
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

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.

@k-ye k-ye requested a review from ola-rozenfeld July 9, 2020 00:20
@k-ye
Copy link
Contributor Author

k-ye commented Jul 9, 2020

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..).

@ola-rozenfeld
Copy link
Contributor

ola-rozenfeld commented Jul 9, 2020 via email

@k-ye
Copy link
Contributor Author

k-ye commented Jul 10, 2020

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 :)

@ola-rozenfeld
Copy link
Contributor

Sorry for disappearing, I was off for a few days!

@ola-rozenfeld ola-rozenfeld merged commit ef239a1 into bazelbuild:master Jul 14, 2020
@k-ye k-ye deleted the sym branch July 16, 2020 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes The author signed a CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants