mirror of
https://github.com/rclone/rclone.git
synced 2026-01-05 18:13:17 +00: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:
@@ -275,7 +275,7 @@ func makeConfigPath() string {
|
||||
return configFile
|
||||
}
|
||||
var mkdirErr error
|
||||
if mkdirErr = os.MkdirAll(configDir, os.ModePerm); mkdirErr == nil {
|
||||
if mkdirErr = file.MkdirAll(configDir, os.ModePerm); mkdirErr == nil {
|
||||
return configFile
|
||||
}
|
||||
// Problem: Try a fallback location. If we did find a home directory then
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
"github.com/rclone/rclone/lib/file"
|
||||
)
|
||||
|
||||
// Install installs the config file handler
|
||||
@@ -109,7 +110,7 @@ func (s *Storage) Save() error {
|
||||
}
|
||||
|
||||
dir, name := filepath.Split(configPath)
|
||||
err := os.MkdirAll(dir, os.ModePerm)
|
||||
err := file.MkdirAll(dir, os.ModePerm)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create config directory")
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/lib/file"
|
||||
)
|
||||
|
||||
// GetLatestReleaseURL returns the latest release details of the rclone-webui-react
|
||||
@@ -95,7 +96,7 @@ func CheckAndDownloadWebGUIRelease(checkUpdate bool, forceUpdate bool, fetchURL
|
||||
|
||||
cachePathExist, cachePathStat, _ := exists(cachePath)
|
||||
if !cachePathExist {
|
||||
if err := os.MkdirAll(cachePath, 0755); err != nil {
|
||||
if err := file.MkdirAll(cachePath, 0755); err != nil {
|
||||
return errors.New("Error creating cache directory: " + cachePath)
|
||||
}
|
||||
}
|
||||
@@ -174,7 +175,7 @@ func Unzip(src, dest string) (err error) {
|
||||
}
|
||||
defer fs.CheckClose(r, &err)
|
||||
|
||||
if err := os.MkdirAll(dest, 0755); err != nil {
|
||||
if err := file.MkdirAll(dest, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -193,14 +194,14 @@ func Unzip(src, dest string) (err error) {
|
||||
defer fs.CheckClose(rc, &err)
|
||||
|
||||
if f.FileInfo().IsDir() {
|
||||
if err := os.MkdirAll(path, 0755); err != nil {
|
||||
if err := file.MkdirAll(path, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
if err := file.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
f, err := file.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -239,7 +240,7 @@ func exists(path string) (existence bool, stat os.FileInfo, err error) {
|
||||
func CreatePathIfNotExist(path string) (err error) {
|
||||
exists, stat, _ := exists(path)
|
||||
if !exists {
|
||||
if err := os.MkdirAll(path, 0755); err != nil {
|
||||
if err := file.MkdirAll(path, 0755); err != nil {
|
||||
return errors.New("Error creating : " + path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user