Skip to content

Commit a461d90

Browse files
6543lunnyzeripath
authored
Fix bug when upload on web (#15042) (#15055)
* Fix bug when upload on web * move into own function Co-authored-by: 6543 <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent 70e4134 commit a461d90

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

modules/repofiles/upload.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,13 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
120120
return err
121121
}
122122
infos[i] = uploadInfo
123-
124123
} else if objectHash, err = t.HashObject(file); err != nil {
125124
return err
126125
}
127126

128127
// Add the object to the index
129128
if err := t.AddObjectToIndex("100644", objectHash, path.Join(opts.TreePath, uploadInfo.upload.Name)); err != nil {
130129
return err
131-
132130
}
133131
}
134132

@@ -165,28 +163,10 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
165163
// OK now we can insert the data into the store - there's no way to clean up the store
166164
// once it's in there, it's in there.
167165
contentStore := &lfs.ContentStore{ObjectStorage: storage.LFS}
168-
for _, uploadInfo := range infos {
169-
if uploadInfo.lfsMetaObject == nil {
170-
continue
171-
}
172-
exist, err := contentStore.Exists(uploadInfo.lfsMetaObject)
173-
if err != nil {
166+
for _, info := range infos {
167+
if err := uploadToLFSContentStore(info, contentStore); err != nil {
174168
return cleanUpAfterFailure(&infos, t, err)
175169
}
176-
if !exist {
177-
file, err := os.Open(uploadInfo.upload.LocalPath())
178-
if err != nil {
179-
return cleanUpAfterFailure(&infos, t, err)
180-
}
181-
defer file.Close()
182-
// FIXME: Put regenerates the hash and copies the file over.
183-
// I guess this strictly ensures the soundness of the store but this is inefficient.
184-
if err := contentStore.Put(uploadInfo.lfsMetaObject, file); err != nil {
185-
// OK Now we need to cleanup
186-
// Can't clean up the store, once uploaded there they're there.
187-
return cleanUpAfterFailure(&infos, t, err)
188-
}
189-
}
190170
}
191171

192172
// Then push this tree to NewBranch
@@ -196,3 +176,29 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
196176

197177
return models.DeleteUploads(uploads...)
198178
}
179+
180+
func uploadToLFSContentStore(info uploadInfo, contentStore *lfs.ContentStore) error {
181+
if info.lfsMetaObject == nil {
182+
return nil
183+
}
184+
exist, err := contentStore.Exists(info.lfsMetaObject)
185+
if err != nil {
186+
return err
187+
}
188+
if !exist {
189+
file, err := os.Open(info.upload.LocalPath())
190+
if err != nil {
191+
return err
192+
}
193+
194+
defer file.Close()
195+
// FIXME: Put regenerates the hash and copies the file over.
196+
// I guess this strictly ensures the soundness of the store but this is inefficient.
197+
if err := contentStore.Put(info.lfsMetaObject, file); err != nil {
198+
// OK Now we need to cleanup
199+
// Can't clean up the store, once uploaded there they're there.
200+
return err
201+
}
202+
}
203+
return nil
204+
}

0 commit comments

Comments
 (0)