Skip to content

Commit 709fcfa

Browse files
committed
Skip upload if object exists.
1 parent c45f43c commit 709fcfa

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

services/lfs/server.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ func BatchHandler(ctx *context.Context) {
219219

220220
exists, err := contentStore.Exists(p)
221221
if err != nil {
222-
log.Error("Unable to check if LFS OID[%s] exist on %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
222+
log.Error("Unable to check if LFS OID[%s] exist. Error: %v", p.Oid, rc.User, rc.Repo, err)
223223
writeStatus(ctx, http.StatusInternalServerError)
224224
return
225225
}
226226

227-
meta, metaErr := repository.GetLFSMetaObjectByOid(p.Oid)
228-
if metaErr != nil && metaErr != models.ErrLFSObjectNotExist {
229-
log.Error("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, metaErr)
227+
meta, err := repository.GetLFSMetaObjectByOid(p.Oid)
228+
if err != nil && err != models.ErrLFSObjectNotExist {
229+
log.Error("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
230230
writeStatus(ctx, http.StatusInternalServerError)
231231
return
232232
}
@@ -315,6 +315,18 @@ func UploadHandler(ctx *context.Context) {
315315
}
316316

317317
contentStore := lfs_module.NewContentStore()
318+
319+
exists, err := contentStore.Exists(p)
320+
if err != nil {
321+
log.Error("Unable to check if LFS OID[%s] exist. Error: %v", p.Oid, err)
322+
writeStatus(ctx, http.StatusInternalServerError)
323+
return
324+
}
325+
if m.Existing || exisits {
326+
ctx.Resp.WriteHeader(http.StatusOK)
327+
return
328+
}
329+
318330
defer ctx.Req.Body.Close()
319331
if err := contentStore.Put(meta.Pointer, ctx.Req.Body); err != nil {
320332
if err == lfs_module.ErrSizeMismatch || err == lfs_module.ErrHashMismatch {

0 commit comments

Comments
 (0)