[lxc-devel] [lxd/master] lxd import: handle non-existing snapshots path
brauner on Github
lxc-bot at linuxcontainers.org
Thu Apr 20 15:48:13 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 381 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170420/82d30841/attachment.bin>
-------------- next part --------------
From ebc81ed050238547b63da69c7ad4ba573bc7830a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 20 Apr 2017 17:47:00 +0200
Subject: [PATCH] lxd import: handle non-existing snapshots path
Closes #3198.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/api_internal.go | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/lxd/api_internal.go b/lxd/api_internal.go
index f9627e9..2298d84 100644
--- a/lxd/api_internal.go
+++ b/lxd/api_internal.go
@@ -249,19 +249,22 @@ func internalImport(d *Daemon, r *http.Request) Response {
// Detect discrepancy between snapshots recorded in "backup.yaml" and
// those actually existing on disk.
+ snapshotNames := []string{}
snapshotsPath := getSnapshotMountPoint(containerPoolName, req.Name)
snapshotsDir, err := os.Open(snapshotsPath)
if err != nil {
- return InternalError(err)
- }
-
- // Get a list of all snapshots that exist on disk.
- snapshotNames, err := snapshotsDir.Readdirnames(-1)
- if err != nil {
+ if !os.IsNotExist(err) {
+ return InternalError(err)
+ }
+ } else {
+ // Get a list of all snapshots that exist on disk.
+ snapshotNames, err = snapshotsDir.Readdirnames(-1)
+ if err != nil {
+ snapshotsDir.Close()
+ return InternalError(err)
+ }
snapshotsDir.Close()
- return InternalError(err)
}
- snapshotsDir.Close()
onDiskSnapshots := map[string]*api.ContainerSnapshot{}
for _, snapName := range snapshotNames {
More information about the lxc-devel
mailing list