From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6864480010557718528 X-Received: by 2002:a17:906:1542:: with SMTP id c2mr23009830ejd.533.1599495640146; Mon, 07 Sep 2020 09:20:40 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a50:bc05:: with SMTP id j5ls233246edh.0.gmail; Mon, 07 Sep 2020 09:20:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdMHMpgVezYzDNqWAZTbrl4ybo83CyuV0cU6cIjmGEgRESbScUgmxkU19HSAK2QSdvMgHU X-Received: by 2002:aa7:c70a:: with SMTP id i10mr22865029edq.218.1599495639027; Mon, 07 Sep 2020 09:20:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599495639; cv=none; d=google.com; s=arc-20160816; b=ufr07Q2p9YWVHQWg5NsH2yBwxX/9Lo+pVaNidmuJFUt/4gzWNS7H14h1it+Rm0+8ND 5etrWm3dgKyC5k8dI6CNDTjS4dFP3AE6AH24hxgS25V4Wv51YF78u+XJU1kWrYq2x0aG 4wLgtOlQLLdjU/qteytWEoQv1OdLsSfPWxKpE1VIWou73Y/XJYeadqO4aIhJEJ1DWcIJ fkSrY5KXHwXr/ADhQdeQknbOPUFxThtvV365liI+NesgJxayIk3dsVQKRSbRqfKXXctV mneacR1qwilXsVgGztj/18AvvvTKlpkGRzNYZ5FAQ/Dp/O91ad7DFRXXTPkRo+hHjQvb IrUg== 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=DHtH720mMp7SV0++xcnRIFPC6CMD0VTkY8lKZVCmbWDNLOur9wQOPgqUI9uA4PEGjY LQ0aOycpyBC1zy2mhMOpn8M+LG8rVKbGh868zFLPNxaQeWG/4OMXCA6VW6ksntIx93T+ Y6dOM59iWmMDk16wbjbu0rfsan2QJvEXuwtEfnCUxqIblnM38G0ju2+0EhNlMZqyTIXy tKGbSrNupolGj8B3CyFt4Dl26kQ+ac16hANcSumRgan32JPz9opnB9671i8Yp8ED9J1A 6FS//CPBCuPEViR4jmsMLn2wft2/8PyVyCZAjbcY1kuE8hia0Gl1hsQeHcyVVbtLFNK/ aqaA== 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.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Sep 2020 09:20:39 -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: HQxldEcWFrMXBBP4smlSOznEF5Gxtxbl/JRwcQpOHLxl4Or/Lbf9QzpeXw7arxfbqANF9Wcm4v E/KqmouLuaFLblII6Q5TSWsZ5zQzrmxdoZF65D+qA8x+EfT/7m+MGuGdn4mW+d+aDzjyYu1ix7 Y/QWXwSzm3WJjGzlm8Nw9L6deLxnA60qJhRPJtcgYZUzaGYXCpUG/6Ui51K0PvNcRC1xjeN16r tQBthMMjzoF12rvzkr2Zx4Qu2FznPy7wdBYqD8mMWOy9WNxUsIQZtjqT7BG21yHD0xXHpQCJ7d WHM= X-IronPort-AV: E=Sophos;i="5.76,402,1592899200"; d="scan'208";a="52770193" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 07 Sep 2020 08:20:37 -0800 IronPort-SDR: vGOILfRnRHHo7bbGI38jOE+5ywsjuUMwlDy6hM+PV+DwLhDpYm6rIQ6RL6aziyCj5FsRKW05M2 tAxmejZwJL7sKEIK8f0dCglJQiSQZI6V7YXUqAszksjMXY6BAYV0FXuW9WvrD9Le5ub4CKdJIo LlJbFZNJuUPIDWE1BDvAqbsmcfgLhhvgaNDOryqOTOZLX+ipHtJMJbNKUK/MkUNQFNHXXJWgav Zv7tdBxGx7fAVG3UIpWXfW6Lp+eEER0Q4oPmOpw86RX7R9zqOUJ8KNoekWmAP29P7ZvtAQp421 Qzg= From: Vijai Kumar K To: , Subject: [PATCH v3 4/9] oe.path: Add copyhardlink() helper function Date: Mon, 7 Sep 2020 21:50:13 +0530 Message-ID: <20200907162018.16636-1-Vijaikumar_Kanagarajan@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200907161756.16372-4-Vijaikumar_Kanagarajan@mentor.com> References: <20200907161756.16372-4-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: ahQemC6tjeMP 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