Cleanup lchmod logic in archive

Move to single lchmod interface mirroring other implementations.
Separate logic for freebsd which supports symlink no follow flag.

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2021-07-06 17:57:46 -07:00
parent 7eceeb950b
commit 53835221f6
5 changed files with 36 additions and 21 deletions

View File

@@ -18,7 +18,11 @@
package archive
import "golang.org/x/sys/unix"
import (
"os"
"golang.org/x/sys/unix"
)
// mknod wraps Unix.Mknod and casts dev to int
func mknod(path string, mode uint32, dev uint64) error {
@@ -34,3 +38,18 @@ func lsetxattrCreate(link string, attr string, data []byte) error {
}
return err
}
// lchmod checks for symlink and changes the mode if not a symlink
func lchmod(path string, mode os.FileMode) error {
fi, err := os.Lstat(path)
if err != nil {
return err
}
if fi.Mode()&os.ModeSymlink == 0 {
if err := os.Chmod(path, mode); err != nil {
return err
}
}
return nil
}