Handle the possibility of the DB not existing on startup
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2022-11-30 22:38:22 -08:00
parent 56550a5135
commit 0ac8ccac81
2 changed files with 22 additions and 4 deletions

View File

@ -17,6 +17,10 @@ var (
DBPath string
)
// DBPresent is true if the database
// was present when LURE was started
var DBPresent bool
func init() {
cfgDir, err := os.UserConfigDir()
if err != nil {
@ -66,4 +70,7 @@ func init() {
}
DBPath = filepath.Join(CacheDir, "db")
_, err = os.ReadDir(DBPath)
DBPresent = err == nil
}

View File

@ -68,15 +68,26 @@ func Pull(ctx context.Context, gdb *genji.DB, repos []types.Repo) error {
}
repoFS = w.Filesystem
if !errors.Is(err, git.NoErrAlreadyUpToDate) {
// Make sure the DB is created even if the repo is up to date
if !errors.Is(err, git.NoErrAlreadyUpToDate) || !config.DBPresent {
new, err := r.Head()
if err != nil {
return err
}
err = processRepoChanges(ctx, repo, r, old, new, gdb)
if err != nil {
return err
// If the DB was not present at startup, that means it's
// empty. In this case, we need to update the DB fully
// rather than just incrementally.
if config.DBPresent {
err = processRepoChanges(ctx, repo, r, old, new, gdb)
if err != nil {
return err
}
} else {
err = processRepoFull(ctx, repo, repoDir, gdb)
if err != nil {
return err
}
}
}
} else {