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

Typos and constants #738

Merged
merged 1 commit into from
Aug 5, 2020
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
13 changes: 7 additions & 6 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
)

const defaultDirectoryPermission = 0740
const rwFilePermission = 0600

// HomeFolder returns the home folder of the current user
// HomeFolder returns the home folder of the current user.
func HomeFolder() string {
u, err := user.Current()
if err != nil {
Expand All @@ -20,8 +21,8 @@ func HomeFolder() string {
return u.HomeDir
}

// CreateSecureFolder checks if the folder exists and has the appropriate permission rights. In case of bad permission rights)
// the empty string is returned.If the folder doesn't exist it creates it.
// CreateSecureFolder checks if the folder exists and has the appropriate permission rights. In case of bad permission rights
// the empty string is returned. If the folder doesn't exist it, create it.
func CreateSecureFolder(folder string) string {
if exists, _ := Exists(folder); !exists {
if err := os.MkdirAll(folder, defaultDirectoryPermission); err != nil {
Expand All @@ -37,7 +38,7 @@ func CreateSecureFolder(folder string) string {
}
perm := int(info.Mode().Perm())
if perm != int(defaultDirectoryPermission) {
fmt.Printf("Folder different permission: %#o vs %#o \n", perm, 0740)
fmt.Printf("Folder different permission: %#o vs %#o \n", perm, defaultDirectoryPermission)
return folder
}
}
Expand All @@ -64,10 +65,10 @@ func CreateSecureFile(file string) (*os.File, error) {
return nil, err
}
fd.Close()
if err := os.Chmod(file, 0600); err != nil {
if err := os.Chmod(file, rwFilePermission); err != nil {
return nil, nil
}
return os.OpenFile(file, os.O_RDWR, 0600)
return os.OpenFile(file, os.O_RDWR, rwFilePermission)
}

// Files returns the list of file names included in the given path or error if
Expand Down