Handle the possibility of the DB not existing on startup
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
56550a5135
commit
0ac8ccac81
|
@ -17,6 +17,10 @@ var (
|
||||||
DBPath string
|
DBPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DBPresent is true if the database
|
||||||
|
// was present when LURE was started
|
||||||
|
var DBPresent bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cfgDir, err := os.UserConfigDir()
|
cfgDir, err := os.UserConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -66,4 +70,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
DBPath = filepath.Join(CacheDir, "db")
|
DBPath = filepath.Join(CacheDir, "db")
|
||||||
|
|
||||||
|
_, err = os.ReadDir(DBPath)
|
||||||
|
DBPresent = err == nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,15 +68,26 @@ func Pull(ctx context.Context, gdb *genji.DB, repos []types.Repo) error {
|
||||||
}
|
}
|
||||||
repoFS = w.Filesystem
|
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()
|
new, err := r.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = processRepoChanges(ctx, repo, r, old, new, gdb)
|
// If the DB was not present at startup, that means it's
|
||||||
if err != nil {
|
// empty. In this case, we need to update the DB fully
|
||||||
return err
|
// 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 {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue