Skip to content

Commit

Permalink
make id functions private
Browse files Browse the repository at this point in the history
  • Loading branch information
jxsl13 committed Jul 9, 2024
1 parent 82c0e49 commit 764fc7f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions backupfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ func toFInfo(path string, fi fs.FileInfo) *fInfo {
FileMode: uint32(fi.Mode()),
FileModTime: fi.ModTime().UnixNano(),
FileSize: fi.Size(),
FileUid: Uid(fi),
FileGid: Gid(fi),
FileUid: toUID(fi),
FileGid: toGID(fi),
}
}

Expand Down
12 changes: 6 additions & 6 deletions fs_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func copySymlink(source, target FS, name string, info fs.FileInfo) error {
return err
}

return ignoreChownError(target.Lchown(name, Uid(info), Gid(info)))
return ignoreChownError(target.Lchown(name, toUID(info), toGID(info)))
}

// Chown is an operating system dependent implementation.
Expand All @@ -229,15 +229,15 @@ func chown(from fs.FileInfo, toName string, fs FS) error {
return fmt.Errorf("lstat for chown failed: %w", err)
}

oldUid := Uid(oldOwnerFi)
oldGid := Gid(oldOwnerFi)
oldUid := toUID(oldOwnerFi)
oldGid := toGID(oldOwnerFi)

newUid := Uid(from)
newGid := Gid(from)
newUid := toUID(from)
newGid := toGID(from)

// only update when something changed
if oldUid != newUid || oldGid != newGid {
err = fs.Chown(toName, Uid(from), Gid(from))
err = fs.Chown(toName, toUID(from), toGID(from))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions fs_utils_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
// reference: os package
var chmodBits fs.FileMode = fs.ModePerm | fs.ModeSetuid | fs.ModeSetgid | fs.ModeSticky

func Uid(from fs.FileInfo) int {
func toUID(from fs.FileInfo) int {
if stat, ok := from.Sys().(*syscall.Stat_t); ok {
return int(stat.Uid)
}
// invalid uid = default value
return -1
}

func Gid(from fs.FileInfo) int {
func toGID(from fs.FileInfo) int {
if stat, ok := from.Sys().(*syscall.Stat_t); ok {
return int(stat.Gid)
}
Expand Down

0 comments on commit 764fc7f

Please sign in to comment.