@@ -120,15 +120,13 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
120
120
return err
121
121
}
122
122
infos [i ] = uploadInfo
123
-
124
123
} else if objectHash , err = t .HashObject (file ); err != nil {
125
124
return err
126
125
}
127
126
128
127
// Add the object to the index
129
128
if err := t .AddObjectToIndex ("100644" , objectHash , path .Join (opts .TreePath , uploadInfo .upload .Name )); err != nil {
130
129
return err
131
-
132
130
}
133
131
}
134
132
@@ -165,28 +163,10 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
165
163
// OK now we can insert the data into the store - there's no way to clean up the store
166
164
// once it's in there, it's in there.
167
165
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 {
174
168
return cleanUpAfterFailure (& infos , t , err )
175
169
}
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
- }
190
170
}
191
171
192
172
// Then push this tree to NewBranch
@@ -196,3 +176,29 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
196
176
197
177
return models .DeleteUploads (uploads ... )
198
178
}
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