Skip to content

Commit

Permalink
Use RWX for restic output.json (#1001)
Browse files Browse the repository at this point in the history
xref: #1000

Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Dec 20, 2019
1 parent 4d9cdbc commit e18f30d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/restic/output.go
Expand Up @@ -29,7 +29,7 @@ import (
api_v1beta1 "stash.appscode.dev/stash/apis/stash/v1beta1"
)

const FileModeRWAll = 0666
const FileModeRWXAll = 0777

type BackupOutput struct {
// HostBackupStats shows backup statistics of a host
Expand Down Expand Up @@ -61,7 +61,7 @@ func (out *BackupOutput) WriteOutput(fileName string) error {
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(fileName), FileModeRWAll); err != nil {
if err := os.MkdirAll(filepath.Dir(fileName), FileModeRWXAll); err != nil {
return err
}
// check if the output file already exist. if it does not, then owner should chmod to make the file writable to other users
Expand All @@ -70,12 +70,12 @@ func (out *BackupOutput) WriteOutput(fileName string) error {
newFile = true
}

if err := ioutil.WriteFile(fileName, jsonOutput, FileModeRWAll); err != nil { // this does not make the file writable to other users
if err := ioutil.WriteFile(fileName, jsonOutput, FileModeRWXAll); err != nil { // this does not make the file writable to other users
return err
}
// change the file permission to make it writable to other users
if newFile {
return os.Chmod(fileName, FileModeRWAll)
return os.Chmod(fileName, FileModeRWXAll)
}
return nil
}
Expand All @@ -85,7 +85,7 @@ func (out *RestoreOutput) WriteOutput(fileName string) error {
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(fileName), FileModeRWAll); err != nil {
if err := os.MkdirAll(filepath.Dir(fileName), FileModeRWXAll); err != nil {
return err
}
// check if the output file already exist. if it does not, then owner should chmod to make the file writable to other users
Expand All @@ -94,12 +94,12 @@ func (out *RestoreOutput) WriteOutput(fileName string) error {
newFile = true
}

if err := ioutil.WriteFile(fileName, jsonOutput, FileModeRWAll); err != nil { // this does not make the file writable to other users
if err := ioutil.WriteFile(fileName, jsonOutput, FileModeRWXAll); err != nil { // this does not make the file writable to other users
return err
}
// change the file permission to make it writable to other users
if newFile {
return os.Chmod(fileName, FileModeRWAll)
return os.Chmod(fileName, FileModeRWXAll)
}
return nil
}
Expand Down

0 comments on commit e18f30d

Please sign in to comment.