MCPcopy
hub / github.com/lxc/incus / createStoragePoolBucketFromBackup

Function createStoragePoolBucketFromBackup

cmd/incusd/storage_buckets.go:1548–1644  ·  view source on GitHub ↗
(s *state.State, r *http.Request, requestProjectName string, projectName string, data io.Reader, pool string, bucketName string)

Source from the content-addressed store, hash-verified

1546}
1547
1548func createStoragePoolBucketFromBackup(s *state.State, r *http.Request, requestProjectName string, projectName string, data io.Reader, pool string, bucketName string) response.Response {
1549 reverter := revert.New()
1550 defer reverter.Fail()
1551
1552 // Create temporary file to store uploaded backup data.
1553 backupFile, err := os.CreateTemp(internalUtil.VarPath("backups"), fmt.Sprintf("%s_", backup.WorkingDirPrefix))
1554 if err != nil {
1555 return response.InternalError(err)
1556 }
1557
1558 defer logger.WarnOnError(func() error { return os.Remove(backupFile.Name()) }, "Failed to remove backup file")
1559 reverter.Add(func() { _ = backupFile.Close() })
1560
1561 // Get disk budget for the project if any.
1562 var budget int64
1563
1564 err = s.DB.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error {
1565 budget, err = project.GetSpaceBudget(tx, projectName)
1566 if err != nil {
1567 return err
1568 }
1569
1570 return nil
1571 })
1572 if err != nil {
1573 return response.InternalError(err)
1574 }
1575
1576 // Stream uploaded backup data into temporary file.
1577 _, err = util.SafeCopy(internalIO.NewQuotaWriter(backupFile, budget), data)
1578 if err != nil {
1579 return response.InternalError(err)
1580 }
1581
1582 // Parse the backup information.
1583 _, err = backupFile.Seek(0, io.SeekStart)
1584 if err != nil {
1585 return response.InternalError(err)
1586 }
1587
1588 logger.Debug("Reading backup file info")
1589 bInfo, err := backup.GetInfo(backupFile, s.OS, backupFile.Name())
1590 if err != nil {
1591 return response.BadRequest(err)
1592 }
1593
1594 bInfo.Project = projectName
1595
1596 // Override pool.
1597 if pool != "" {
1598 bInfo.Pool = pool
1599 }
1600
1601 // Override bucket name.
1602 if bucketName != "" {
1603 bInfo.Name = bucketName
1604 }
1605

Callers 1

storagePoolBucketsPostFunction · 0.85

Calls 15

NewFunction · 0.92
InternalErrorFunction · 0.92
WarnOnErrorFunction · 0.92
GetSpaceBudgetFunction · 0.92
SafeCopyFunction · 0.92
DebugFunction · 0.92
GetInfoFunction · 0.92
BadRequestFunction · 0.92
NewURLFunction · 0.92
OperationCreateFunction · 0.92
OperationResponseFunction · 0.92
FailMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…