[lxc-devel] [lxd/master] lxd/patches: Add missing transition for symlinks

stgraber on Github lxc-bot at linuxcontainers.org
Thu Nov 8 19:54:12 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181108/80b3c6e6/attachment.bin>
-------------- next part --------------
From ceebf6128fc55d7d8b768dd6630e1d4b213243b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 8 Nov 2018 14:35:28 -0500
Subject: [PATCH] lxd/patches: Add missing transition for symlinks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #5262

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/patches.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/lxd/patches.go b/lxd/patches.go
index d8af850966..a61721f456 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -67,6 +67,7 @@ var patches = []patch{
 	{name: "candid_rename_config_key", run: patchCandidConfigKey},
 	{name: "move_backups", run: patchMoveBackups},
 	{name: "storage_api_rename_container_snapshots_dir", run: patchStorageApiRenameContainerSnapshotsDir},
+	{name: "storage_api_rename_container_snapshots_links", run: patchStorageApiUpdateContainerSnapshots},
 }
 
 type patch struct {
@@ -3216,6 +3217,54 @@ func patchStorageApiRenameContainerSnapshotsDir(name string, d *Daemon) error {
 	return nil
 }
 
+func patchStorageApiUpdateContainerSnapshots(name string, d *Daemon) error {
+	snapshotLinksDir, err := os.Open(shared.VarPath("snapshots"))
+	if err != nil {
+		return err
+	}
+	defer snapshotLinksDir.Close()
+
+	// Get a list of all symlinks
+	snapshotLinks, err := snapshotLinksDir.Readdirnames(-1)
+	snapshotLinksDir.Close()
+	if err != nil {
+		return err
+	}
+
+	for _, linkName := range snapshotLinks {
+		targetName, err := os.Readlink(shared.VarPath("snapshots", linkName))
+		if err != nil {
+			return err
+		}
+
+		targetFields := strings.Split(targetName, "/")
+
+		if len(targetFields) < 4 {
+			continue
+		}
+
+		if targetFields[len(targetFields)-2] != "snapshots" {
+			continue
+		}
+
+		targetFields[len(targetFields)-2] = "containers-snapshots"
+		newTargetName := strings.Join(targetFields, "/")
+
+		err = os.Remove(shared.VarPath("snapshots", linkName))
+		if err != nil {
+			return err
+		}
+
+		err = os.Symlink(newTargetName, shared.VarPath("snapshots", linkName))
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
+
 // Patches end here
 
 // Here are a couple of legacy patches that were originally in


More information about the lxc-devel mailing list