diff mbox

btrfs-progs: receive: handle root subvol path in clone

Message ID 20160614232615.20467-1-benedikt.morbach@googlemail.com (mailing list archive)
State Superseded
Headers show

Commit Message

Benedikt Morbach June 14, 2016, 11:26 p.m. UTC
otherwise we get

    ERROR: cannot open <subvol_path>: No such file or directory

because <full_root_path>/<subvol_path> doesn't exist, so openat() will fail below.

Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com>
---


resend with 'btrfs-progs:' in the subject.
Sorry for the noise

cheers

 cmds-receive.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox

Patch

diff --git a/cmds-receive.c b/cmds-receive.c
index f4a3a4f..a975fdd 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -753,6 +753,17 @@  static int process_clone(const char *path, u64 offset, u64 len,
 		subvol_path = strdup(si->path);
 	}
 
+	/* strip the subvolume that we are receiving to from the start of subvol_path */
+	if (r->full_root_path &&
+		strstr(subvol_path, r->full_root_path) == subvol_path) {
+		size_t root_len = strlen(r->full_root_path);
+		size_t sub_len = strlen(subvol_path);
+
+		memmove(subvol_path,
+			subvol_path + root_len + 1,
+			sub_len - root_len);
+	}
+
 	ret = path_cat_out(full_clone_path, subvol_path, clone_path);
 	if (ret < 0) {
 		error("clone: target path invalid: %s", clone_path);