rename Force to Immediate for clarity (#18540)

This commit is contained in:
Anis Eleuch 2023-11-28 22:35:16 -08:00 committed by GitHub
parent e9babf3dac
commit b7d11141e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 69 additions and 68 deletions

View File

@ -232,7 +232,7 @@ func (h *healingTracker) delete(ctx context.Context) error {
pathJoin(bucketMetaPrefix, healingTrackerFilename),
DeleteOptions{
Recursive: false,
Force: false,
Immediate: false,
},
)
}

View File

@ -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())
}

View File

@ -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)

View File

@ -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)
}

View File

@ -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)

View File

@ -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.

View File

@ -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)
}

View File

@ -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,
})
}
}

View File

@ -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.

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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))

View File

@ -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) {

View File

@ -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)
}

View File

@ -64,7 +64,7 @@ func TestUNCPaths(t *testing.T) {
}
fs.Delete(context.Background(), "voldir", test.objName, DeleteOptions{
Recursive: false,
Force: false,
Immediate: false,
})
})
}