MCPcopy Index your code
hub / github.com/aptly-dev/aptly / apiFilesUploadOne

Function apiFilesUploadOne

api/files.go:207–249  ·  view source on GitHub ↗

@Summary Upload One File @Description **Upload one file to a directory** @Description @Description - file is uploaded @Description - existing uploaded are overwritten @Description @Description **Example:** @Description ``` @Description $ dput aptly aptly_0.9~dev+217+ge5d646c_i386.changes @Descripti

(c *gin.Context)

Source from the content-addressed store, hash-verified

205// @Failure 500 {object} Error "Internal Server Error"
206// @Router /api/files/{dir}/{file} [put]
207func apiFilesUploadOne(c *gin.Context) {
208 if !verifyDir(c) {
209 return
210 }
211
212 fileName := c.Params.ByName("file")
213 if !verifyPath(fileName) {
214 AbortWithJSONError(c, 400, fmt.Errorf("wrong file"))
215 return
216 }
217
218 path := filepath.Join(context.UploadPath(), utils.SanitizePath(c.Params.ByName("dir")))
219 err := os.MkdirAll(path, 0777)
220
221 if err != nil {
222 AbortWithJSONError(c, 500, err)
223 return
224 }
225 stored := []string{}
226
227 destPath := filepath.Join(path, fileName)
228 dst, err := os.Create(destPath)
229 if err != nil {
230 AbortWithJSONError(c, 500, err)
231 return
232 }
233 defer func() { _ = dst.Close() }()
234
235 if _, err = io.Copy(dst, c.Request.Body); err != nil {
236 AbortWithJSONError(c, 500, err)
237 return
238 }
239
240 if err = syncFile(dst); err != nil {
241 AbortWithJSONError(c, 500, fmt.Errorf("error syncing file %s: %s", fileName, err))
242 return
243 }
244
245 stored = append(stored, filepath.Join(c.Params.ByName("dir"), fileName))
246
247 apiFilesUploadedCounter.WithLabelValues(c.Params.ByName("dir")).Inc()
248 c.JSON(200, stored)
249}
250
251// @Summary List Files
252// @Description **Show uploaded files in upload directory**

Callers

nothing calls this directly

Calls 8

SanitizePathFunction · 0.92
verifyDirFunction · 0.85
verifyPathFunction · 0.85
AbortWithJSONErrorFunction · 0.85
UploadPathMethod · 0.80
CloseMethod · 0.65
ByNameMethod · 0.45
CopyMethod · 0.45

Tested by

no test coverage detected