mirror of
https://github.com/minio/minio.git
synced 2025-02-05 02:38:07 -05:00
cleanup existing part.N's before renamePart() (#20466)
this is a safety-net to avoid any unexpected parts to show up.
This commit is contained in:
parent
0c53d86017
commit
f6f0807c86
@ -526,6 +526,14 @@ func (er erasureObjects) NewMultipartUpload(ctx context.Context, bucket, object
|
|||||||
|
|
||||||
// renamePart - renames multipart part to its relevant location under uploadID.
|
// renamePart - renames multipart part to its relevant location under uploadID.
|
||||||
func (er erasureObjects) renamePart(ctx context.Context, disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, optsMeta []byte, writeQuorum int) ([]StorageAPI, error) {
|
func (er erasureObjects) renamePart(ctx context.Context, disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, optsMeta []byte, writeQuorum int) ([]StorageAPI, error) {
|
||||||
|
paths := []string{
|
||||||
|
dstEntry,
|
||||||
|
dstEntry + ".meta",
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanup existing paths first across all drives.
|
||||||
|
er.cleanupMultipartPath(ctx, paths...)
|
||||||
|
|
||||||
g := errgroup.WithNErrs(len(disks))
|
g := errgroup.WithNErrs(len(disks))
|
||||||
|
|
||||||
// Rename file on all underlying storage disks.
|
// Rename file on all underlying storage disks.
|
||||||
@ -542,11 +550,6 @@ func (er erasureObjects) renamePart(ctx context.Context, disks []StorageAPI, src
|
|||||||
// Wait for all renames to finish.
|
// Wait for all renames to finish.
|
||||||
errs := g.Wait()
|
errs := g.Wait()
|
||||||
|
|
||||||
paths := []string{
|
|
||||||
dstEntry,
|
|
||||||
dstEntry + ".meta",
|
|
||||||
}
|
|
||||||
|
|
||||||
err := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
err := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
er.cleanupMultipartPath(ctx, paths...)
|
er.cleanupMultipartPath(ctx, paths...)
|
||||||
|
@ -2921,7 +2921,8 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenamePart - rename part path to destination path atomically.
|
// RenamePart - rename part path to destination path atomically, this is meant to be used
|
||||||
|
// only with multipart API
|
||||||
func (s *xlStorage) RenamePart(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string, meta []byte) (err error) {
|
func (s *xlStorage) RenamePart(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string, meta []byte) (err error) {
|
||||||
srcVolumeDir, err := s.getVolDir(srcVolume)
|
srcVolumeDir, err := s.getVolDir(srcVolume)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2952,46 +2953,23 @@ func (s *xlStorage) RenamePart(ctx context.Context, srcVolume, srcPath, dstVolum
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srcIsDir := HasSuffix(srcPath, SlashSeparator)
|
srcIsDir := HasSuffix(srcPath, SlashSeparator)
|
||||||
dstIsDir := HasSuffix(dstPath, SlashSeparator)
|
dstIsDir := HasSuffix(dstPath, SlashSeparator)
|
||||||
// Either src and dst have to be directories or files, else return error.
|
// either source or destination is a directory return error.
|
||||||
if !(srcIsDir && dstIsDir || !srcIsDir && !dstIsDir) {
|
if srcIsDir || dstIsDir {
|
||||||
return errFileAccessDenied
|
return errFileAccessDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
srcFilePath := pathutil.Join(srcVolumeDir, srcPath)
|
srcFilePath := pathutil.Join(srcVolumeDir, srcPath)
|
||||||
if err = checkPathLength(srcFilePath); err != nil {
|
if err = checkPathLength(srcFilePath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dstFilePath := pathutil.Join(dstVolumeDir, dstPath)
|
dstFilePath := pathutil.Join(dstVolumeDir, dstPath)
|
||||||
if err = checkPathLength(dstFilePath); err != nil {
|
if err = checkPathLength(dstFilePath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if srcIsDir {
|
|
||||||
// If source is a directory, we expect the destination to be non-existent but we
|
|
||||||
// we still need to allow overwriting an empty directory since it represents
|
|
||||||
// an object empty directory.
|
|
||||||
dirInfo, err := Lstat(dstFilePath)
|
|
||||||
if isSysErrIO(err) {
|
|
||||||
return errFaultyDisk
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
if !osIsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !dirInfo.IsDir() {
|
|
||||||
return errFileAccessDenied
|
|
||||||
}
|
|
||||||
if err = Remove(dstFilePath); err != nil {
|
|
||||||
if isSysErrNotEmpty(err) || isSysErrNotDir(err) {
|
|
||||||
return errFileAccessDenied
|
|
||||||
} else if isSysErrIO(err) {
|
|
||||||
return errFaultyDisk
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = renameAll(srcFilePath, dstFilePath, dstVolumeDir); err != nil {
|
if err = renameAll(srcFilePath, dstFilePath, dstVolumeDir); err != nil {
|
||||||
if isSysErrNotEmpty(err) || isSysErrNotDir(err) {
|
if isSysErrNotEmpty(err) || isSysErrNotDir(err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user