lchmod_linux.go 496 B

12345678910111213141516171819
  1. package driver
  2. import (
  3. "os"
  4. "golang.org/x/sys/unix"
  5. )
  6. // Lchmod changes the mode of a file not following symlinks.
  7. func (d *driver) Lchmod(path string, mode os.FileMode) error {
  8. // On Linux, file mode is not supported for symlinks,
  9. // and fchmodat() does not support AT_SYMLINK_NOFOLLOW,
  10. // so symlinks need to be skipped entirely.
  11. if st, err := os.Stat(path); err == nil && st.Mode()&os.ModeSymlink != 0 {
  12. return nil
  13. }
  14. return unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), 0)
  15. }