|
|
@ -19,8 +19,7 @@ package main |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
slashpath "path" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"syscall" |
|
|
|
"syscall" |
|
|
|
|
|
|
|
|
|
|
@ -148,7 +147,7 @@ func getAllUniqueVols(dirPath string) ([]VolInfo, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
var volsInfo []VolInfo |
|
|
|
var volsInfo []VolInfo |
|
|
|
for _, entry := range entries { |
|
|
|
for _, entry := range entries { |
|
|
|
if !strings.HasSuffix(entry, slashSeparator) || !isValidVolname(filepath.Clean(entry)) { |
|
|
|
if !strings.HasSuffix(entry, slashSeparator) || !isValidVolname(slashpath.Clean(entry)) { |
|
|
|
// Skip if entry is neither a directory not a valid volume name.
|
|
|
|
// Skip if entry is neither a directory not a valid volume name.
|
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
@ -479,7 +478,7 @@ func (s fsStorage) StatFile(volume, path string) (file FileInfo, err error) { |
|
|
|
return FileInfo{}, err |
|
|
|
return FileInfo{}, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
filePath := pathJoin(volumeDir, path) |
|
|
|
filePath := slashpath.Join(volumeDir, path) |
|
|
|
st, err := os.Stat(filePath) |
|
|
|
st, err := os.Stat(filePath) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.WithFields(logrus.Fields{ |
|
|
|
log.WithFields(logrus.Fields{ |
|
|
@ -548,10 +547,10 @@ func deleteFile(basePath, deletePath string) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
// Recursively go down the next path and delete again.
|
|
|
|
// Recursively go down the next path and delete again.
|
|
|
|
if err := deleteFile(basePath, path.Dir(deletePath)); err != nil { |
|
|
|
if err := deleteFile(basePath, slashpath.Dir(deletePath)); err != nil { |
|
|
|
log.WithFields(logrus.Fields{ |
|
|
|
log.WithFields(logrus.Fields{ |
|
|
|
"basePath": basePath, |
|
|
|
"basePath": basePath, |
|
|
|
"deleteDir": path.Dir(deletePath), |
|
|
|
"deleteDir": slashpath.Dir(deletePath), |
|
|
|
}).Debugf("deleteFile failed with %s", err) |
|
|
|
}).Debugf("deleteFile failed with %s", err) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -595,7 +594,7 @@ func (s fsStorage) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) err |
|
|
|
}).Errorf("getVolumeDir failed with %s", err) |
|
|
|
}).Errorf("getVolumeDir failed with %s", err) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if err = os.MkdirAll(path.Join(dstVolumeDir, path.Dir(dstPath)), 0755); err != nil { |
|
|
|
if err = os.MkdirAll(slashpath.Join(dstVolumeDir, slashpath.Dir(dstPath)), 0755); err != nil { |
|
|
|
// File path cannot be verified since one of the parents is a file.
|
|
|
|
// File path cannot be verified since one of the parents is a file.
|
|
|
|
if strings.Contains(err.Error(), "not a directory") { |
|
|
|
if strings.Contains(err.Error(), "not a directory") { |
|
|
|
return errFileAccessDenied |
|
|
|
return errFileAccessDenied |
|
|
@ -603,7 +602,7 @@ func (s fsStorage) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) err |
|
|
|
log.Errorf("os.MkdirAll failed with %s", err) |
|
|
|
log.Errorf("os.MkdirAll failed with %s", err) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
err = os.Rename(path.Join(srcVolumeDir, srcPath), path.Join(dstVolumeDir, dstPath)) |
|
|
|
err = os.Rename(slashpath.Join(srcVolumeDir, srcPath), slashpath.Join(dstVolumeDir, dstPath)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
if os.IsNotExist(err) { |
|
|
|
if os.IsNotExist(err) { |
|
|
|
return errFileNotFound |
|
|
|
return errFileNotFound |
|
|
|