mirror of
https://github.com/minio/minio.git
synced 2025-01-12 07:23:23 -05:00
xl/fs: pathJoin now takes variadic inputs. (#1550)
Retains slash for the last element. Fixes #1546
This commit is contained in:
parent
04a5b25929
commit
722abe2d0f
@ -458,11 +458,11 @@ func listMultipartUploadsCommon(layer ObjectLayer, bucket, prefix, keyMarker, up
|
|||||||
if fi.Mode.IsDir() {
|
if fi.Mode.IsDir() {
|
||||||
// All directory entries are common prefixes.
|
// All directory entries are common prefixes.
|
||||||
uploadID = "" // Upload ids are empty for CommonPrefixes.
|
uploadID = "" // Upload ids are empty for CommonPrefixes.
|
||||||
objectName = strings.TrimPrefix(fi.Name, retainSlash(path.Join(mpartMetaPrefix, bucket)))
|
objectName = strings.TrimPrefix(fi.Name, retainSlash(pathJoin(mpartMetaPrefix, bucket)))
|
||||||
result.CommonPrefixes = append(result.CommonPrefixes, objectName)
|
result.CommonPrefixes = append(result.CommonPrefixes, objectName)
|
||||||
} else {
|
} else {
|
||||||
uploadID = path.Base(fi.Name)
|
uploadID = path.Base(fi.Name)
|
||||||
objectName = strings.TrimPrefix(path.Dir(fi.Name), retainSlash(path.Join(mpartMetaPrefix, bucket)))
|
objectName = strings.TrimPrefix(path.Dir(fi.Name), retainSlash(pathJoin(mpartMetaPrefix, bucket)))
|
||||||
result.Uploads = append(result.Uploads, uploadMetadata{
|
result.Uploads = append(result.Uploads, uploadMetadata{
|
||||||
Object: objectName,
|
Object: objectName,
|
||||||
UploadID: uploadID,
|
UploadID: uploadID,
|
||||||
|
@ -71,7 +71,7 @@ func cleanupDir(storage StorageAPI, volume, dirPath string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return delFunc(retainSlash(dirPath))
|
return delFunc(retainSlash(pathJoin(dirPath)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Common object layer functions.
|
/// Common object layer functions.
|
||||||
|
@ -105,12 +105,14 @@ func retainSlash(s string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pathJoin - like path.Join() but retains trailing "/" of the last element
|
// pathJoin - like path.Join() but retains trailing "/" of the last element
|
||||||
func pathJoin(s1 string, s2 string) string {
|
func pathJoin(elem ...string) string {
|
||||||
trailingSlash := ""
|
trailingSlash := ""
|
||||||
if strings.HasSuffix(s2, slashSeparator) {
|
if len(elem) > 0 {
|
||||||
|
if strings.HasSuffix(elem[len(elem)-1], slashSeparator) {
|
||||||
trailingSlash = "/"
|
trailingSlash = "/"
|
||||||
}
|
}
|
||||||
return path.Join(s1, s2) + trailingSlash
|
}
|
||||||
|
return path.Join(elem...) + trailingSlash
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an s3 compatible MD5sum for complete multipart transaction.
|
// Create an s3 compatible MD5sum for complete multipart transaction.
|
||||||
|
15
posix.go
15
posix.go
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user