Skip to content

Commit

Permalink
Fix posix permissions build constraints (#7956)
Browse files Browse the repository at this point in the history
  • Loading branch information
eladlachmi authored Jul 3, 2024
1 parent d44d961 commit c15ff92
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 18 deletions.
19 changes: 1 addition & 18 deletions pkg/local/posix_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"strings"
"sync"
"syscall"

"github.com/treeverse/lakefs/pkg/api/apigen"
"github.com/treeverse/lakefs/pkg/api/apiutil"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
31 changes: 31 additions & 0 deletions pkg/local/posix_permissions_darwin.go
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 31 additions & 0 deletions pkg/local/posix_permissions_freebsd.go
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 31 additions & 0 deletions pkg/local/posix_permissions_linux.go
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 31 additions & 0 deletions pkg/local/posix_permissions_openbsd.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions pkg/local/posix_permissions_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package local

import (
"os"
)

func getUmask() int {
return 0
}

func permissionsFromFileInfo(info os.FileInfo) (*POSIXPermissions, error) {
return nil, ErrUnsupportedFS
}

0 comments on commit c15ff92

Please sign in to comment.