From b7d11141e1fdad6ffdb24a47fa3d8a7c7940e0f3 Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Tue, 28 Nov 2023 22:35:16 -0800 Subject: [PATCH] rename Force to Immediate for clarity (#18540) --- cmd/background-newdisks-heal-ops.go | 2 +- cmd/erasure-encode_test.go | 2 +- cmd/erasure-healing-common_test.go | 4 +-- cmd/erasure-healing.go | 2 +- cmd/erasure-healing_test.go | 22 ++++++------ cmd/erasure-multipart.go | 10 +++--- cmd/erasure-object.go | 4 +-- cmd/erasure-object_test.go | 4 +-- cmd/format-erasure.go | 2 +- cmd/storage-datatypes.go | 2 +- cmd/storage-datatypes_gen.go | 52 ++++++++++++++--------------- cmd/storage-rest_test.go | 2 +- cmd/xl-storage-disk-id-check.go | 2 +- cmd/xl-storage.go | 13 ++++---- cmd/xl-storage_test.go | 12 +++---- cmd/xl-storage_windows_test.go | 2 +- 16 files changed, 69 insertions(+), 68 deletions(-) diff --git a/cmd/background-newdisks-heal-ops.go b/cmd/background-newdisks-heal-ops.go index 70cdb44ad..cf2aa16f9 100644 --- a/cmd/background-newdisks-heal-ops.go +++ b/cmd/background-newdisks-heal-ops.go @@ -232,7 +232,7 @@ func (h *healingTracker) delete(ctx context.Context) error { pathJoin(bucketMetaPrefix, healingTrackerFilename), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }, ) } diff --git a/cmd/erasure-encode_test.go b/cmd/erasure-encode_test.go index e30d7e970..f799e839b 100644 --- a/cmd/erasure-encode_test.go +++ b/cmd/erasure-encode_test.go @@ -190,7 +190,7 @@ func benchmarkErasureEncode(data, parity, dataDown, parityDown int, size int64, } disk.Delete(context.Background(), "testbucket", "object", DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) writers[i] = newBitrotWriter(disk, "testbucket", "object", erasure.ShardFileSize(size), DefaultBitrotAlgorithm, erasure.ShardSize()) } diff --git a/cmd/erasure-healing-common_test.go b/cmd/erasure-healing-common_test.go index 2515fcf27..a2aba098f 100644 --- a/cmd/erasure-healing-common_test.go +++ b/cmd/erasure-healing-common_test.go @@ -273,7 +273,7 @@ func TestListOnlineDisks(t *testing.T) { tamperedIndex = index dErr := erasureDisks[index].Delete(context.Background(), bucket, pathJoin(object, fi.DataDir, "part.1"), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if dErr != nil { t.Fatalf("Failed to delete %s - %v", filepath.Join(object, "part.1"), dErr) @@ -455,7 +455,7 @@ func TestListOnlineDisksSmallObjects(t *testing.T) { tamperedIndex = index dErr := erasureDisks[index].Delete(context.Background(), bucket, pathJoin(object, xlStorageFormatFile), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if dErr != nil { t.Fatalf("Failed to delete %s - %v", pathJoin(object, xlStorageFormatFile), dErr) diff --git a/cmd/erasure-healing.go b/cmd/erasure-healing.go index 0637dac29..5bad2779c 100644 --- a/cmd/erasure-healing.go +++ b/cmd/erasure-healing.go @@ -866,7 +866,7 @@ func (er *erasureObjects) healObjectDir(ctx context.Context, bucket, object stri defer wg.Done() _ = disk.Delete(ctx, bucket, object, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) }(index, disk) } diff --git a/cmd/erasure-healing_test.go b/cmd/erasure-healing_test.go index 864604b87..57f6915d5 100644 --- a/cmd/erasure-healing_test.go +++ b/cmd/erasure-healing_test.go @@ -848,7 +848,7 @@ func TestHealCorrectQuorum(t *testing.T) { for i := 0; i < nfi.Erasure.ParityBlocks; i++ { erasureDisks[i].Delete(context.Background(), bucket, pathJoin(object, xlStorageFormatFile), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) } @@ -875,7 +875,7 @@ func TestHealCorrectQuorum(t *testing.T) { for i := 0; i < nfi.Erasure.ParityBlocks; i++ { erasureDisks[i].Delete(context.Background(), minioMetaBucket, pathJoin(cfgFile, xlStorageFormatFile), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) } @@ -959,7 +959,7 @@ func TestHealObjectCorruptedPools(t *testing.T) { firstDisk := erasureDisks[0] err = firstDisk.Delete(context.Background(), bucket, pathJoin(object, xlStorageFormatFile), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if err != nil { t.Fatalf("Failed to delete a file - %v", err) @@ -982,7 +982,7 @@ func TestHealObjectCorruptedPools(t *testing.T) { err = firstDisk.Delete(context.Background(), bucket, pathJoin(object, fi.DataDir, "part.1"), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if err != nil { t.Errorf("Failure during deleting part.1 - %v", err) @@ -1012,7 +1012,7 @@ func TestHealObjectCorruptedPools(t *testing.T) { err = firstDisk.Delete(context.Background(), bucket, pathJoin(object, fi.DataDir, "part.1"), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if err != nil { t.Errorf("Failure during deleting part.1 - %v", err) @@ -1046,7 +1046,7 @@ func TestHealObjectCorruptedPools(t *testing.T) { for i := 0; i <= nfi.Erasure.DataBlocks; i++ { erasureDisks[i].Delete(context.Background(), bucket, pathJoin(object, xlStorageFormatFile), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) } @@ -1141,7 +1141,7 @@ func TestHealObjectCorruptedXLMeta(t *testing.T) { err = firstDisk.Delete(context.Background(), bucket, pathJoin(object, xlStorageFormatFile), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if err != nil { t.Fatalf("Failed to delete a file - %v", err) @@ -1196,7 +1196,7 @@ func TestHealObjectCorruptedXLMeta(t *testing.T) { for i := 0; i <= nfi2.Erasure.DataBlocks; i++ { erasureDisks[i].Delete(context.Background(), bucket, pathJoin(object, xlStorageFormatFile), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) } @@ -1296,7 +1296,7 @@ func TestHealObjectCorruptedParts(t *testing.T) { // Test 1, remove part.1 err = firstDisk.Delete(context.Background(), bucket, pathJoin(object, fi.DataDir, "part.1"), DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if err != nil { t.Fatalf("Failed to delete a file - %v", err) @@ -1344,7 +1344,7 @@ func TestHealObjectCorruptedParts(t *testing.T) { err = secondDisk.Delete(context.Background(), bucket, object, DeleteOptions{ Recursive: true, - Force: false, + Immediate: false, }) if err != nil { t.Fatalf("Failed to delete a file - %v", err) @@ -1435,7 +1435,7 @@ func TestHealObjectErasure(t *testing.T) { // Delete the whole object folder err = firstDisk.Delete(context.Background(), bucket, object, DeleteOptions{ Recursive: true, - Force: false, + Immediate: false, }) if err != nil { t.Fatalf("Failed to delete a file - %v", err) diff --git a/cmd/erasure-multipart.go b/cmd/erasure-multipart.go index cb9247f78..dec06faf3 100644 --- a/cmd/erasure-multipart.go +++ b/cmd/erasure-multipart.go @@ -118,7 +118,7 @@ func (er erasureObjects) removePartMeta(bucket, object, uploadID, dataDir string g.Go(func() error { _ = storageDisks[index].Delete(context.TODO(), minioMetaMultipartBucket, curpartPath+".meta", DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) return nil @@ -145,11 +145,11 @@ func (er erasureObjects) removeObjectPart(bucket, object, uploadID, dataDir stri // the object. The presence of parts that don't belong in the object doesn't affect correctness. _ = storageDisks[index].Delete(context.TODO(), minioMetaMultipartBucket, curpartPath, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) _ = storageDisks[index].Delete(context.TODO(), minioMetaMultipartBucket, curpartPath+".meta", DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) return nil @@ -185,7 +185,7 @@ func (er erasureObjects) deleteAll(ctx context.Context, bucket, prefix string) { defer wg.Done() disk.Delete(ctx, bucket, prefix, DeleteOptions{ Recursive: true, - Force: false, + Immediate: false, }) }(disk) } @@ -564,7 +564,7 @@ func writeAllDisks(ctx context.Context, disks []StorageAPI, dstBucket, dstEntry } index := index g.Go(func() error { - return disks[index].Delete(ctx, dstBucket, dstEntry, DeleteOptions{Force: true}) + return disks[index].Delete(ctx, dstBucket, dstEntry, DeleteOptions{Immediate: true}) }, index) } // Ignore these errors. diff --git a/cmd/erasure-object.go b/cmd/erasure-object.go index 6e059397b..13ca70395 100644 --- a/cmd/erasure-object.go +++ b/cmd/erasure-object.go @@ -1772,11 +1772,11 @@ func (er erasureObjects) deletePrefix(ctx context.Context, bucket, prefix string // - The prefix__XLDIR__ defer disks[index].Delete(ctx, bucket, dirPrefix, DeleteOptions{ Recursive: true, - Force: true, + Immediate: true, }) return disks[index].Delete(ctx, bucket, prefix, DeleteOptions{ Recursive: true, - Force: true, + Immediate: true, }) }, index) } diff --git a/cmd/erasure-object_test.go b/cmd/erasure-object_test.go index 3878eba60..bee50451f 100644 --- a/cmd/erasure-object_test.go +++ b/cmd/erasure-object_test.go @@ -526,7 +526,7 @@ func TestGetObjectNoQuorum(t *testing.T) { if file != "xl.meta" { disk.Delete(ctx, bucket, pathJoin(object, file), DeleteOptions{ Recursive: true, - Force: false, + Immediate: false, }) } } @@ -630,7 +630,7 @@ func TestHeadObjectNoQuorum(t *testing.T) { if file != "xl.meta" { disk.Delete(ctx, bucket, pathJoin(object, file), DeleteOptions{ Recursive: true, - Force: false, + Immediate: false, }) } } diff --git a/cmd/format-erasure.go b/cmd/format-erasure.go index 331a9ee1d..b9324e980 100644 --- a/cmd/format-erasure.go +++ b/cmd/format-erasure.go @@ -364,7 +364,7 @@ func saveFormatErasure(disk StorageAPI, format *formatErasureV3, healID string) // Purge any existing temporary file, okay to ignore errors here. defer disk.Delete(context.TODO(), minioMetaBucket, tmpFormat, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) // write to unique file. diff --git a/cmd/storage-datatypes.go b/cmd/storage-datatypes.go index e235d9db4..681c0a0e1 100644 --- a/cmd/storage-datatypes.go +++ b/cmd/storage-datatypes.go @@ -24,7 +24,7 @@ import ( // DeleteOptions represents the disk level delete options available for the APIs type DeleteOptions struct { Recursive bool `msg:"r"` - Force bool `msg:"f"` + Immediate bool `msg:"i"` } //go:generate msgp -file=$GOFILE diff --git a/cmd/storage-datatypes_gen.go b/cmd/storage-datatypes_gen.go index 720497d6e..e72e29f74 100644 --- a/cmd/storage-datatypes_gen.go +++ b/cmd/storage-datatypes_gen.go @@ -245,10 +245,10 @@ func (z *DeleteFileHandlerParams) DecodeMsg(dc *msgp.Reader) (err error) { err = msgp.WrapError(err, "Opts", "Recursive") return } - case "f": - z.Opts.Force, err = dc.ReadBool() + case "i": + z.Opts.Immediate, err = dc.ReadBool() if err != nil { - err = msgp.WrapError(err, "Opts", "Force") + err = msgp.WrapError(err, "Opts", "Immediate") return } default: @@ -319,14 +319,14 @@ func (z *DeleteFileHandlerParams) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "Opts", "Recursive") return } - // write "f" - err = en.Append(0xa1, 0x66) + // write "i" + err = en.Append(0xa1, 0x69) if err != nil { return } - err = en.WriteBool(z.Opts.Force) + err = en.WriteBool(z.Opts.Immediate) if err != nil { - err = msgp.WrapError(err, "Opts", "Force") + err = msgp.WrapError(err, "Opts", "Immediate") return } return @@ -351,9 +351,9 @@ func (z *DeleteFileHandlerParams) MarshalMsg(b []byte) (o []byte, err error) { // string "r" o = append(o, 0x82, 0xa1, 0x72) o = msgp.AppendBool(o, z.Opts.Recursive) - // string "f" - o = append(o, 0xa1, 0x66) - o = msgp.AppendBool(o, z.Opts.Force) + // string "i" + o = append(o, 0xa1, 0x69) + o = msgp.AppendBool(o, z.Opts.Immediate) return } @@ -414,10 +414,10 @@ func (z *DeleteFileHandlerParams) UnmarshalMsg(bts []byte) (o []byte, err error) err = msgp.WrapError(err, "Opts", "Recursive") return } - case "f": - z.Opts.Force, bts, err = msgp.ReadBoolBytes(bts) + case "i": + z.Opts.Immediate, bts, err = msgp.ReadBoolBytes(bts) if err != nil { - err = msgp.WrapError(err, "Opts", "Force") + err = msgp.WrapError(err, "Opts", "Immediate") return } default: @@ -470,10 +470,10 @@ func (z *DeleteOptions) DecodeMsg(dc *msgp.Reader) (err error) { err = msgp.WrapError(err, "Recursive") return } - case "f": - z.Force, err = dc.ReadBool() + case "i": + z.Immediate, err = dc.ReadBool() if err != nil { - err = msgp.WrapError(err, "Force") + err = msgp.WrapError(err, "Immediate") return } default: @@ -500,14 +500,14 @@ func (z DeleteOptions) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "Recursive") return } - // write "f" - err = en.Append(0xa1, 0x66) + // write "i" + err = en.Append(0xa1, 0x69) if err != nil { return } - err = en.WriteBool(z.Force) + err = en.WriteBool(z.Immediate) if err != nil { - err = msgp.WrapError(err, "Force") + err = msgp.WrapError(err, "Immediate") return } return @@ -520,9 +520,9 @@ func (z DeleteOptions) MarshalMsg(b []byte) (o []byte, err error) { // string "r" o = append(o, 0x82, 0xa1, 0x72) o = msgp.AppendBool(o, z.Recursive) - // string "f" - o = append(o, 0xa1, 0x66) - o = msgp.AppendBool(o, z.Force) + // string "i" + o = append(o, 0xa1, 0x69) + o = msgp.AppendBool(o, z.Immediate) return } @@ -550,10 +550,10 @@ func (z *DeleteOptions) UnmarshalMsg(bts []byte) (o []byte, err error) { err = msgp.WrapError(err, "Recursive") return } - case "f": - z.Force, bts, err = msgp.ReadBoolBytes(bts) + case "i": + z.Immediate, bts, err = msgp.ReadBoolBytes(bts) if err != nil { - err = msgp.WrapError(err, "Force") + err = msgp.WrapError(err, "Immediate") return } default: diff --git a/cmd/storage-rest_test.go b/cmd/storage-rest_test.go index 8a2c5719d..a1b5d5489 100644 --- a/cmd/storage-rest_test.go +++ b/cmd/storage-rest_test.go @@ -382,7 +382,7 @@ func testStorageAPIDeleteFile(t *testing.T, storage StorageAPI) { for i, testCase := range testCases { err := storage.Delete(context.Background(), testCase.volumeName, testCase.objectName, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) expectErr := (err != nil) diff --git a/cmd/xl-storage-disk-id-check.go b/cmd/xl-storage-disk-id-check.go index 8c6ad9554..e7d2e73d5 100644 --- a/cmd/xl-storage-disk-id-check.go +++ b/cmd/xl-storage-disk-id-check.go @@ -979,7 +979,7 @@ func (p *xlStorageDiskIDCheck) monitorDiskStatus(spent time.Duration) { } err = p.storage.Delete(context.Background(), minioMetaTmpBucket, fn, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if err == nil { t := time.Unix(0, atomic.LoadInt64(&p.health.lastSuccess)) diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index ffa75b3ee..ad3bd315f 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -1109,7 +1109,7 @@ func (s *xlStorage) DeleteVersions(ctx context.Context, volume string, versions return errs } -func (s *xlStorage) moveToTrash(filePath string, recursive, force bool) (err error) { +func (s *xlStorage) moveToTrash(filePath string, recursive, immediatePurge bool) (err error) { pathUUID := mustGetUUID() targetPath := pathutil.Join(s.drivePath, minioMetaTmpDeletedBucket, pathUUID) @@ -1126,6 +1126,7 @@ func (s *xlStorage) moveToTrash(filePath string, recursive, force bool) (err err } else { err = Remove(filePath) } + return err // Avoid the immediate purge since not needed } if err != nil { @@ -1133,7 +1134,7 @@ func (s *xlStorage) moveToTrash(filePath string, recursive, force bool) (err err } // immediately purge the target - if force { + if immediatePurge { removeAll(targetPath) } @@ -1146,7 +1147,7 @@ func (s *xlStorage) DeleteVersion(ctx context.Context, volume, path string, fi F if HasSuffix(path, SlashSeparator) { return s.Delete(ctx, volume, path, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) } @@ -2171,7 +2172,7 @@ func (s *xlStorage) CheckParts(ctx context.Context, volume string, path string, // move up the tree, deleting empty parent directories until it finds one // with files in it. Returns nil for a non-empty directory even when // recursive is set to false. -func (s *xlStorage) deleteFile(basePath, deletePath string, recursive, force bool) error { +func (s *xlStorage) deleteFile(basePath, deletePath string, recursive, immediate bool) error { if basePath == "" || deletePath == "" { return nil } @@ -2184,7 +2185,7 @@ func (s *xlStorage) deleteFile(basePath, deletePath string, recursive, force boo var err error if recursive { - err = s.moveToTrash(deletePath, true, force) + err = s.moveToTrash(deletePath, true, immediate) } else { err = Remove(deletePath) } @@ -2256,7 +2257,7 @@ func (s *xlStorage) Delete(ctx context.Context, volume string, path string, dele } // Delete file and delete parent directory as well if it's empty. - return s.deleteFile(volumeDir, filePath, deleteOpts.Recursive, deleteOpts.Force) + return s.deleteFile(volumeDir, filePath, deleteOpts.Recursive, deleteOpts.Immediate) } func skipAccessChecks(volume string) (ok bool) { diff --git a/cmd/xl-storage_test.go b/cmd/xl-storage_test.go index f41d3dd5f..1de574b46 100644 --- a/cmd/xl-storage_test.go +++ b/cmd/xl-storage_test.go @@ -892,7 +892,7 @@ func TestXLStorageListDir(t *testing.T) { if err = xlStorageNew.Delete(context.Background(), "mybucket", "myobject", DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }); err != errFileAccessDenied { t.Errorf("expected: %s, got: %s", errFileAccessDenied, err) } @@ -902,7 +902,7 @@ func TestXLStorageListDir(t *testing.T) { // should fail with disk not found. err = xlStorageDeletedStorage.Delete(context.Background(), "del-vol", "my-file", DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if err != errDiskNotFound { t.Errorf("Expected: \"Drive not found\", got \"%s\"", err) @@ -988,7 +988,7 @@ func TestXLStorageDeleteFile(t *testing.T) { for i, testCase := range testCases { if err = xlStorage.Delete(context.Background(), testCase.srcVol, testCase.srcPath, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }); err != testCase.expectedErr { t.Errorf("TestXLStorage case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) } @@ -1015,7 +1015,7 @@ func TestXLStorageDeleteFile(t *testing.T) { if err = xlStorageNew.Delete(context.Background(), "mybucket", "myobject", DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }); err != errFileAccessDenied { t.Errorf("expected: %s, got: %s", errFileAccessDenied, err) } @@ -1036,7 +1036,7 @@ func TestXLStorageDeleteFile(t *testing.T) { // should fail with disk not found. err = xlStorageDeletedStorage.Delete(context.Background(), "del-vol", "my-file", DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) if err != errDiskNotFound { t.Errorf("Expected: \"Drive not found\", got \"%s\"", err) @@ -1862,7 +1862,7 @@ func TestXLStorageVerifyFile(t *testing.T) { if err := storage.Delete(context.Background(), volName, fileName, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }); err != nil { t.Fatal(err) } diff --git a/cmd/xl-storage_windows_test.go b/cmd/xl-storage_windows_test.go index c6403a3cf..7bb5466ee 100644 --- a/cmd/xl-storage_windows_test.go +++ b/cmd/xl-storage_windows_test.go @@ -64,7 +64,7 @@ func TestUNCPaths(t *testing.T) { } fs.Delete(context.Background(), "voldir", test.objName, DeleteOptions{ Recursive: false, - Force: false, + Immediate: false, }) }) }