From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6812695221159067648 X-Received: by 2002:a05:651c:28a:: with SMTP id b10mr617704ljo.223.1586204215636; Mon, 06 Apr 2020 13:16:55 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:ac2:5456:: with SMTP id d22ls526940lfn.6.gmail; Mon, 06 Apr 2020 13:16:55 -0700 (PDT) X-Google-Smtp-Source: APiQypLg9emb/P3CCAJcg+sJxRMwFNKNZJBVI/BFg0YgF76stmGTWUi5jzO+keYaxAxYn22nmYtG X-Received: by 2002:ac2:5f52:: with SMTP id 18mr14282336lfz.133.1586204214975; Mon, 06 Apr 2020 13:16:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586204214; cv=none; d=google.com; s=arc-20160816; b=qWcpwCaPNlpAdRatnqh0i38m2InKExFqKQQBG58w/pU2q3/EX2bNyJmhjx9NeahQrl E11E4vboKrtvP/Nn2Z6gCgrNZT7zQQ5lhtNZnSUnuULcIgM196XZSqaxO3iPQl2h3C6Y vHzfWpCpftqZ1MBMYfwwK9KUFCyexCWr6f3YsLy2AJavgMnBuX1TTFXq9gXJbRyKCj1i 0r567DeUDB2BDzdeAMtrDjtLCUIEyvrlsJy/l2F8BryJPukwCgDSq7VIRjd+GPgUkFty GY5SfuuFUSlGHjfOZ0mU2ejHcspKBrjOpO5/J73NecPFuuQciFGaNI/upbUHI50Bz4gd XGug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=FJ9Nm1nJOVWiqNx5YNJKqqSOnAB/Xd8c1wjG6jxfJro=; b=wAVZHEytb5XTYdkr8Dtj0eeN5U/DYJ+WYOklKq4UU4qFXLgzExmBnIpBB+KriogUEu FYnwhFfschnlsGM45zjZNpPz8HkdaHY3em/U4zrvgMK1HBTjAa+f1ex8t6AZq2l6YAW8 YyIrhNW/JbYFdn1l8XN/JYPls7Vo9sR0sDEYCRE2C0DSJ+/UBjx1JkZtEpIvQGjgt5cG t37Obac2NNrzs1pVPMjRlV0GPPpXJ92TpD4I5L6VersD4PIFfQJFQgYwwkU/WUFZcDL3 j+si6L88kp7snNZZBPBw/EJL6zEFjB2DwKpHolDzu+3W0DmsLL436FcaZlO7W3mRgBy7 QhVA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=henning.schild@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from gecko.sbs.de (gecko.sbs.de. [194.138.37.40]) by gmr-mx.google.com with ESMTPS id f17si50315lfp.0.2020.04.06.13.16.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2020 13:16:53 -0700 (PDT) Received-SPF: pass (google.com: domain of henning.schild@siemens.com designates 194.138.37.40 as permitted sender) client-ip=194.138.37.40; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=henning.schild@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by gecko.sbs.de (8.15.2/8.15.2) with ESMTPS id 036KGrCB001576 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Apr 2020 22:16:53 +0200 Received: from localhost.localdomain ([139.22.32.4]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id 036KGpoW013720; Mon, 6 Apr 2020 22:16:52 +0200 From: Henning Schild To: isar-users@googlegroups.com Cc: Henning Schild , Richard Purdie Subject: [PATCH 2/3] lib/oe/path: try hardlinking instead of guessing when it might fail Date: Mon, 6 Apr 2020 22:16:47 +0200 Message-Id: <20200406201648.26945-3-henning.schild@siemens.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200406201648.26945-1-henning.schild@siemens.com> References: <20200406201648.26945-1-henning.schild@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: DzbCHkNGJQ6G From: Henning Schild The comparison of the stat st_dev is not enough to judge whether hardlinking will work. One example would be where you try and hardlink across two bind-mounts of a directory. The st_dev will be the same and the operation will still fail. Instead of implementing a check to try and figure out hardlink support just try hardlinking and fall back to a copy when running into an exception. Signed-off-by: Henning Schild Signed-off-by: Richard Purdie --- meta/lib/oe/path.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py index c6bb6042a3..3506e2c989 100644 --- a/meta/lib/oe/path.py +++ b/meta/lib/oe/path.py @@ -99,7 +99,22 @@ def copyhardlinktree(src, dst): if os.path.isdir(src) and not len(os.listdir(src)): return - if (os.stat(src).st_dev == os.stat(dst).st_dev): + canhard = False + testfile = None + for root, dirs, files in os.walk(src): + if len(files): + testfile = os.path.join(root, files[0]) + break + + if testfile is not None: + try: + os.link(testfile, os.path.join(dst, 'testfile')) + os.unlink(os.path.join(dst, 'testfile')) + canhard = True + except Exception as e: + bb.debug(2, "Hardlink test failed with " + str(e)) + + if (canhard): # Need to copy directories only with tar first since cp will error if two # writers try and create a directory at the same time cmd = "cd %s; find . -type d -print | tar --xattrs --xattrs-include='*' -cf - -S -C %s -p --no-recursion --files-from - | tar --xattrs --xattrs-include='*' -xhf - -C %s" % (src, src, dst) @@ -121,12 +136,9 @@ def copyhardlinktree(src, dst): def copyhardlink(src, dst): """Make a hard link when possible, otherwise copy.""" - # We need to stat the destination directory as the destination file probably - # doesn't exist yet. - dstdir = os.path.dirname(dst) - if os.stat(src).st_dev == os.stat(dstdir).st_dev: + try: os.link(src, dst) - else: + except OSError: shutil.copy(src, dst) def remove(path, recurse=True): -- 2.24.1