Skip to content

Commit f5b895a

Browse files
committed
driver/{Mknod,Mkfifo,Lchmod}: return PathError
In case any of these methods fail, make sure to return an error wrapped in os.PathError, to be in line with the other methods (most of which are wrappers for os.Foo() calls, which return os.PathError or os.LinkError). [v2: use keyed fields] Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent c7c5070 commit f5b895a

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

driver/driver_unix.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import (
1313
)
1414

1515
func (d *driver) Mknod(path string, mode os.FileMode, major, minor int) error {
16-
return devices.Mknod(path, mode, major, minor)
16+
err := devices.Mknod(path, mode, major, minor)
17+
if err != nil {
18+
err = &os.PathError{Op: "mknod", Path: path, Err: err}
19+
}
20+
return err
1721
}
1822

1923
func (d *driver) Mkfifo(path string, mode os.FileMode) error {
@@ -22,7 +26,11 @@ func (d *driver) Mkfifo(path string, mode os.FileMode) error {
2226
}
2327
// mknod with a mode that has ModeNamedPipe set creates a fifo, not a
2428
// device.
25-
return devices.Mknod(path, mode, 0, 0)
29+
err := devices.Mknod(path, mode, 0, 0)
30+
if err != nil {
31+
err = &os.PathError{Op: "mkfifo", Path: path, Err: err}
32+
}
33+
return err
2634
}
2735

2836
// Getxattr returns all of the extended attributes for the file at path p.

driver/driver_windows.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import (
44
"os"
55

66
"github.com/containerd/continuity/sysx"
7-
"github.com/pkg/errors"
87
)
98

109
func (d *driver) Mknod(path string, mode os.FileMode, major, minor int) error {
11-
return errors.Wrap(ErrNotSupported, "cannot create device node on Windows")
10+
return &os.PathError{Op: "mknod", Path: path, Err: ErrNotSupported}
1211
}
1312

1413
func (d *driver) Mkfifo(path string, mode os.FileMode) error {
15-
return errors.Wrap(ErrNotSupported, "cannot create fifo on Windows")
14+
return &os.PathError{Op: "mkfifo", Path: path, Err: ErrNotSupported}
1615
}
1716

1817
// Lchmod changes the mode of an file not following symlinks.

driver/lchmod_linux.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ func (d *driver) Lchmod(path string, mode os.FileMode) error {
1515
return nil
1616
}
1717

18-
return unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), 0)
18+
err := unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), 0)
19+
if err != nil {
20+
err = &os.PathError{Op: "lchmod", Path: path, Err: err}
21+
}
22+
return err
1923
}

driver/lchmod_unix.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ import (
1010

1111
// Lchmod changes the mode of a file not following symlinks.
1212
func (d *driver) Lchmod(path string, mode os.FileMode) error {
13-
return unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), unix.AT_SYMLINK_NOFOLLOW)
13+
err := unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), unix.AT_SYMLINK_NOFOLLOW)
14+
if err != nil {
15+
err = &os.PathError{Op: "lchmod", Path: path, Err: err}
16+
}
17+
return err
1418
}

0 commit comments

Comments
 (0)