From aca5a3c69a625eedf4c463b4a255658baf526c00 Mon Sep 17 00:00:00 2001 From: Dom Lavery Date: Fri, 7 Jan 2022 09:16:45 +0000 Subject: [PATCH 1/2] Fix #141 comparing symlink permissions --- fs/manifest_darwin.go | 30 ++++++++++++++++++++++++++++++ fs/manifest_test.go | 11 +++++++++++ fs/manifest_unix.go | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 fs/manifest_darwin.go diff --git a/fs/manifest_darwin.go b/fs/manifest_darwin.go new file mode 100644 index 00000000..ad502fa7 --- /dev/null +++ b/fs/manifest_darwin.go @@ -0,0 +1,30 @@ +// +build darwin + +package fs + +import ( + "os" + "syscall" +) + +const ( + defaultRootDirMode = os.ModeDir | 0700 + defaultSymlinkMode = os.ModeSymlink | 0755 +) + +func newResourceFromInfo(info os.FileInfo) resource { + statT := info.Sys().(*syscall.Stat_t) + return resource{ + mode: info.Mode(), + uid: statT.Uid, + gid: statT.Gid, + } +} + +func (p *filePath) SetMode(mode os.FileMode) { + p.file.mode = mode +} + +func (p *directoryPath) SetMode(mode os.FileMode) { + p.directory.mode = mode | os.ModeDir +} diff --git a/fs/manifest_test.go b/fs/manifest_test.go index 0b31c7f7..2cbc6108 100644 --- a/fs/manifest_test.go +++ b/fs/manifest_test.go @@ -75,6 +75,17 @@ func TestManifestFromDir(t *testing.T) { actual.root.items["s"].(*directory).items["k"].(*file).content.Close() } +func TestSymlinks(t *testing.T) { + rootDirectory := NewDir(t, "root", + WithFile("foo.txt", "foo"), + WithSymlink("foo.link", "foo.txt")) + defer rootDirectory.Remove() + expected := Expected(t, + WithFile("foo.txt", "foo"), + WithSymlink("foo.link", rootDirectory.Join("foo.txt"))) + assert.Assert(t, Equal(rootDirectory.Path(), expected)) +} + var cmpManifest = cmp.Options{ cmp.AllowUnexported(Manifest{}, resource{}, file{}, symlink{}, directory{}), cmp.Comparer(func(x, y io.ReadCloser) bool { diff --git a/fs/manifest_unix.go b/fs/manifest_unix.go index bba2fcd9..e1dd9937 100644 --- a/fs/manifest_unix.go +++ b/fs/manifest_unix.go @@ -1,4 +1,4 @@ -// +build !windows +// +build !windows,!darwin package fs From 7501e42ed8a007981438063c2433d0e8fe626666 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Sat, 8 Jan 2022 13:27:24 -0500 Subject: [PATCH 2/2] switch darwin defaults using runtime.GOOS To remove the need to duplicate the rest of the file. --- fs/manifest_darwin.go | 30 ------------------------------ fs/manifest_unix.go | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 35 deletions(-) delete mode 100644 fs/manifest_darwin.go diff --git a/fs/manifest_darwin.go b/fs/manifest_darwin.go deleted file mode 100644 index ad502fa7..00000000 --- a/fs/manifest_darwin.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build darwin - -package fs - -import ( - "os" - "syscall" -) - -const ( - defaultRootDirMode = os.ModeDir | 0700 - defaultSymlinkMode = os.ModeSymlink | 0755 -) - -func newResourceFromInfo(info os.FileInfo) resource { - statT := info.Sys().(*syscall.Stat_t) - return resource{ - mode: info.Mode(), - uid: statT.Uid, - gid: statT.Gid, - } -} - -func (p *filePath) SetMode(mode os.FileMode) { - p.file.mode = mode -} - -func (p *directoryPath) SetMode(mode os.FileMode) { - p.directory.mode = mode | os.ModeDir -} diff --git a/fs/manifest_unix.go b/fs/manifest_unix.go index e1dd9937..d2956f33 100644 --- a/fs/manifest_unix.go +++ b/fs/manifest_unix.go @@ -1,16 +1,24 @@ -// +build !windows,!darwin +//go:build !windows +// +build !windows package fs import ( "os" + "runtime" "syscall" ) -const ( - defaultRootDirMode = os.ModeDir | 0700 - defaultSymlinkMode = os.ModeSymlink | 0777 -) +const defaultRootDirMode = os.ModeDir | 0700 + +var defaultSymlinkMode = os.ModeSymlink | 0777 + +func init() { + switch runtime.GOOS { + case "darwin": + defaultSymlinkMode = os.ModeSymlink | 0755 + } +} func newResourceFromInfo(info os.FileInfo) resource { statT := info.Sys().(*syscall.Stat_t)