-
Notifications
You must be signed in to change notification settings - Fork 52
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 flag to set symlink following behavior for uploading directory #591
Add flag to set symlink following behavior for uploading directory #591
Conversation
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.
Please check go format when done (this is why presubmits are failing). Thank you!
go/pkg/tool/embeddedtool.go
Outdated
@@ -119,7 +121,7 @@ var RemoteToolOperations = map[OpType]func(ctx context.Context, c *Client){ | |||
} | |||
}, | |||
uploadDir: func(ctx context.Context, c *Client) { | |||
us, err := c.UploadDirectory(ctx, getPathFlag()) | |||
us, err := c.UploadDirectory(ctx, getPathFlag(), getSymlinkBehaviorType()) |
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: use the function you added to Command to parse the string as enum.
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.
Is it okay to add the dependency on command
here? I didn't want to introduce a new dep unnecessarily and potentially break some boundaries. Will do!
go/pkg/command/command.go
Outdated
@@ -71,6 +71,17 @@ func (s SymlinkBehaviorType) String() string { | |||
return fmt.Sprintf("InvalidSymlinkBehaviorType(%d)", s) | |||
} | |||
|
|||
func SymlinkBehavior(s string) SymlinkBehaviorType { |
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: the name sounds more like a type. I'd use ParseSymlinkBehavior
which is akin to strconv.ParseInt
. SymlinkBahaviorFromString
is another reasonable name which is akin to uuid.FromString
.
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, I've just noticed there is already a symlinkBehaviorFromProto
in this file.
Thank you for the PR and thank you @ola-rozenfeld for the review. |
We would like to be able to use
upload_dir
in a situation that makes heavy use of symlinks. However, the previous implementation did not respect symlinks and instead resulted in resolving the symlink to the actual path. This is problematic because it means that duplicated data was going to be recreated on a download.This is solved by introducing a
symlink_behavior
argument that acceptsunspecified
(default),preserve
, andresolve
which map to theSymlinkBehaviorType
enum. This allows the caller to specify how to handle symlinks and ensure that later downloads match exactly what the upload was. This also appears to reduce the data uploaded.Test