Skip to content

Commit

Permalink
fix: files and directories are created with the correct permissions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerahikada committed Jan 30, 2024
1 parent 04e03a8 commit 5c5ab6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/filebrowser/filebrowser/v2/rules"
)

const PermFile = 0664
const PermFile = 0644
const PermDir = 0755

// FileInfo describes a file.
Expand Down
6 changes: 4 additions & 2 deletions fileutils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"

"github.com/spf13/afero"

"github.com/filebrowser/filebrowser/v2/files"
)

// MoveFile moves file from src to dst.
Expand Down Expand Up @@ -40,13 +42,13 @@ func CopyFile(fs afero.Fs, source, dest string) error {

// Makes the directory needed to create the dst
// file.
err = fs.MkdirAll(filepath.Dir(dest), 0666) //nolint:gomnd
err = fs.MkdirAll(filepath.Dir(dest), files.PermDir)
if err != nil {
return err
}

// Create the destination file.
dst, err := fs.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775) //nolint:gomnd
dst, err := fs.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_TRUNC, files.PermFile)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions http/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func resourcePostHandler(fileCache FileCache) handleFunc {

// Directories creation on POST.
if strings.HasSuffix(r.URL.Path, "/") {
err := d.user.Fs.MkdirAll(r.URL.Path, 0775) //nolint:gomnd
err := d.user.Fs.MkdirAll(r.URL.Path, files.PermDir)
return errToStatus(err), err
}

Expand Down Expand Up @@ -256,12 +256,12 @@ func addVersionSuffix(source string, fs afero.Fs) string {

func writeFile(fs afero.Fs, dst string, in io.Reader) (os.FileInfo, error) {
dir, _ := path.Split(dst)
err := fs.MkdirAll(dir, 0775) //nolint:gomnd
err := fs.MkdirAll(dir, files.PermDir)
if err != nil {
return nil, err
}

file, err := fs.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775) //nolint:gomnd
file, err := fs.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, files.PermFile)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5c5ab6b

Please sign in to comment.