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

fix: make CopyFile create target directories with sensible permissions #215

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/repository/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ func (r *Copy) CopyFile(
return err
}

// Ensure target directory exists; it will be created with the same mode as
// the target file, plus x-bits.
dirMode := si.Mode() & 0o777
dirMode |= ((dirMode & 0o444) >> 2) | ((dirMode & 0o222) >> 1)
retr0h marked this conversation as resolved.
Show resolved Hide resolved
_ = r.appFs.MkdirAll(r.appFs.Dir(dst), dirMode)
// Open dest file for writing; make it owner-only perms before putting
// anything in it
_ = r.appFs.MkdirAll(r.appFs.Dir(dst), si.Mode())
out, err := r.appFs.Create(dst)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions internal/repository/copy_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (suite *CopyPublicTestSuite) TestCopyFileOk() {

got, _ := avfs.Exists(suite.appFs, assertFile)
assert.True(suite.T(), got)
// ensure target dir is created with sensible permissions — expressed
// in "canonical" form here so the test result is legible
parent, _ := suite.appFs.Stat(suite.dstDir)
assert.Equal(suite.T(), fs.FileMode(0o20000000755), parent.Mode())
}

func (suite *CopyPublicTestSuite) TestCopyFileReturnsError() {
Expand Down
Loading