Skip to content

Commit 3b2739b

Browse files
authored
Closing iterator for import listing and validate args (treeverse#1398)
1 parent c8ad8bb commit 3b2739b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

catalog/entry_catalog.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,21 @@ func NewEntryCatalog(cfg *config.Config, db db.Database) (*EntryCatalog, error)
133133
}
134134

135135
func (e *EntryCatalog) AddCommitToBranchHead(ctx context.Context, repositoryID graveler.RepositoryID, branchID graveler.BranchID, commit graveler.Commit) (graveler.CommitID, error) {
136+
if err := Validate([]ValidateArg{
137+
{"repositoryID", repositoryID, ValidateRepositoryID},
138+
{"branchID", branchID, ValidateBranchID},
139+
}); err != nil {
140+
return "", err
141+
}
136142
return e.Store.AddCommitToBranchHead(ctx, repositoryID, branchID, commit)
137143
}
138144

139145
func (e *EntryCatalog) AddCommit(ctx context.Context, repositoryID graveler.RepositoryID, commit graveler.Commit) (graveler.CommitID, error) {
146+
if err := Validate([]ValidateArg{
147+
{"repositoryID", repositoryID, ValidateRepositoryID},
148+
}); err != nil {
149+
return "", err
150+
}
140151
return e.Store.AddCommit(ctx, repositoryID, commit)
141152
}
142153

graveler/graveler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ func (g *Graveler) validateCommitParent(ctx context.Context, repositoryID Reposi
946946
return parentCommitID, nil
947947
}
948948

949-
func (g *Graveler) commitExists(ctx context.Context, repositoryID RepositoryID, commitID CommitID) (bool, error) {
949+
func (g *Graveler) isCommitExist(ctx context.Context, repositoryID RepositoryID, commitID CommitID) (bool, error) {
950950
_, err := g.RefManager.GetCommit(ctx, repositoryID, commitID)
951951
if err == nil {
952952
// commit already exists
@@ -977,7 +977,7 @@ func (g *Graveler) AddCommitToBranchHead(ctx context.Context, repositoryID Repos
977977

978978
// check if commit already exists.
979979
commitID := CommitID(ident.NewHexAddressProvider().ContentAddress(commit))
980-
if exists, err := g.commitExists(ctx, repositoryID, commitID); err != nil {
980+
if exists, err := g.isCommitExist(ctx, repositoryID, commitID); err != nil {
981981
return nil, err
982982
} else if exists {
983983
return commitID, nil
@@ -1011,7 +1011,7 @@ func (g *Graveler) AddCommit(ctx context.Context, repositoryID RepositoryID, com
10111011

10121012
// check if commit already exists.
10131013
commitID := CommitID(ident.NewHexAddressProvider().ContentAddress(commit))
1014-
if exists, err := g.commitExists(ctx, repositoryID, commitID); err != nil {
1014+
if exists, err := g.isCommitExist(ctx, repositoryID, commitID); err != nil {
10151015
return "", err
10161016
} else if exists {
10171017
return commitID, nil

onboard/catalog_actions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (c *CatalogRepoActions) ApplyImport(ctx context.Context, it Iterator, _ boo
8989
if err != nil {
9090
return nil, fmt.Errorf("listing commit: %w", err)
9191
}
92+
defer listIt.Close()
9293

9394
c.createdMetaRangeID, err = c.entryCataloger.WriteMetaRange(ctx, c.repoID, newPrefixMergeIterator(NewValueToEntryIterator(invIt, c.progress), listIt, c.prefixes))
9495
if err != nil {

0 commit comments

Comments
 (0)