Skip to content
/ incus Public
forked from lxc/incus

Commit

Permalink
incusd/instances/publish: Fix base metadata
Browse files Browse the repository at this point in the history
Closes lxc#1371

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Nov 14, 2024
1 parent 58a72e0 commit 12b7b37
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
51 changes: 27 additions & 24 deletions internal/server/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5188,6 +5188,30 @@ func (d *lxc) Export(w io.Writer, properties map[string]string, expiration time.
return nil
}

// Get the instance's architecture.
var arch string
if d.IsSnapshot() {
parentName, _, _ := api.GetParentAndSnapshotName(d.name)
parent, err := instance.LoadByProjectAndName(d.state, d.project.Name, parentName)
if err != nil {
_ = tarWriter.Close()
d.logger.Error("Failed exporting instance", ctxMap)
return meta, err
}

arch, _ = osarch.ArchitectureName(parent.Architecture())
} else {
arch, _ = osarch.ArchitectureName(d.architecture)
}

if arch == "" {
arch, err = osarch.ArchitectureName(d.state.OS.Architectures[0])
if err != nil {
d.logger.Error("Failed exporting instance", ctxMap)
return meta, err
}
}

// Look for metadata.yaml.
fnam := filepath.Join(cDir, "metadata.yaml")
if !util.PathExists(fnam) {
Expand All @@ -5201,30 +5225,6 @@ func (d *lxc) Export(w io.Writer, properties map[string]string, expiration time.

defer func() { _ = os.RemoveAll(tempDir) }()

// Get the instance's architecture.
var arch string
if d.IsSnapshot() {
parentName, _, _ := api.GetParentAndSnapshotName(d.name)
parent, err := instance.LoadByProjectAndName(d.state, d.project.Name, parentName)
if err != nil {
_ = tarWriter.Close()
d.logger.Error("Failed exporting instance", ctxMap)
return meta, err
}

arch, _ = osarch.ArchitectureName(parent.Architecture())
} else {
arch, _ = osarch.ArchitectureName(d.architecture)
}

if arch == "" {
arch, err = osarch.ArchitectureName(d.state.OS.Architectures[0])
if err != nil {
d.logger.Error("Failed exporting instance", ctxMap)
return meta, err
}
}

// Fill in the metadata.
meta.Architecture = arch
meta.CreationDate = time.Now().UTC().Unix()
Expand Down Expand Up @@ -5280,6 +5280,9 @@ func (d *lxc) Export(w io.Writer, properties map[string]string, expiration time.
return meta, err
}

// Fill in the metadata.
meta.Architecture = arch
meta.CreationDate = time.Now().UTC().Unix()

This comment has been minimized.

Copy link
@Salamandar

Salamandar Nov 14, 2024

This is actually already present line 5229.

Also it should be outside the block starting with if !util.PathExists(fnam) { because it needs to be set whether the file already exists or not.

if !expiration.IsZero() {
meta.ExpiryDate = expiration.UTC().Unix()
}
Expand Down
51 changes: 27 additions & 24 deletions internal/server/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6378,6 +6378,30 @@ func (d *qemu) Export(w io.Writer, properties map[string]string, expiration time
return nil
}

// Get the instance's architecture.
var arch string
if d.IsSnapshot() {
parentName, _, _ := api.GetParentAndSnapshotName(d.name)
parent, err := instance.LoadByProjectAndName(d.state, d.project.Name, parentName)
if err != nil {
_ = tarWriter.Close()
d.logger.Error("Failed exporting instance", ctxMap)
return meta, err
}

arch, _ = osarch.ArchitectureName(parent.Architecture())
} else {
arch, _ = osarch.ArchitectureName(d.architecture)
}

if arch == "" {
arch, err = osarch.ArchitectureName(d.state.OS.Architectures[0])
if err != nil {
d.logger.Error("Failed exporting instance", ctxMap)
return meta, err
}
}

// Look for metadata.yaml.
fnam := filepath.Join(cDir, "metadata.yaml")
if !util.PathExists(fnam) {
Expand All @@ -6391,30 +6415,6 @@ func (d *qemu) Export(w io.Writer, properties map[string]string, expiration time

defer func() { _ = os.RemoveAll(tempDir) }()

// Get the instance's architecture.
var arch string
if d.IsSnapshot() {
parentName, _, _ := api.GetParentAndSnapshotName(d.name)
parent, err := instance.LoadByProjectAndName(d.state, d.project.Name, parentName)
if err != nil {
_ = tarWriter.Close()
d.logger.Error("Failed exporting instance", ctxMap)
return meta, err
}

arch, _ = osarch.ArchitectureName(parent.Architecture())
} else {
arch, _ = osarch.ArchitectureName(d.architecture)
}

if arch == "" {
arch, err = osarch.ArchitectureName(d.state.OS.Architectures[0])
if err != nil {
d.logger.Error("Failed exporting instance", ctxMap)
return meta, err
}
}

// Fill in the metadata.
meta.Architecture = arch
meta.CreationDate = time.Now().UTC().Unix()
Expand Down Expand Up @@ -6469,6 +6469,9 @@ func (d *qemu) Export(w io.Writer, properties map[string]string, expiration time
return meta, err
}

// Fill in the metadata.
meta.Architecture = arch
meta.CreationDate = time.Now().UTC().Unix()
if !expiration.IsZero() {
meta.ExpiryDate = expiration.UTC().Unix()
}
Expand Down

0 comments on commit 12b7b37

Please sign in to comment.