Skip to content

[fileutil] use 0755 as default filemode to create dir #1103

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

Merged
merged 1 commit into from
Jun 7, 2023
Merged
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
11 changes: 9 additions & 2 deletions internal/fileutil/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package fileutil

import (
"io/fs"
"os"
"path/filepath"

Expand All @@ -27,11 +28,17 @@ func CopyAll(src, dst string) error {
}

func ClearDir(dir string) error {
// if the dir doesn't exist, use default filemode 0755 to create it
// if the dir exists, use its own filemode to re-create it
var mode os.FileMode
f, err := os.Stat(dir)
if err != nil {
if err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we preserve returning an error unless it is fs.ErrNotExist?

var mode os.FileMode
if f, err := os.Stat(dir); if err == nil {
      mode = f.Mode()
} else if errors.Is(err, fs.ErrNotExist) {
         mode = 0755
else {
 	return errors.WithStack(err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

mode = f.Mode()
} else if errors.Is(err, fs.ErrNotExist) {
mode = 0755
} else {
return errors.WithStack(err)
}
mode := f.Mode()

if err := os.RemoveAll(dir); err != nil {
return errors.WithStack(err)
Expand Down