diff --git a/asset/boltdb_manager.go b/asset/boltdb_manager.go index 5ee0c84dd..a3cc57e27 100644 --- a/asset/boltdb_manager.go +++ b/asset/boltdb_manager.go @@ -247,7 +247,7 @@ func (b *boltDBAssetManager) expandWithDuration(tmpFile *os.File, asset *corev2. CacheDir := viper.GetString(FlagCacheDir) fullPath := filepath.Join(CacheDir, assetSHA) - if err := CleanUp(fullPath); err != nil { + if err := os.RemoveAll(fullPath); err != nil { logger.WithField("assetSHA path", fullPath).WithError(err). Error("error cleaning up the assetSHA") } diff --git a/asset/boltdb_manager_test.go b/asset/boltdb_manager_test.go index 6d494f006..d41ca7a4b 100644 --- a/asset/boltdb_manager_test.go +++ b/asset/boltdb_manager_test.go @@ -7,6 +7,7 @@ import ( "io" "io/ioutil" "os" + "path/filepath" "testing" bolt "go.etcd.io/bbolt" @@ -218,6 +219,33 @@ func TestFailedExpand(t *testing.T) { t.Log("expected error, got nil") t.Fail() } + + // Create a temporary directory for testing + tmpDir := t.TempDir() + + // Define the SHA and file name + SHAName := "shaAsset.tar" + SHAFilePath := filepath.Join(tmpDir, SHAName) + + // Create a dummy file inside the temporary directory + SHAFile, err := os.Create(SHAFilePath) + if err != nil { + t.Fatalf("Failed to create dummy file: %v", err) + } + SHAFile.Close() + + // Call CleanUp with the SHA of the dummy file and the temporary directory + err = os.RemoveAll(SHAFilePath) + if err != nil { + t.Errorf("CleanUp returned an error: %v", err) + t.Fail() + } + + _, err = os.Stat(SHAFilePath) + if !os.IsNotExist(err) { + t.Errorf("CleanUp did not remove the dummy file as expected") + t.Fail() + } } func TestSuccessfulGetAsset(t *testing.T) { diff --git a/asset/expander.go b/asset/expander.go index ef59d7bc1..03929a682 100644 --- a/asset/expander.go +++ b/asset/expander.go @@ -3,10 +3,8 @@ package asset import ( "errors" "fmt" - "io" - "os" - archiver "github.com/mholt/archiver/v3" + "io" filetype "gopkg.in/h2non/filetype.v1" filetype_types "gopkg.in/h2non/filetype.v1/types" @@ -93,6 +91,6 @@ func sniffType(f io.ReadSeeker) (filetype_types.Type, error) { } // cleanup of the assetSHA when cache dir gets force deleted -func CleanUp(fullPath string) error { - return os.RemoveAll(fullPath) -} +//func CleanUp(fullPath string) error { +// return os.RemoveAll(fullPath) +//} diff --git a/asset/expander_test.go b/asset/expander_test.go index 44236c6b5..7ae10c7a7 100644 --- a/asset/expander_test.go +++ b/asset/expander_test.go @@ -115,31 +115,31 @@ func TestExpandInvalidArchive(t *testing.T) { } // ---Test to check CleanUp -func TestCleanUp(t *testing.T) { - t.Parallel() - - // Create a temporary directory for testing - tmpDir := t.TempDir() - - // Define the SHA and file name - SHAName := "shaAsset.tar" - SHAFilePath := filepath.Join(tmpDir, SHAName) - - // Create a dummy file inside the temporary directory - SHAFile, err := os.Create(SHAFilePath) - if err != nil { - t.Fatalf("Failed to create dummy file: %v", err) - } - SHAFile.Close() - - // Call CleanUp with the SHA of the dummy file and the temporary directory - err = CleanUp(SHAFilePath) - if err != nil { - t.Errorf("CleanUp returned an error: %v", err) - } - - _, err = os.Stat(SHAFilePath) - if !os.IsNotExist(err) { - t.Errorf("CleanUp did not remove the dummy file as expected") - } -} +//func TestCleanUp(t *testing.T) { +// t.Parallel() +// +// // Create a temporary directory for testing +// tmpDir := t.TempDir() +// +// // Define the SHA and file name +// SHAName := "shaAsset.tar" +// SHAFilePath := filepath.Join(tmpDir, SHAName) +// +// // Create a dummy file inside the temporary directory +// SHAFile, err := os.Create(SHAFilePath) +// if err != nil { +// t.Fatalf("Failed to create dummy file: %v", err) +// } +// SHAFile.Close() +// +// // Call CleanUp with the SHA of the dummy file and the temporary directory +// err = CleanUp(SHAFilePath) +// if err != nil { +// t.Errorf("CleanUp returned an error: %v", err) +// } +// +// _, err = os.Stat(SHAFilePath) +// if !os.IsNotExist(err) { +// t.Errorf("CleanUp did not remove the dummy file as expected") +// } +//}