2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

fs: Include filename in mknod errors

This commit is contained in:
greatroar 2024-10-03 21:17:22 +02:00 committed by Michael Eischer
parent 986d981bf6
commit 3c82fe6ef5
3 changed files with 32 additions and 6 deletions

View File

@ -3,8 +3,16 @@
package restic
import "golang.org/x/sys/unix"
import (
"os"
func mknod(path string, mode uint32, dev uint64) (err error) {
return unix.Mknod(path, mode, int(dev))
"golang.org/x/sys/unix"
)
func mknod(path string, mode uint32, dev uint64) error {
err := unix.Mknod(path, mode, int(dev))
if err != nil {
err = &os.PathError{Op: "mknod", Path: path, Err: err}
}
return err
}

View File

@ -3,14 +3,21 @@
package restic
import "syscall"
import (
"os"
"syscall"
)
func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
return nil
}
func mknod(path string, mode uint32, dev uint64) (err error) {
return syscall.Mknod(path, mode, dev)
func mknod(path string, mode uint32, dev uint64) error {
err := syscall.Mknod(path, mode, dev)
if err != nil {
err = &os.PathError{Op: "mknod", Path: path, Err: err}
}
return err
}
func (s statT) atim() syscall.Timespec { return s.Atimespec }

View File

@ -7,10 +7,12 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"syscall"
"testing"
"time"
"github.com/restic/restic/internal/errors"
rtest "github.com/restic/restic/internal/test"
)
@ -145,3 +147,12 @@ func TestNodeFromFileInfo(t *testing.T) {
})
}
}
func TestMknodError(t *testing.T) {
d := t.TempDir()
// Call mkfifo, which calls mknod, as mknod may give
// "operation not permitted" on Mac.
err := mkfifo(d, 0)
rtest.Assert(t, errors.Is(err, os.ErrExist), "want ErrExist, got %q", err)
rtest.Assert(t, strings.Contains(err.Error(), d), "filename not in %q", err)
}