Skip to content

Commit

Permalink
remove override mode for dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Apr 12, 2024
1 parent 5849477 commit eb21499
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
3 changes: 0 additions & 3 deletions internal/deb/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ func extractData(dataReader io.Reader, options *ExtractOptions) error {
Path: filepath.Join(options.TargetDir, path),
Mode: mode,
MakeParents: true,
// We dont want this implicit parent directory to overwrite
// an existing directory.
OverrideMode: false,
}
err := options.Create(nil, createOptions)
if err != nil {
Expand Down
7 changes: 1 addition & 6 deletions internal/fsutil/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ type CreateOptions struct {
Mode fs.FileMode
Data io.Reader
Link string
// If OverrideMode is true and a directory exists, its mode will be modified.
OverrideMode bool
// If MakeParents is true, missing parent directories of Path are
// created with permissions 0755.
MakeParents bool
Expand Down Expand Up @@ -76,10 +74,7 @@ func createDir(o *CreateOptions) error {
debugf("Creating directory: %s (mode %#o)", o.Path, o.Mode)
err := os.Mkdir(o.Path, o.Mode)
if os.IsExist(err) {
if !o.OverrideMode {
return nil
}
err = os.Chmod(o.Path, o.Mode)
return nil
}
return err
}
Expand Down
18 changes: 2 additions & 16 deletions internal/fsutil/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ var createTests = []createTest{{
error: `.*: no such file or directory`,
}, {
options: fsutil.CreateOptions{
Path: "foo",
Mode: fs.ModeDir | 0775,
OverrideMode: false,
Path: "foo",
Mode: fs.ModeDir | 0775,
},
hackdir: func(c *C, dir string) {
c.Assert(os.Mkdir(filepath.Join(dir, "foo/"), fs.ModeDir|0765), IsNil)
Expand All @@ -81,19 +80,6 @@ var createTests = []createTest{{
// mode is not updated.
"/foo/": "dir 0765",
},
}, {
options: fsutil.CreateOptions{
Path: "foo",
Mode: fs.ModeDir | 0775,
OverrideMode: true,
},
hackdir: func(c *C, dir string) {
c.Assert(os.Mkdir(filepath.Join(dir, "foo/"), fs.ModeDir|0765), IsNil)
},
result: map[string]string{
// mode is updated.
"/foo/": "dir 0775",
},
}}

func (s *S) TestCreate(c *C) {
Expand Down

0 comments on commit eb21499

Please sign in to comment.