From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6864480010557718528 X-Received: by 2002:a17:902:b602:: with SMTP id b2mr3319844pls.280.1599073033770; Wed, 02 Sep 2020 11:57:13 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a17:90a:73c9:: with SMTP id n9ls146697pjk.1.experimental-gmail; Wed, 02 Sep 2020 11:57:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvF37KPG7Z5zo8jzhvQpli7wvmnfi6dmggs/lypclSx90L6CKD5KLZFtzR5H0N5DSqizbr X-Received: by 2002:a17:902:7689:b029:cf:85aa:69f4 with SMTP id m9-20020a1709027689b02900cf85aa69f4mr4771581pll.1.1599073032987; Wed, 02 Sep 2020 11:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599073032; cv=none; d=google.com; s=arc-20160816; b=JAcdFrcHDjo+1mrx2rdwHmVPtsq3v9PKDuPNqmIwEWcGf0EAnMq8wxr3Qo59BO8MVq IRCEZTGD+VyCHN9ISjAjt8pBZASTDhCEyeWVERbDCkrqHEpCBg/wFS6+ZiqL8vUrUn4Q kRwmNYfqAKSju8V4SJDqCH9MR8OMxXFAOmO8Z8FnawbKoJUnGQ9I6LsgnuU4ylVVm7pn yZF6BXtM+dBDgEjIiNQO/ymplmWiJfeB5Bmn/s3Yk0UEyIvEzrkHcRjwnPCMy/FtzeRT bgBS2doS/S5bIgT1K8h9dpSwm831zu3zO/qUw8540EgQrBfzeI1ozdZyNB/Fayv+bT1C Vlqw== 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=zWJUxF6CZxU+0M0u0o81afBunohqXSowFXsr/m8uO9l3YsHtScdnW9t5j1Z0mcjvBv AAz2hLv7R4hyTHsBBsgboLaZaxu/KgHsBmt0lmGG42CUj7e6Ucpm2C1ieWovHgvTKYA+ zp5uAXCjOW7hIYRjkca2GGfm13VK7eBYj7jauorgUnQvtymE+3cujGlT9TCTrPXhcc7B omQ8CviuGDazU5iGBxAJwJCktEfDxrJ+L5S58VT0xFbkQ8YkanPebUJHjX8tTsMtWcq1 38UzAdTDFc2Y7ojqghmezJb9zt4gexNgWl8F4ay6ZxFsZFt/JCz66/Eem62wilkcKyhn xsZA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of vijaikumar_kanagarajan@mentor.com designates 68.232.129.153 as permitted sender) smtp.mailfrom=Vijaikumar_Kanagarajan@mentor.com Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com. [68.232.129.153]) by gmr-mx.google.com with ESMTPS id a199si43434pfd.1.2020.09.02.11.57.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2020 11:57:12 -0700 (PDT) Received-SPF: pass (google.com: domain of vijaikumar_kanagarajan@mentor.com designates 68.232.129.153 as permitted sender) client-ip=68.232.129.153; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of vijaikumar_kanagarajan@mentor.com designates 68.232.129.153 as permitted sender) smtp.mailfrom=Vijaikumar_Kanagarajan@mentor.com IronPort-SDR: /Z7ndzDMf3CO/hoEpgfXhU5NA/uQbZcbMhugy4hndRdxFCQ6FvsHO96uvvDj9KioFvI03XMD1Z /6f6uXwDCkcuKhEt796r0xZYml+Ik4KmMotSRv0RAWBQKX6/SrecA0+XGRdpOvWlWjYCh1Nhxs oOuMOx5MshzZSf7F7x9SNWuzlhr3OEE8eIa1rqyJCrHOs88XRXIhoOBDscnWhTPvnkH8y/BI8y U+7jMgt2jZJvBtMuJFfi2J1QpTB4IxVT+9kZAajPEOUofegqAg6L57bVMFX+2UIc4ZLvLRZtAk +Kc= X-IronPort-AV: E=Sophos;i="5.76,383,1592899200"; d="scan'208";a="54698486" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 02 Sep 2020 10:57:12 -0800 IronPort-SDR: i0PZNpSXHXXW3qvHi40ZLsbLbBQYBieV2151Nrl/SYFnNuVO2HjIccpQxMs0XkOBvVWg+UcGXL fQ7bc4BpSt3EI8JAMrRspPL30bR3GzM3QovIs9MDsWsKA42YFvrYjqVNxnFYcTGMdmIpL4CTgg Ec7sf70ebFl/P0gkyroKO/fyR/0RaevX5+958NbAA3JwD056q6Sa5UHDQvSFX88h01Qnzky/a1 yW9pMvtFxPwlECHZ0I7KiTD4GFU3zX+fF47fsiHZXtE6YelnYdjxHoAW/y9J1v/PO3I990EHJW bkw= From: Vijai Kumar K To: , Subject: [PATCH v2 05/10] lib/oe/path: try hardlinking instead of guessing when it might fail Date: Thu, 3 Sep 2020 00:26:19 +0530 Message-ID: <20200902185624.15044-6-Vijaikumar_Kanagarajan@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200902185624.15044-1-Vijaikumar_Kanagarajan@mentor.com> References: <20200902185624.15044-1-Vijaikumar_Kanagarajan@mentor.com> MIME-Version: 1.0 Content-Type: text/plain Return-Path: Vijaikumar_Kanagarajan@mentor.com X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) X-TUID: lCNpPvfv+egB 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