mirror of
https://github.com/minio/minio.git
synced 2025-01-12 07:23:23 -05:00
simplify removing temporary files (#10389)
This commit is contained in:
parent
cb61e50b51
commit
102ad60dee
@ -41,9 +41,8 @@ func fsRemoveFile(ctx context.Context, filePath string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.Remove((filePath)); err != nil {
|
if err = os.Remove(filePath); err != nil {
|
||||||
err = osErrToFileErr(err)
|
if err = osErrToFileErr(err); err != errFileNotFound {
|
||||||
if err != errFileNotFound {
|
|
||||||
logger.LogIf(ctx, err)
|
logger.LogIf(ctx, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,22 +319,22 @@ func (fs *FSObjects) PutObjectPart(ctx context.Context, bucket, object, uploadID
|
|||||||
|
|
||||||
tmpPartPath := pathJoin(fs.fsPath, minioMetaTmpBucket, fs.fsUUID, uploadID+"."+mustGetUUID()+"."+strconv.Itoa(partID))
|
tmpPartPath := pathJoin(fs.fsPath, minioMetaTmpBucket, fs.fsUUID, uploadID+"."+mustGetUUID()+"."+strconv.Itoa(partID))
|
||||||
bytesWritten, err := fsCreateFile(ctx, tmpPartPath, data, buf, data.Size())
|
bytesWritten, err := fsCreateFile(ctx, tmpPartPath, data, buf, data.Size())
|
||||||
|
|
||||||
|
// Delete temporary part in case of failure. If
|
||||||
|
// PutObjectPart succeeds then there would be nothing to
|
||||||
|
// delete in which case we just ignore the error.
|
||||||
|
defer fsRemoveFile(ctx, tmpPartPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsRemoveFile(ctx, tmpPartPath)
|
|
||||||
return pi, toObjectErr(err, minioMetaTmpBucket, tmpPartPath)
|
return pi, toObjectErr(err, minioMetaTmpBucket, tmpPartPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should return IncompleteBody{} error when reader has fewer
|
// Should return IncompleteBody{} error when reader has fewer
|
||||||
// bytes than specified in request header.
|
// bytes than specified in request header.
|
||||||
if bytesWritten < data.Size() {
|
if bytesWritten < data.Size() {
|
||||||
fsRemoveFile(ctx, tmpPartPath)
|
|
||||||
return pi, IncompleteBody{}
|
return pi, IncompleteBody{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete temporary part in case of failure. If
|
|
||||||
// PutObjectPart succeeds then there would be nothing to
|
|
||||||
// delete in which case we just ignore the error.
|
|
||||||
defer fsRemoveFile(ctx, tmpPartPath)
|
|
||||||
etag := r.MD5CurrentHexString()
|
etag := r.MD5CurrentHexString()
|
||||||
|
|
||||||
if etag == "" {
|
if etag == "" {
|
||||||
@ -863,8 +863,7 @@ func (fs *FSObjects) cleanupStaleMultipartUploads(ctx context.Context, cleanupIn
|
|||||||
fs.appendFileMapMu.Lock()
|
fs.appendFileMapMu.Lock()
|
||||||
bgAppend, ok := fs.appendFileMap[uploadID]
|
bgAppend, ok := fs.appendFileMap[uploadID]
|
||||||
if ok {
|
if ok {
|
||||||
err := fsRemoveFile(ctx, bgAppend.filePath)
|
_ = fsRemoveFile(ctx, bgAppend.filePath)
|
||||||
logger.LogIf(ctx, err)
|
|
||||||
delete(fs.appendFileMap, uploadID)
|
delete(fs.appendFileMap, uploadID)
|
||||||
}
|
}
|
||||||
fs.appendFileMapMu.Unlock()
|
fs.appendFileMapMu.Unlock()
|
||||||
|
13
cmd/fs-v1.go
13
cmd/fs-v1.go
@ -1200,8 +1200,13 @@ func (fs *FSObjects) putObject(ctx context.Context, bucket string, object string
|
|||||||
buf := make([]byte, int(bufSize))
|
buf := make([]byte, int(bufSize))
|
||||||
fsTmpObjPath := pathJoin(fs.fsPath, minioMetaTmpBucket, fs.fsUUID, tempObj)
|
fsTmpObjPath := pathJoin(fs.fsPath, minioMetaTmpBucket, fs.fsUUID, tempObj)
|
||||||
bytesWritten, err := fsCreateFile(ctx, fsTmpObjPath, data, buf, data.Size())
|
bytesWritten, err := fsCreateFile(ctx, fsTmpObjPath, data, buf, data.Size())
|
||||||
|
|
||||||
|
// Delete the temporary object in the case of a
|
||||||
|
// failure. If PutObject succeeds, then there would be
|
||||||
|
// nothing to delete.
|
||||||
|
defer fsRemoveFile(ctx, fsTmpObjPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsRemoveFile(ctx, fsTmpObjPath)
|
|
||||||
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
||||||
}
|
}
|
||||||
fsMeta.Meta["etag"] = r.MD5CurrentHexString()
|
fsMeta.Meta["etag"] = r.MD5CurrentHexString()
|
||||||
@ -1209,15 +1214,9 @@ func (fs *FSObjects) putObject(ctx context.Context, bucket string, object string
|
|||||||
// Should return IncompleteBody{} error when reader has fewer
|
// Should return IncompleteBody{} error when reader has fewer
|
||||||
// bytes than specified in request header.
|
// bytes than specified in request header.
|
||||||
if bytesWritten < data.Size() {
|
if bytesWritten < data.Size() {
|
||||||
fsRemoveFile(ctx, fsTmpObjPath)
|
|
||||||
return ObjectInfo{}, IncompleteBody{}
|
return ObjectInfo{}, IncompleteBody{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the temporary object in the case of a
|
|
||||||
// failure. If PutObject succeeds, then there would be
|
|
||||||
// nothing to delete.
|
|
||||||
defer fsRemoveFile(ctx, fsTmpObjPath)
|
|
||||||
|
|
||||||
// Entire object was written to the temp location, now it's safe to rename it to the actual location.
|
// Entire object was written to the temp location, now it's safe to rename it to the actual location.
|
||||||
fsNSObjPath := pathJoin(fs.fsPath, bucket, object)
|
fsNSObjPath := pathJoin(fs.fsPath, bucket, object)
|
||||||
if err = fsRenameFile(ctx, fsTmpObjPath, fsNSObjPath); err != nil {
|
if err = fsRenameFile(ctx, fsTmpObjPath, fsNSObjPath); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user