From 84ee6f07460ede5ae1e971efb1143ce8319351e9 Mon Sep 17 00:00:00 2001 From: kevinrizza Date: Fri, 1 May 2020 11:32:22 -0400 Subject: [PATCH] (bug) Always overwrite local db when copying Multiple runs of index add when --generate is specified because the db file cannot be cleaned up. To account for this, update the copyDatabaseTo function to not return when the parent folder already exists and overwrite the actual database when doing io.Copy() --- pkg/lib/indexer/indexer.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/lib/indexer/indexer.go b/pkg/lib/indexer/indexer.go index c7862a0af..5eb8aa093 100644 --- a/pkg/lib/indexer/indexer.go +++ b/pkg/lib/indexer/indexer.go @@ -71,7 +71,7 @@ func (i ImageIndexer) AddToIndex(request AddToIndexRequest) error { // this is in its own function context so that the deferred cleanup runs before we do a docker build // which prevents the full contents of the previous image from being in the build context var databasePath string - if err := func () error { + if err := func() error { tmpDir, err := ioutil.TempDir("./", tmpDirPrefix) if err != nil { @@ -152,7 +152,7 @@ func (i ImageIndexer) DeleteFromIndex(request DeleteFromIndexRequest) error { // this is in its own function context so that the deferred cleanup runs before we do a docker build // which prevents the full contents of the previous image from being in the build context var databasePath string - if err := func () error { + if err := func() error { tmpDir, err := ioutil.TempDir("./", tmpDirPrefix) if err != nil { @@ -228,7 +228,7 @@ func (i ImageIndexer) PruneFromIndex(request PruneFromIndexRequest) error { // this is in its own function context so that the deferred cleanup runs before we do a docker build // which prevents the full contents of the previous image from being in the build context var databasePath string - if err := func () error { + if err := func() error { tmpDir, err := ioutil.TempDir("./", tmpDirPrefix) if err != nil { @@ -339,7 +339,7 @@ func copyDatabaseTo(databaseFile, targetDir string) (string, error) { if err := os.MkdirAll(targetDir, 0777); err != nil { return "", err } - } else { + } else if err != nil { return "", err } @@ -353,7 +353,7 @@ func copyDatabaseTo(databaseFile, targetDir string) (string, error) { dbFile := path.Join(targetDir, defaultDatabaseFile) // define the path to copy to the database/index.db file - to, err := os.OpenFile(dbFile, os.O_RDWR|os.O_CREATE, 0666) + to, err := os.OpenFile(dbFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { return "", err }