From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6864480010557718528 X-Received: by 2002:a50:e0cf:: with SMTP id j15mr23137030edl.285.1599495642113; Mon, 07 Sep 2020 09:20:42 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:aa7:c545:: with SMTP id s5ls233984edr.3.gmail; Mon, 07 Sep 2020 09:20:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznzr69y9NGk5TEcq3ViT22XwQLSA6s9ZAeTdLerUjLmoHXgKR3iZMmwnZMiwJSxCHB8N0/ X-Received: by 2002:aa7:d40f:: with SMTP id z15mr23003966edq.247.1599495641131; Mon, 07 Sep 2020 09:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599495641; cv=none; d=google.com; s=arc-20160816; b=akrhoFFAxQhga/bACoHewseKVOe+N//qyDdMXS7ADunrXcodEWsxIjMbMpR2jedZng EVKkgP2BtUpNJ3mYvNlVlj5KA3McO7yHTrQe8MMlG2KND9KctEnJzmqJCJiWJ27GwdbO zFGiu4iILTD611orMWxvp8jD12zjs4VZyOyI4qDWo6SM6SOw7VDxtKX9FXkGvfJYwLng piVITik8NTYkffwTCFZa1fqAzW2IbsWN60Av5ePRM0QuTmT4M9fN/VQizC++EnioYDeo Wj7E7GLRG/BZHJCxsZM/tJFuvYtKEWZrLdbxBmnPhutEhdp9LxbgYb40CJ8FdTEh51V7 5ZhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject:to:from :ironport-sdr:ironport-sdr; bh=3hESc+kJKtwqKrBuuST3QyiQQb+6pEbodWyFniokofA=; b=Ixo5lmBDQYaRVvdXGyFVNkCJRIgGg+a5FpBzonK/HfKsU9s+ndMeLKg9PwSUkME9FK Io43A1jn1idJj+bnI/CNfrdTNZLp2U//45y7TLYajuHCEVi5EswL148H9pXWFI8mLZLq FIr1ubsQ2WmWvaJY5+jZbh3HYXNBxD61bYGe67KHSOfDw2Oq4K/40MbiFN3J/mIxCBFZ QwXxIf0puEqog0W8nJ4jJuSiLkC0YiKAatpiU3V5NjeEgQIWkbSK4aT7WOJDc1n0PuKa 2T+8q4zn8mV5HhOgibq3eSRNHu/e2LSanritwe8yT2sljDwj4w75SvCdiI2giwHiED/0 Wlfg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of vijaikumar_kanagarajan@mentor.com designates 68.232.137.252 as permitted sender) smtp.mailfrom=Vijaikumar_Kanagarajan@mentor.com Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com. [68.232.137.252]) by gmr-mx.google.com with ESMTPS id w16si466474edq.4.2020.09.07.09.20.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Sep 2020 09:20:41 -0700 (PDT) Received-SPF: pass (google.com: domain of vijaikumar_kanagarajan@mentor.com designates 68.232.137.252 as permitted sender) client-ip=68.232.137.252; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of vijaikumar_kanagarajan@mentor.com designates 68.232.137.252 as permitted sender) smtp.mailfrom=Vijaikumar_Kanagarajan@mentor.com IronPort-SDR: 9UZDv6AjVkeXLYKpYKp7A2i2So49N8XMf9JDEPILRr9Na+Q/MpPDcDhyhWfWbATFGWHQ0dZAM/ m6+29DJIIPWmu1GBb4HWVJmrJaoaTomRPzySW+ky51NVdK6rwqFA/yz0JKUPXPF74f1pHe2vsO 92yT2yXFEbJuqGWkLuMUG4WWPvxUrenXg9vFHErxA1mDX6xJdxATIHClnO5UuSXFcPq3wU41Xy Gyb646sf1Tzxps2qGg0fH9pjOQGzjtdjqwOVoZ7aEMxlgd+aeXNX//Uf05AHCYpwXL47pnTHTy /GY= X-IronPort-AV: E=Sophos;i="5.76,402,1592899200"; d="scan'208";a="52770194" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 07 Sep 2020 08:20:40 -0800 IronPort-SDR: sjsLotMhpUxhKVIs/Na7Fu5g8Xwn8fe0mhhPMONKix8pz+3tXU51+fPalqn8YMIFcc1s007k2Y RXFtFGnzQ1Ksd7esqUlkSSt8yHGww2Xi6yIvVaxw99gciOaf6B4ab76GDl9/VmLoD33Mo73kSi Zr9gUcT5cic7DGWHOR8tWsMe0TXphSjNQtd2V1oKiYhLj1gZ+WvpsU32AfITkKqfIqs+EjYT8S gKxy2X9PrizCtindW3CZoFb5Cl7ImP98SO+QcPsGa58CSX4y0lyxsvbrwfALHe+t1JE6dRS/7m 1OY= From: Vijai Kumar K To: , Subject: [PATCH v3 5/9] lib/oe/path: try hardlinking instead of guessing when it might fail Date: Mon, 7 Sep 2020 21:50:14 +0530 Message-ID: <20200907162018.16636-2-Vijaikumar_Kanagarajan@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200907162018.16636-1-Vijaikumar_Kanagarajan@mentor.com> References: <20200907161756.16372-4-Vijaikumar_Kanagarajan@mentor.com> <20200907162018.16636-1-Vijaikumar_Kanagarajan@mentor.com> MIME-Version: 1.0 Content-Type: text/plain Return-Path: Vijaikumar_Kanagarajan@mentor.com X-ClientProxiedBy: SVR-ORW-MBX-09.mgc.mentorg.com (147.34.90.209) To svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) X-TUID: Ec9BNOzBNbEt 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 [Vijai: Imported from OE core f5571bda8327f927feb23b167ab4594b7d0c95bc] Signed-off-by: Vijai Kumar K --- 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 c6bb604..3506e2c 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.17.1