diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go index 48d6ca819..8927f7e89 100644 --- a/cmd/fs-v1.go +++ b/cmd/fs-v1.go @@ -117,14 +117,16 @@ func (fs fsObjects) Shutdown() error { // List if there are any multipart entries. _, err := fs.storage.ListDir(minioMetaBucket, mpartMetaPrefix) if err != errFileNotFound { - // Multipart directory is not empty hence do not remove '.minio.sys' volume. - return nil + // A nil err means that multipart directory is not empty hence do not remove '.minio.sys' volume. + // A non nil err means that an unexpected error occured + return err } // List if there are any bucket configuration entries. _, err = fs.storage.ListDir(minioMetaBucket, bucketConfigPrefix) if err != errFileNotFound { - // Bucket config directory is not empty hence do not remove '.minio.sys' volume. - return nil + // A nil err means that bucket config directory is not empty hence do not remove '.minio.sys' volume. + // A non nil err means that an unexpected error occured + return err } // Cleanup everything else. prefix := "" diff --git a/cmd/fs-v1_test.go b/cmd/fs-v1_test.go index e657bc1ac..275cdb008 100644 --- a/cmd/fs-v1_test.go +++ b/cmd/fs-v1_test.go @@ -17,6 +17,7 @@ package cmd import ( + "bytes" "os" "path/filepath" "testing" @@ -59,3 +60,39 @@ func TestNewFS(t *testing.T) { } } } + +// TestFSShutdown - initialize a new FS object layer then calls Shutdown +// to check returned results +func TestFSShutdown(t *testing.T) { + // Create an FS object and shutdown it. No errors expected + disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix()) + obj, err := newFSObjects(disk) + if err != nil { + t.Fatal("Cannot create a new FS object: ", err) + } + + fs := obj.(fsObjects) + fsStorage := fs.storage.(*posix) + + bucketName := "testbucket" + objectName := "object" + objectContent := "12345" + + obj.MakeBucket(bucketName) + obj.PutObject(bucketName, objectName, int64(len(objectContent)), bytes.NewReader([]byte(objectContent)), nil) + + if err := fs.Shutdown(); err != nil { + t.Fatal("Cannot shutdown the FS object: ", err) + } + + // Create an FS and program errors with disks when shutdown is called + for i := 1; i <= 5; i++ { + naughty := newNaughtyDisk(fsStorage, map[int]error{i: errFaultyDisk}, nil) + fs.storage = naughty + if err := fs.Shutdown(); err != errFaultyDisk { + t.Fatal(i, ", Got unexpected fs shutdown error: ", err) + } + } + + removeAll(disk) +}