From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6864480010557718528 X-Received: by 2002:a17:90a:4ec4:: with SMTP id v4mr3380453pjl.62.1599073031642; Wed, 02 Sep 2020 11:57:11 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a17:902:720b:: with SMTP id ba11ls1640934plb.0.gmail; Wed, 02 Sep 2020 11:57:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye7gZshB1HzNQGaohcywOx3W2NI8nSxqJY3+wKjwciH+ujGYFdjtS9yCgi9gDG6cR9hpAy X-Received: by 2002:a17:902:fe0b:: with SMTP id g11mr3248360plj.172.1599073030986; Wed, 02 Sep 2020 11:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599073030; cv=none; d=google.com; s=arc-20160816; b=uC3onr2uTsoYiP2rutns9ZN++a1w+DegbnTO4auhumx8BdRNIH2iMtoaXbp1CLV78k daB5dsC94hatSqFiAkZj9Spw9NbiqJsfmhHzyej4B2o0H4eEbjWzkM3z6kNs/07srO0K fAV3IrcbfH3WKortCjM3bnibVhSo6T8XrvzKhObECwpbhTr3ICEiFB+jnMhrsc1A6UwA SiCZYLBByOZqcy9aNfkA+Ii055SQmeYEKT+bzIgOeg3CR0+5/UFRk7xyQxTC6t4Zyg56 +fFryt7qQF63Mw5yVWtdRscnNjUgvUZSMdxvXzen45WZHgQJLpTaWNJvob0SuIPejyyd jBQA== 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=44YMmy8he/Krw5pKz6mdxmyPNemXWdNAzenOwLm4qaM=; b=AzVqOT0ZXUpGlS2QPjqwR5zAmIvI9ymHR/UCQ7ya3NzfAli19JyjlRKy4zzmZ+afWD 1DQK+Jw9ABWC70WcHOcUkiF2Lh/bGYv+lMAPQCgFmBbyM7zUXWSEwaYAViGNWJ7ateNl GJDS98xVcOWTErTN0TPebu/uf4++VagN5wfhE9LG0Tj7Th/LauMOBGBbRTWplqW9F5GK 1yjhrI43uuPgZnBFaqhrwLCR0wsbFu5uWz+Vha0vLlCvRXcAL5i5tBXhzEYNQZr+3NIT H5IIRzN+zhVpN4Y2idYtK4QejCzE3WWqP3NckiIUewBKoYwXQLDmG/SLsJHVeR4+pWN7 lkBA== 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.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2020 11:57:10 -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: 30nirJfAuxUROOc7D5WZ+KAHXYbqKDQpS7zQT0+izkOvVMsepGKVa/tu4V3jkovqqBtV6tZ3z0 8BZAaYq1UAd5y1NaN1x6oIsSO1IhdhMTGZhARsyaYJ7c0aoA1GbmI4PE4gRozbmP3epmBnAXT5 OQHx7cX4FlrobzHkn53Kg68gUoHvU5Dy2jMJdGCIOYsByU3BYRmj2US0VLfxcJPO8DzKEVfm8y SUdTVZoRpsWJPR2OmfnMGBqhQeUyACCbjcb1HckbQPuYHEbDbYHR6aTvPXugh6gOgLcVa9qO5q UEo= X-IronPort-AV: E=Sophos;i="5.76,383,1592899200"; d="scan'208";a="54698484" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 02 Sep 2020 10:57:10 -0800 IronPort-SDR: kAGh/oaaq47mm/pT3H2BrE2REQuUo0ICS973KaVgOkHntGRtsDJpdPZgMNAukBVl+NYrUYNbOB 7ojpKpKCm6S/znr4RJ1x1/sxz4QgiEE0ZW2TP5IOUal2PlfARxRyM1mPDb++0m9vl4Fkx/6d14 Uldk6D8HRwBA3DTPxDedHXIIfHFC6/A8VfCnemquYY+M6f0MlrJ1UDAXO2CVqgfBIL7fn81QPb pQ8cUb18z323SUqaHFXwFuH9Ijy0/+BM77840T8MCh8oRIMTihI3uIteHFN3OOSmGwU0KMd549 GC4= From: Vijai Kumar K To: , Subject: [PATCH v2 04/10] oe.path: Add copyhardlink() helper function Date: Thu, 3 Sep 2020 00:26:18 +0530 Message-ID: <20200902185624.15044-5-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: /lAfjJopdL3F From: Paul Barker This function creates hard links if possible, falling back to copying the file if the destination is on a different volume to the source. The docstring for copyhardlinktree() is also updated to make the difference between the two functions a little clearer. Signed-off-by: Paul Barker Signed-off-by: Ross Burton Signed-off-by: Richard Purdie [Vijai: Imported from OE-core 5437efa16f9bec914e417c6c939a39c247084f52] Signed-off-by: Vijai Kumar K --- meta/lib/oe/path.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py index 90c87f5..c6bb604 100644 --- a/meta/lib/oe/path.py +++ b/meta/lib/oe/path.py @@ -94,7 +94,7 @@ def copytree(src, dst): subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) def copyhardlinktree(src, dst): - """ Make the hard link when possible, otherwise copy. """ + """Make a tree of hard links when possible, otherwise copy.""" bb.utils.mkdirhier(dst) if os.path.isdir(src) and not len(os.listdir(src)): return @@ -118,6 +118,17 @@ def copyhardlinktree(src, dst): else: copytree(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: + os.link(src, dst) + else: + shutil.copy(src, dst) + def remove(path, recurse=True): """ Equivalent to rm -f or rm -rf -- 2.17.1