From patchwork Tue Jun 14 22:55:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benedikt Morbach X-Patchwork-Id: 9177155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 278D6604DB for ; Tue, 14 Jun 2016 22:55:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15FA028307 for ; Tue, 14 Jun 2016 22:55:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06BFF2833B; Tue, 14 Jun 2016 22:55:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AA2B28307 for ; Tue, 14 Jun 2016 22:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932111AbcFNWzs (ORCPT ); Tue, 14 Jun 2016 18:55:48 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36625 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751635AbcFNWzr (ORCPT ); Tue, 14 Jun 2016 18:55:47 -0400 Received: by mail-wm0-f68.google.com with SMTP id m124so1787648wme.3 for ; Tue, 14 Jun 2016 15:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=XgNX0pfoGJUX6gFReozuHCCEkkl5Pf/1sPdCi8wL9yQ=; b=vc5HhG/DDRpeTtWW6XoJVom9LgQL2QEIDEwnxpwZbmEuXrzOPgdkti4Xtw/BU8tySS JQd2DYLWtXDmypaHm3t7/FaLL06A9WQzXq8295pXs4FCDpdOWmNOJ4eBv2gO65qs6cVr GPrp4KunehsJXVuJtdeQNvN9Jh5jaL/JIBBjPxhzhzw9LB69EQagvqf7FH52K0/x58zB ujNGuYCHCwS213w4o7RYwotO07SeBvzajcCEw346FNQd12Z5TtI7cYB2xmAX7LtbSZSf V2WspeWcm5R6lk7Nu8bex+xRD+RqskUwzJ26i+n1at2AGXINs/Uz+AvfmlFzxeCgXS/f t6ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=XgNX0pfoGJUX6gFReozuHCCEkkl5Pf/1sPdCi8wL9yQ=; b=Xr3L+Ilk4cO78b0rujbvZox37MmyR9ibq7/9rJHnElFpfO577Ot/+SB4RCUBSE821/ L45IVu3Gp9nPwUZqJpDR1WNov3QuXK14WpLEEIYVLUT/ptHUFPr5w/JIxBf6ayqoXvMv hSGl9ScRLcLfvilYobquRg2B+DdyF7Zmk77LL00sp3bT9vgVy29h0FqqFKe2maBuvHXp wpMnGvfH6hw+jPhkGWf99r0SeehQDCk+61wzTCHHNerr1Jo1ZkAegmyWSjEPulCcRyQI muRiFCECXEfDI03dK5dtI6rTcCne+FoHNQjjrY0EBaRxl9p20sipwgSqkaftrTjShAl/ fe3A== X-Gm-Message-State: ALyK8tK2q+8bJy/fLxkRQqg2SA6rMcBZ2STlm4eRjNAGc3gaTbg68zMcFYZtQL487q0NnQ== X-Received: by 10.28.173.66 with SMTP id w63mr8877329wme.14.1465944945905; Tue, 14 Jun 2016 15:55:45 -0700 (PDT) Received: from detritus.atuin (p4FDCC87F.dip0.t-ipconnect.de. [79.220.200.127]) by smtp.gmail.com with ESMTPSA id q63sm2435228wma.0.2016.06.14.15.55.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Jun 2016 15:55:45 -0700 (PDT) From: Benedikt Morbach To: linux-btrfs@vger.kernel.org Cc: Benedikt Morbach Subject: [PATCH] receive: strip root subvol path during process_clone Date: Wed, 15 Jun 2016 00:55:41 +0200 Message-Id: <20160614225541.18140-1-benedikt.morbach@googlemail.com> X-Mailer: git-send-email 2.8.4 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP otherwise we get ERROR: cannot open : No such file or directory because / doesn't exist, so openat() will fail below. Signed-off-by: Benedikt Morbach --- cmds-receive.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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);