MCPcopy
hub / github.com/aptly-dev/aptly / apiSnapshotsCreate

Function apiSnapshotsCreate

api/snapshot.go:158–250  ·  view source on GitHub ↗

@Summary Snapshot Packages @Description **Create a snapshot from package refs** @Description @Description Refs can be obtained from snapshots, local repos, or mirrors @Tags Snapshots @Param request body snapshotsCreateParams true "Parameters" @Param _async query bool false "Run in background and ret

(c *gin.Context)

Source from the content-addressed store, hash-verified

156// @Failure 500 {object} Error "Internal Server Error"
157// @Router /api/snapshots [post]
158func apiSnapshotsCreate(c *gin.Context) {
159 var (
160 err error
161 snapshot *deb.Snapshot
162 b snapshotsCreateParams
163 )
164
165 if c.Bind(&b) != nil {
166 return
167 }
168
169 if b.Description == "" {
170 if len(b.SourceSnapshots)+len(b.PackageRefs) == 0 {
171 b.Description = "Created as empty"
172 }
173 }
174
175 // Phase 1: Pre-task validation (shallow load for 404 checks only)
176 collectionFactory := context.NewCollectionFactory()
177 snapshotCollection := collectionFactory.SnapshotCollection()
178 var resources []string
179
180 sources := make([]*deb.Snapshot, len(b.SourceSnapshots))
181
182 for i := range b.SourceSnapshots {
183 sources[i], err = snapshotCollection.ByName(b.SourceSnapshots[i])
184 if err != nil {
185 AbortWithJSONError(c, 404, err)
186 return
187 }
188
189 resources = append(resources, string(sources[i].Key()))
190 }
191
192 maybeRunTaskInBackground(c, "Create snapshot "+b.Name, resources, func(_ aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
193 // Phase 2: Inside task lock - create fresh factory
194 taskCollectionFactory := context.NewCollectionFactory()
195 taskSnapshotCollection := taskCollectionFactory.SnapshotCollection()
196 taskPackageCollection := taskCollectionFactory.PackageCollection()
197
198 // Fresh load of all sources after lock acquired
199 freshSources := make([]*deb.Snapshot, len(b.SourceSnapshots))
200 for i := range b.SourceSnapshots {
201 freshSources[i], err = taskSnapshotCollection.ByName(b.SourceSnapshots[i])
202 if err != nil {
203 return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
204 }
205 // LoadComplete on fresh copy
206 err = taskSnapshotCollection.LoadComplete(freshSources[i])
207 if err != nil {
208 return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
209 }
210 }
211
212 // Merge packages from all source snapshots
213 var refList *deb.PackageRefList
214 if len(freshSources) > 0 {
215 refList = freshSources[0].RefList()

Callers

nothing calls this directly

Calls 15

SnapshotCollectionMethod · 0.95
PackageCollectionMethod · 0.95
MergeMethod · 0.95
AddMethod · 0.95
NewPackageRefListFunction · 0.92
NewPackageListFunction · 0.92
NewSnapshotFromRefListFunction · 0.92
AbortWithJSONErrorFunction · 0.85
maybeRunTaskInBackgroundFunction · 0.85
NewCollectionFactoryMethod · 0.80
ByKeyMethod · 0.80

Tested by

no test coverage detected