mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
lib/file: improve error message when attempting to create dir on nonexistent drive on windows
This replaces built-in os.MkdirAll with a patched version that stops the recursion when reaching the volume part of the path. The original version would continue recursion, and for extended length paths end up with \\? as the top-level directory, and the error message would then be something like: mkdir \\?: The filename, directory name, or volume label syntax is incorrect.
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
"github.com/rclone/rclone/fstest"
|
||||
"github.com/rclone/rclone/lib/file"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -36,7 +37,7 @@ func initialise(ctx context.Context, t *testing.T) (string, fs.Fs) {
|
||||
// Make test cache directory
|
||||
testDir, err := fstest.LocalRemote()
|
||||
require.NoError(t, err)
|
||||
err = os.MkdirAll(testDir, 0755)
|
||||
err = file.MkdirAll(testDir, 0755)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make test file system
|
||||
@@ -350,7 +351,7 @@ func testMountAPI(t *testing.T, sockAddr string) {
|
||||
|
||||
// Run test sequence
|
||||
path1 := filepath.Join(testDir, "path1")
|
||||
require.NoError(t, os.MkdirAll(path1, 0755))
|
||||
require.NoError(t, file.MkdirAll(path1, 0755))
|
||||
mount1 := filepath.Join(testDir, "vol1")
|
||||
res := ""
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
"github.com/rclone/rclone/lib/atexit"
|
||||
"github.com/rclone/rclone/lib/file"
|
||||
"github.com/rclone/rclone/vfs/vfscommon"
|
||||
"github.com/rclone/rclone/vfs/vfsflags"
|
||||
)
|
||||
@@ -44,12 +45,12 @@ func NewDriver(ctx context.Context, root string, mntOpt *mountlib.Options, vfsOp
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to make --cache-dir absolute")
|
||||
}
|
||||
err = os.MkdirAll(cacheDir, 0700)
|
||||
err = file.MkdirAll(cacheDir, 0700)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to create cache directory: %s", cacheDir)
|
||||
}
|
||||
|
||||
//err = os.MkdirAll(root, 0755)
|
||||
//err = file.MkdirAll(root, 0755)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to create mount root: %s", root)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/lib/atexit"
|
||||
"github.com/rclone/rclone/lib/file"
|
||||
)
|
||||
|
||||
// Server connects plugin with docker daemon by protocol
|
||||
@@ -87,7 +88,7 @@ func writeSpecFile(addr, proto, specDir string) (string, error) {
|
||||
if specDir == "" {
|
||||
specDir = defSpecDir
|
||||
}
|
||||
if err := os.MkdirAll(specDir, 0755); err != nil {
|
||||
if err := file.MkdirAll(specDir, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
specFile := filepath.Join(specDir, "rclone.spec")
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/rclone/rclone/lib/file"
|
||||
)
|
||||
|
||||
func newUnixListener(path string, gid int) (net.Listener, string, error) {
|
||||
@@ -31,7 +33,7 @@ func newUnixListener(path string, gid int) (net.Listener, string, error) {
|
||||
path = filepath.Join(sockDir, path)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
if err := file.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
"github.com/rclone/rclone/fs/rc"
|
||||
"github.com/rclone/rclone/lib/file"
|
||||
)
|
||||
|
||||
// Errors
|
||||
@@ -153,7 +154,7 @@ func (vol *Volume) checkMountpoint() error {
|
||||
}
|
||||
_, err := os.Lstat(path)
|
||||
if os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(path, 0700); err != nil {
|
||||
if err = file.MkdirAll(path, 0700); err != nil {
|
||||
return errors.Wrapf(err, "failed to create mountpoint: %s", path)
|
||||
}
|
||||
} else if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user