+
+// chmodNoFollow works like os.Chmod but doesn't follow symlinks.
+func chmodNoFollow(path string, mode fs.FileMode) error {
+ x, err := os.OpenFile(path,
+ os.O_RDONLY|syscall.O_NOFOLLOW|syscall.O_NONBLOCK, 0)
+ if err != nil {
+ return err
+ }
+ defer x.Close()
+
+ err = x.Chmod(mode)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}