@@ -125,15 +125,13 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
125125 return err
126126 }
127127 infos [i ] = uploadInfo
128-
129128 } else if objectHash , err = t .HashObject (file ); err != nil {
130129 return err
131130 }
132131
133132 // Add the object to the index
134133 if err := t .AddObjectToIndex ("100644" , objectHash , path .Join (opts .TreePath , uploadInfo .upload .Name )); err != nil {
135134 return err
136-
137135 }
138136 }
139137
@@ -170,28 +168,10 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
170168 // OK now we can insert the data into the store - there's no way to clean up the store
171169 // once it's in there, it's in there.
172170 contentStore := & lfs.ContentStore {ObjectStorage : storage .LFS }
173- for _ , uploadInfo := range infos {
174- if uploadInfo .lfsMetaObject == nil {
175- continue
176- }
177- exist , err := contentStore .Exists (uploadInfo .lfsMetaObject )
178- if err != nil {
171+ for _ , info := range infos {
172+ if err := uploadToLFSContentStore (info , contentStore ); err != nil {
179173 return cleanUpAfterFailure (& infos , t , err )
180174 }
181- if ! exist {
182- file , err := os .Open (uploadInfo .upload .LocalPath ())
183- if err != nil {
184- return cleanUpAfterFailure (& infos , t , err )
185- }
186- defer file .Close ()
187- // FIXME: Put regenerates the hash and copies the file over.
188- // I guess this strictly ensures the soundness of the store but this is inefficient.
189- if err := contentStore .Put (uploadInfo .lfsMetaObject , file ); err != nil {
190- // OK Now we need to cleanup
191- // Can't clean up the store, once uploaded there they're there.
192- return cleanUpAfterFailure (& infos , t , err )
193- }
194- }
195175 }
196176
197177 // Then push this tree to NewBranch
@@ -201,3 +181,29 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
201181
202182 return models .DeleteUploads (uploads ... )
203183}
184+
185+ func uploadToLFSContentStore (info uploadInfo , contentStore * lfs.ContentStore ) error {
186+ if info .lfsMetaObject == nil {
187+ return nil
188+ }
189+ exist , err := contentStore .Exists (info .lfsMetaObject )
190+ if err != nil {
191+ return err
192+ }
193+ if ! exist {
194+ file , err := os .Open (info .upload .LocalPath ())
195+ if err != nil {
196+ return err
197+ }
198+
199+ defer file .Close ()
200+ // FIXME: Put regenerates the hash and copies the file over.
201+ // I guess this strictly ensures the soundness of the store but this is inefficient.
202+ if err := contentStore .Put (info .lfsMetaObject , file ); err != nil {
203+ // OK Now we need to cleanup
204+ // Can't clean up the store, once uploaded there they're there.
205+ return err
206+ }
207+ }
208+ return nil
209+ }
0 commit comments