// POST /api/mirrors/:name/snapshots/ func apiSnapshotsCreateFromMirror(c *gin.Context) { var ( err error repo *deb.RemoteRepo snapshot *deb.Snapshot ) var b struct { Name string `binding:"required"` Description string } if !c.Bind(&b) { return } collection := context.CollectionFactory().RemoteRepoCollection() collection.RLock() defer collection.RUnlock() snapshotCollection := context.CollectionFactory().SnapshotCollection() snapshotCollection.Lock() defer snapshotCollection.Unlock() repo, err = collection.ByName(c.Params.ByName("name")) if err != nil { c.Fail(404, err) return } err = repo.CheckLock() if err != nil { c.Fail(409, err) return } err = collection.LoadComplete(repo) if err != nil { c.Fail(500, err) return } snapshot, err = deb.NewSnapshotFromRepository(b.Name, repo) if err != nil { c.Fail(400, err) return } if b.Description != "" { snapshot.Description = b.Description } err = snapshotCollection.Add(snapshot) if err != nil { c.Fail(400, err) return } c.JSON(201, snapshot) }
func (a *Api) SnapshotCreateFromMirror(mirrorName, snapshotName, description string) (*deb.Snapshot, error) { collection := a.Ctx().CollectionFactory().RemoteRepoCollection() collection.RLock() defer collection.RUnlock() snapshotCollection := a.Ctx().CollectionFactory().SnapshotCollection() snapshotCollection.Lock() defer snapshotCollection.Unlock() repo, err := collection.ByName(mirrorName) if err != nil { return nil, err } err = repo.CheckLock() if err != nil { return nil, err } err = collection.LoadComplete(repo) if err != nil { return nil, err } snapshot, err := deb.NewSnapshotFromRepository(snapshotName, repo) if err != nil { return nil, err } snapshot.Description = description snapshotCollection.Add(snapshot) if err != nil { return nil, err } return snapshot, nil }
func aptlySnapshotCreate(cmd *commander.Command, args []string) error { var ( err error snapshot *deb.Snapshot ) if len(args) == 4 && args[1] == "from" && args[2] == "mirror" { // aptly snapshot create snap from mirror mirror var repo *deb.RemoteRepo repoName, snapshotName := args[3], args[0] repo, err = context.CollectionFactory().RemoteRepoCollection().ByName(repoName) if err != nil { return fmt.Errorf("unable to create snapshot: %s", err) } err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo) if err != nil { return fmt.Errorf("unable to create snapshot: %s", err) } snapshot, err = deb.NewSnapshotFromRepository(snapshotName, repo) if err != nil { return fmt.Errorf("unable to create snapshot: %s", err) } } else if len(args) == 4 && args[1] == "from" && args[2] == "repo" { // aptly snapshot create snap from repo repo var repo *deb.LocalRepo localRepoName, snapshotName := args[3], args[0] repo, err = context.CollectionFactory().LocalRepoCollection().ByName(localRepoName) if err != nil { return fmt.Errorf("unable to create snapshot: %s", err) } err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo) if err != nil { return fmt.Errorf("unable to create snapshot: %s", err) } snapshot, err = deb.NewSnapshotFromLocalRepo(snapshotName, repo) if err != nil { return fmt.Errorf("unable to create snapshot: %s", err) } } else if len(args) == 2 && args[1] == "empty" { // aptly snapshot create snap empty snapshotName := args[0] packageList := deb.NewPackageList() snapshot = deb.NewSnapshotFromPackageList(snapshotName, nil, packageList, "Created as empty") } else { cmd.Usage() return err } err = context.CollectionFactory().SnapshotCollection().Add(snapshot) if err != nil { return fmt.Errorf("unable to add snapshot: %s", err) } fmt.Printf("\nSnapshot %s successfully created.\nYou can run 'aptly publish snapshot %s' to publish snapshot as Debian repository.\n", snapshot.Name, snapshot.Name) return err }