Skip to content

Commit e1965cd

Browse files
committed
fix: repos is removed if an error occurred while upgrading (fix #195)
1 parent 6431902 commit e1965cd

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

cmd/get.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,6 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
339339
fromHash, err = gitutil.GetHEAD(reposPath)
340340
if err != nil {
341341
result := errors.New("failed to get HEAD commit hash: " + err.Error())
342-
logger.Debug("Rollbacking " + fullReposPath + " ...")
343-
err = cmd.rollbackRepos(fullReposPath)
344-
if err != nil {
345-
result = multierror.Append(result, err)
346-
}
347342
done <- getParallelResult{
348343
reposPath: reposPath,
349344
status: fmt.Sprintf(fmtInstallFailed, reposPath),
@@ -372,11 +367,6 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
372367
err := cmd.upgradePlugin(reposPath, cfg)
373368
if err != git.NoErrAlreadyUpToDate && err != nil {
374369
result := errors.New("failed to upgrade plugin: " + err.Error())
375-
logger.Debug("Rollbacking " + fullReposPath + " ...")
376-
err = cmd.rollbackRepos(fullReposPath)
377-
if err != nil {
378-
result = multierror.Append(result, err)
379-
}
380370
done <- getParallelResult{
381371
reposPath: reposPath,
382372
status: fmt.Sprintf(fmtUpgradeFailed, reposPath),
@@ -396,7 +386,7 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
396386
if err != nil {
397387
result := errors.New("failed to install plugin: " + err.Error())
398388
logger.Debug("Rollbacking " + fullReposPath + " ...")
399-
err = cmd.rollbackRepos(fullReposPath)
389+
err = cmd.removeDir(fullReposPath)
400390
if err != nil {
401391
result = multierror.Append(result, err)
402392
}
@@ -420,10 +410,12 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
420410
toHash, err = gitutil.GetHEAD(reposPath)
421411
if err != nil {
422412
result := errors.New("failed to get HEAD commit hash: " + err.Error())
423-
logger.Debug("Rollbacking " + fullReposPath + " ...")
424-
err = cmd.rollbackRepos(fullReposPath)
425-
if err != nil {
426-
result = multierror.Append(result, err)
413+
if doInstall {
414+
logger.Debug("Rollbacking " + fullReposPath + " ...")
415+
err = cmd.removeDir(fullReposPath)
416+
if err != nil {
417+
result = multierror.Append(result, err)
418+
}
427419
}
428420
done <- getParallelResult{
429421
reposPath: reposPath,
@@ -460,12 +452,14 @@ func (cmd *getCmd) installPlugconf(reposPath pathutil.ReposPath, pluginResult *g
460452
err := cmd.fetchPlugconf(reposPath)
461453
if err != nil {
462454
result := errors.New("failed to install plugconf: " + err.Error())
463-
fullReposPath := pathutil.FullReposPath(reposPath)
464-
logger.Debug("Rollbacking " + fullReposPath + " ...")
465-
err = cmd.rollbackRepos(fullReposPath)
466-
if err != nil {
467-
result = multierror.Append(result, err)
468-
}
455+
// TODO: Call cmd.removeDir() only when the repos *did not* exist previously
456+
// and was installed newly.
457+
// fullReposPath := pathutil.FullReposPath(reposPath)
458+
// logger.Debug("Rollbacking " + fullReposPath + " ...")
459+
// err = cmd.removeDir(fullReposPath)
460+
// if err != nil {
461+
// result = multierror.Append(result, err)
462+
// }
469463
done <- getParallelResult{
470464
reposPath: reposPath,
471465
status: fmt.Sprintf(fmtInstallFailed, reposPath),
@@ -486,7 +480,7 @@ func (*getCmd) detectReposType(fullpath string) (lockjson.ReposType, error) {
486480
return lockjson.ReposStaticType, nil
487481
}
488482

489-
func (*getCmd) rollbackRepos(fullReposPath string) error {
483+
func (*getCmd) removeDir(fullReposPath string) error {
490484
if pathutil.Exists(fullReposPath) {
491485
err := os.RemoveAll(fullReposPath)
492486
if err != nil {

0 commit comments

Comments
 (0)