diff --git a/pkg/local/posix_permissions.go b/pkg/local/posix_permissions.go index 90c0c1cf86c..9e306babd45 100644 --- a/pkg/local/posix_permissions.go +++ b/pkg/local/posix_permissions.go @@ -6,7 +6,6 @@ import ( "os" "strings" "sync" - "syscall" "github.com/treeverse/lakefs/pkg/api/apigen" "github.com/treeverse/lakefs/pkg/api/apiutil" @@ -39,14 +38,6 @@ type POSIXPermissions struct { Mode os.FileMode } -func getUmask() int { - if umask < 0 { - umask = syscall.Umask(0) - syscall.Umask(umask) - } - return umask -} - // GetDefaultPermissions - returns default permissions as defined by file system. Public for testing purposes func GetDefaultPermissions(isDir bool) POSIXPermissions { getOwnershipMutex.Lock() @@ -89,15 +80,7 @@ func getPermissionFromStats(stats apigen.ObjectStats, withDefault bool) (*POSIXP } func getPermissionFromFileInfo(info os.FileInfo) (*POSIXPermissions, error) { - p := POSIXPermissions{} - if stat, ok := info.Sys().(*syscall.Stat_t); ok { - p.UID = int(stat.Uid) - p.GID = int(stat.Gid) - p.Mode = os.FileMode(stat.Mode) - } else { - return nil, ErrUnsupportedFS - } - return &p, nil + return permissionsFromFileInfo(info) } func isPermissionsChanged(localFileInfo os.FileInfo, remoteFileStats apigen.ObjectStats) bool { diff --git a/pkg/local/posix_permissions_darwin.go b/pkg/local/posix_permissions_darwin.go new file mode 100644 index 00000000000..14ad8f1c6d2 --- /dev/null +++ b/pkg/local/posix_permissions_darwin.go @@ -0,0 +1,31 @@ +package local + +import ( + "os" + "syscall" +) + +func getUmask() int { + if umask < 0 { + umask = syscall.Umask(0) + syscall.Umask(umask) + } + return umask +} + +func permissionsFromFileInfo(info os.FileInfo) (*POSIXPermissions, error) { + stat, ok := info.Sys().(*syscall.Stat_t) + if !ok { + return nil, ErrUnsupportedFS + } + + defaultOwnership = &POSIXOwnership{ + UID: int(stat.Uid), + GID: int(stat.Gid), + } + + return &POSIXPermissions{ + Mode: os.FileMode(stat.Mode), + POSIXOwnership: *defaultOwnership, + }, nil +} diff --git a/pkg/local/posix_permissions_freebsd.go b/pkg/local/posix_permissions_freebsd.go new file mode 100644 index 00000000000..14ad8f1c6d2 --- /dev/null +++ b/pkg/local/posix_permissions_freebsd.go @@ -0,0 +1,31 @@ +package local + +import ( + "os" + "syscall" +) + +func getUmask() int { + if umask < 0 { + umask = syscall.Umask(0) + syscall.Umask(umask) + } + return umask +} + +func permissionsFromFileInfo(info os.FileInfo) (*POSIXPermissions, error) { + stat, ok := info.Sys().(*syscall.Stat_t) + if !ok { + return nil, ErrUnsupportedFS + } + + defaultOwnership = &POSIXOwnership{ + UID: int(stat.Uid), + GID: int(stat.Gid), + } + + return &POSIXPermissions{ + Mode: os.FileMode(stat.Mode), + POSIXOwnership: *defaultOwnership, + }, nil +} diff --git a/pkg/local/posix_permissions_linux.go b/pkg/local/posix_permissions_linux.go new file mode 100644 index 00000000000..14ad8f1c6d2 --- /dev/null +++ b/pkg/local/posix_permissions_linux.go @@ -0,0 +1,31 @@ +package local + +import ( + "os" + "syscall" +) + +func getUmask() int { + if umask < 0 { + umask = syscall.Umask(0) + syscall.Umask(umask) + } + return umask +} + +func permissionsFromFileInfo(info os.FileInfo) (*POSIXPermissions, error) { + stat, ok := info.Sys().(*syscall.Stat_t) + if !ok { + return nil, ErrUnsupportedFS + } + + defaultOwnership = &POSIXOwnership{ + UID: int(stat.Uid), + GID: int(stat.Gid), + } + + return &POSIXPermissions{ + Mode: os.FileMode(stat.Mode), + POSIXOwnership: *defaultOwnership, + }, nil +} diff --git a/pkg/local/posix_permissions_openbsd.go b/pkg/local/posix_permissions_openbsd.go new file mode 100644 index 00000000000..14ad8f1c6d2 --- /dev/null +++ b/pkg/local/posix_permissions_openbsd.go @@ -0,0 +1,31 @@ +package local + +import ( + "os" + "syscall" +) + +func getUmask() int { + if umask < 0 { + umask = syscall.Umask(0) + syscall.Umask(umask) + } + return umask +} + +func permissionsFromFileInfo(info os.FileInfo) (*POSIXPermissions, error) { + stat, ok := info.Sys().(*syscall.Stat_t) + if !ok { + return nil, ErrUnsupportedFS + } + + defaultOwnership = &POSIXOwnership{ + UID: int(stat.Uid), + GID: int(stat.Gid), + } + + return &POSIXPermissions{ + Mode: os.FileMode(stat.Mode), + POSIXOwnership: *defaultOwnership, + }, nil +} diff --git a/pkg/local/posix_permissions_windows.go b/pkg/local/posix_permissions_windows.go new file mode 100644 index 00000000000..d243083c68c --- /dev/null +++ b/pkg/local/posix_permissions_windows.go @@ -0,0 +1,13 @@ +package local + +import ( + "os" +) + +func getUmask() int { + return 0 +} + +func permissionsFromFileInfo(info os.FileInfo) (*POSIXPermissions, error) { + return nil, ErrUnsupportedFS +}