Skip to content

Commit 0377f7d

Browse files
Merge pull request #120 from kolyshkin/lchmod-linux-go111
Fix Lchmod() for Linux+Go1.11
2 parents 246e490 + 6d0b394 commit 0377f7d

12 files changed

Lines changed: 33 additions & 151 deletions

context.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,6 @@ func (c *context) Apply(resource Resource) error {
473473
}
474474
}
475475

476-
// NOTE(stevvooe): Chmod on symlink is not supported on linux. We
477-
// may want to maintain support for other platforms that have it.
478-
chmod = false
479-
480476
case Device:
481477
if fi == nil {
482478
if err := c.driver.Mknod(fp, resource.Mode(), int(r.Major()), int(r.Minor())); err != nil {

driver/driver_unix.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"os"
9-
"path/filepath"
109
"sort"
1110

1211
"github.com/containerd/continuity/devices"
@@ -26,18 +25,6 @@ func (d *driver) Mkfifo(path string, mode os.FileMode) error {
2625
return devices.Mknod(path, mode, 0, 0)
2726
}
2827

29-
// Lchmod changes the mode of an file not following symlinks.
30-
func (d *driver) Lchmod(path string, mode os.FileMode) (err error) {
31-
if !filepath.IsAbs(path) {
32-
path, err = filepath.Abs(path)
33-
if err != nil {
34-
return
35-
}
36-
}
37-
38-
return sysx.Fchmodat(0, path, uint32(mode), sysx.AtSymlinkNofollow)
39-
}
40-
4128
// Getxattr returns all of the extended attributes for the file at path p.
4229
func (d *driver) Getxattr(p string) (map[string][]byte, error) {
4330
xattrs, err := sysx.Listxattr(p)

driver/lchmod_linux.go

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

driver/lchmod_unix.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// +build darwin freebsd solaris
2+
3+
package driver
4+
5+
import (
6+
"os"
7+
8+
"golang.org/x/sys/unix"
9+
)
10+
11+
// Lchmod changes the mode of a file not following symlinks.
12+
func (d *driver) Lchmod(path string, mode os.FileMode) error {
13+
return unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), unix.AT_SYMLINK_NOFOLLOW)
14+
}

sysx/chmod_darwin.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

sysx/chmod_darwin_386.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

sysx/chmod_darwin_amd64.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

sysx/chmod_freebsd.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

sysx/chmod_freebsd_amd64.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

sysx/chmod_linux.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)