-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(prune) respect dir permissions during prune #2066
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
fix(prune) respect dir permissions during prune #2066
Conversation
@chris-olszewski is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
cli/internal/fs/copy_file.go
Outdated
if err != nil { | ||
return err | ||
} | ||
return os.MkdirAll(dest, mode) | ||
} | ||
// name is absolute, (originates from godirwalk) |
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 this comment should move up to where src
is allocated.
cli/internal/prune/prune.go
Outdated
@@ -146,10 +146,16 @@ func (p *prune) prune(opts *opts) error { | |||
continue | |||
} | |||
workspaces = append(workspaces, ctx.PackageInfos[internalDep].Dir) | |||
originalDir := p.base.RepoRoot.UntypedJoin(ctx.PackageInfos[internalDep].Dir.ToStringDuringMigration()) |
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 this is supposed to be ctx.PackageInfos[internalDep].Dir.RestoreAnchor(p.base.RepoRoot)
?
@nathanhammond what do you think about also including a method on AbsoluteSystemPath
that is essentially Join
but accepts a single AnchoredSystemPath
instance?
At any rate, this shouldn't be Untyped
, we have the types here for both pieces of the path.
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, thanks for pointing that out. I missed RestoreAnchor
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.
@gsoltis @chris-olszewski I'm game for that method; I just couldn't find a name for it that I was happy with so I didn't create it.
I agree that it isn't intuitive to start with the Anchored path and prepend the Absolute one.
cli/internal/prune/prune.go
Outdated
targetDir := fullDir.UntypedJoin(ctx.PackageInfos[internalDep].Dir.ToStringDuringMigration()) | ||
if err := targetDir.EnsureDir(); err != nil { | ||
return errors.Wrapf(err, "failed to create folder %v for %v", targetDir, internalDep) | ||
if err = targetDir.MkdirAllMode(info.Mode()); err != nil { |
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.
One advantage of this particular pattern is to scope a new err
. By using if err := ...
, you shadow any existing err
, and don't leak this err
beyond the if
block. It's a common enough pattern that I would say you probably don't want to use it if you aren't using :=
, or at least not without a comment explaining why.
In this case, you aren't using the value of err
beyond this block so I would switch to :=
return os.Chmod(p.ToString(), mode) | ||
} else { | ||
// Path exists as file, remove it | ||
if err = p.Remove(); err != nil { |
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 err = os.MkdirAll(p.ToString(), mode); err != nil { |
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.
:=
Just notice this part of os.Chmod:
Which explains the failing windows tests |
Fixes #1872
This PR ended up having larger scope than I originally intended. A few things that changed:
RecursiveCopyFile
now attempts to copy directories with the correct permissionsMkdirAllMode
which is similar toMkdirAll
but it will ensure that the created directory has the permissions passedMkdirAllMode
instead ofEnsureDir
Interaction with umask
Currently we don't consider
umask
when creating files. When copying files that we get from users we should make sure that the permissions are kept, but when creating files for turbo itself, we should probably respectumask
.When copying user files and we want to make sure permissions remain the same, the standard solution is to
chmod
after creating a new dir/file. This would add an additional syscall to all of the file/directory copy methods which seems like a little much. Another option would be to blow awayumask
at the beginning to ensure that we are creating files with the permissions we expect.Testing
Wrote some unit tests, also did a quick spot check that dir permissions are copied over