@@ -125,15 +125,13 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
125
125
return err
126
126
}
127
127
infos [i ] = uploadInfo
128
-
129
128
} else if objectHash , err = t .HashObject (file ); err != nil {
130
129
return err
131
130
}
132
131
133
132
// Add the object to the index
134
133
if err := t .AddObjectToIndex ("100644" , objectHash , path .Join (opts .TreePath , uploadInfo .upload .Name )); err != nil {
135
134
return err
136
-
137
135
}
138
136
}
139
137
@@ -170,28 +168,10 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
170
168
// OK now we can insert the data into the store - there's no way to clean up the store
171
169
// once it's in there, it's in there.
172
170
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 {
179
173
return cleanUpAfterFailure (& infos , t , err )
180
174
}
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
- }
195
175
}
196
176
197
177
// Then push this tree to NewBranch
@@ -201,3 +181,29 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
201
181
202
182
return models .DeleteUploads (uploads ... )
203
183
}
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