Skip to content

Commit

Permalink
Merge pull request #436 from PlakarKorp/jcastets/fix-clone-help
Browse files Browse the repository at this point in the history
clone: improve error messages, avoid duplicates
  • Loading branch information
brmzkw authored Feb 7, 2025
2 parents 5183774 + 506937c commit c688d6f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions cmd/plakar/subcommands/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ func (cmd *Clone) Execute(ctx *appcontext.AppContext, repo *repository.Repositor

cloneStore, err := storage.Create(cmd.Dest, configuration)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: could not create repository: %s\n", cmd.Dest, err)
return 1, err
return 1, fmt.Errorf("could not create repository: %w", err)
}

packfileChecksums, err := sourceStore.GetPackfiles()
if err != nil {
fmt.Fprintf(os.Stderr, "%s: could not get packfiles list from repository: %s\n", sourceStore.Location(), err)
return 1, err
return 1, fmt.Errorf("could not get packfiles list from repository: %w", err)
}

wg := sync.WaitGroup{}
Expand All @@ -92,13 +90,13 @@ func (cmd *Clone) Execute(ctx *appcontext.AppContext, repo *repository.Repositor

rd, err := sourceStore.GetPackfile(packfileChecksum)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: could not get packfile from repository: %s\n", sourceStore.Location(), err)
fmt.Fprintf(os.Stderr, "could not get packfile from repository: %s\n", err)
return
}

err = cloneStore.PutPackfile(packfileChecksum, rd)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: could not put packfile to repository: %s\n", cloneStore.Location(), err)
fmt.Fprintf(os.Stderr, "could not put packfile to repository: %s\n", err)
return
}
}(_packfileChecksum)
Expand All @@ -107,8 +105,7 @@ func (cmd *Clone) Execute(ctx *appcontext.AppContext, repo *repository.Repositor

indexesChecksums, err := sourceStore.GetStates()
if err != nil {
fmt.Fprintf(os.Stderr, "%s: could not get paclfiles list from repository: %s\n", sourceStore.Location(), err)
return 1, err
return 1, fmt.Errorf("could not get packfiles list from repository: %w", err)
}

wg = sync.WaitGroup{}
Expand All @@ -119,13 +116,13 @@ func (cmd *Clone) Execute(ctx *appcontext.AppContext, repo *repository.Repositor

data, err := sourceStore.GetState(indexChecksum)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: could not get index from repository: %s\n", sourceStore.Location(), err)
fmt.Fprintf(os.Stderr, "could not get index from repository: %s\n", err)
return
}

err = cloneStore.PutState(indexChecksum, data)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: could not put packfile to repository: %s\n", cloneStore.Location(), err)
fmt.Fprintf(os.Stderr, "could not put packfile to repository: %s\n", err)
return
}
}(_indexChecksum)
Expand Down

0 comments on commit c688d6f

Please sign in to comment.