From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6812695221159067648 X-Received: by 2002:a1c:7212:: with SMTP id n18mr808617wmc.53.1586204217819; Mon, 06 Apr 2020 13:16:57 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:adf:cd81:: with SMTP id q1ls701566wrj.1.gmail; Mon, 06 Apr 2020 13:16:57 -0700 (PDT) X-Google-Smtp-Source: APiQypKdBiP4525cHOTEiiEoOHHx2V26PlqA7+6DCpLKuxjhaSn8ofhT9L45MfiO7+E6UPIqw4Kb X-Received: by 2002:a5d:6441:: with SMTP id d1mr1067792wrw.301.1586204217242; Mon, 06 Apr 2020 13:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586204217; cv=none; d=google.com; s=arc-20160816; b=V1K/rhUYMsq+heyCdM4rvVzmgEFtIxjrcxfM5wfxc3hkxAgGAqsKm0c1RzZOt47nyT 98lk9J1f3oI3CtTNT90A4bbuohpn7I8kfR+beUGR+6IEkz5/lWye788o4bF0dw+FPSkJ wlreKVMGh7U8MxCAdOL4kEq2LLcgHBvvXaPChCWQMoPtZkzfFRZ79wh7/vQnUnzbUSaX ukYdLF5facpA6zxYHxjB50CSibJkoWzhpxRxuJnA3f+BOTPFCjZTmS3BFHY/UtI+HyvR QG5qycInyDmoybmZrsSdeLKXcUXERFUgx354gE5rFbEcr7dpF6QU/TAC4KtIDnh96DYa dKyg== 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=SPRolsw5C/Hh/kTGYzPJga2jCEs7tH6TBbACXmMYrLI=; b=u1DAonL+FlTW2PcxN0DyyzYbxj2eeylrIUKK/AVtK5fnYjsBPgY3NPNtw+xQK17XKo TP93hbvmJbU0DqTjJTv+rrSLTJvnL1CTJLJaMSqwraPt48J+WKKUDNFmGt4nWKodimUo wS/AJooxNr1zSWa6gZHhp8Yez9xHyJQYchPhfsnQE9g06p8oaKuqoO+FpkU200ejJOge 4pnudlHk+5cprp3PR3avjeZWXMCgashQSFZcmUWkUxqHxLo3gj6SBCclSzJi9oSFwv8P vNb/9iPiUzZJeahhuS8bNd+VLn26SNBt6o2J/SkIgtIEO2+RKswYBs9xCWuYMVJZ4XAH vc+g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 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 david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id z84si38427wmc.2.2020.04.06.13.16.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2020 13:16:57 -0700 (PDT) Received-SPF: pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 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 david.siemens.de (8.15.2/8.15.2) with ESMTPS id 036KGqiB003460 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Apr 2020 22:16:52 +0200 Received: from localhost.localdomain ([139.22.32.4]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id 036KGpoV013720; Mon, 6 Apr 2020 22:16:52 +0200 From: Henning Schild To: isar-users@googlegroups.com Cc: Paul Barker , Ross Burton , Richard Purdie Subject: [PATCH 1/3] oe.path: Add copyhardlink() helper function Date: Mon, 6 Apr 2020 22:16:46 +0200 Message-Id: <20200406201648.26945-2-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: vr04jyeZx2Kr 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 --- 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 90c87f5239..c6bb6042a3 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.24.1