From 82db3bf2d45d859dcfd79d2f20adae7419c76b3c Mon Sep 17 00:00:00 2001 From: kevinrizza Date: Thu, 30 Apr 2020 16:18:42 -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, 4 insertions(+), 6 deletions(-) diff --git a/pkg/lib/indexer/indexer.go b/pkg/lib/indexer/indexer.go index c7862a0afa..8f4deb80b0 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,8 +339,6 @@ func copyDatabaseTo(databaseFile, targetDir string) (string, error) { if err := os.MkdirAll(targetDir, 0777); err != nil { return "", err } - } else { - return "", err } // Open the database file in the working dir @@ -353,7 +351,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 }