Skip to content

Commit

Permalink
Preserve file's permissions when moving a file (#414)
Browse files Browse the repository at this point in the history
* MoveFile() will also move the file's permissions
  • Loading branch information
asafgabai authored Aug 15, 2021
1 parent ddf52b8 commit 1dc09ce
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions utils/io/fileutils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ func MoveFile(sourcePath, destPath string) (err error) {
}
}
}()
inputFileInfo, err := inputFile.Stat()
if err != nil {
return errorutils.CheckError(err)
}

var outputFile *os.File
outputFile, err = os.Create(destPath)
Expand All @@ -664,6 +668,10 @@ func MoveFile(sourcePath, destPath string) (err error) {
if err != nil {
return errorutils.CheckError(err)
}
err = os.Chmod(destPath, inputFileInfo.Mode())
if err != nil {
return errorutils.CheckError(err)
}

// The copy was successful, so now delete the original file
err = inputFile.Close()
Expand Down

0 comments on commit 1dc09ce

Please sign in to comment.