Skip to content

Commit

Permalink
(bug) Always overwrite local db when copying
Browse files Browse the repository at this point in the history
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()
  • Loading branch information
kevinrizza committed May 1, 2020
1 parent 5c21e0f commit 84ee6f0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/lib/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down

0 comments on commit 84ee6f0

Please sign in to comment.