Skip to content

Commit

Permalink
Merge pull request #41 from jxsl13/fix/redhat-root-dir-copy
Browse files Browse the repository at this point in the history
do not touch root directories when copying directories
  • Loading branch information
jxsl13 authored Sep 30, 2024
2 parents f461d97 + e69dc7f commit 46fde3a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ func copyDir(fs FS, name string, info fs.FileInfo) (err error) {
return fmt.Errorf("%w: %s", errDirInfoExpected, name)
}

// do not touch the root directory
// this is either the OS root directory, which we do not want to change, as
// on for example redhat it's a read only directory which is not modifiable.
// on the other hand it is the root directory of the backup folder which has already its permissions
// set correctly.
pathWithoutVolume := TrimVolume(name)
if pathWithoutVolume == separator || pathWithoutVolume == "/" {
// windows supports both path separators, which is why we check for both
return nil
}

// try to create all dirs as somone might have tempered with the file system
targetMode := info.Mode()
err = fs.MkdirAll(name, targetMode.Perm())
Expand Down

0 comments on commit 46fde3a

Please sign in to comment.