Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: openembedded-core <openembedded-core@lists.openembedded.org>
Subject: [PATCH] utils: Add hardlinkdir shell function
Date: Thu, 24 Apr 2014 10:17:18 +0100	[thread overview]
Message-ID: <1398331038.16672.171.camel@ted> (raw)

In a number of places it would be helpful to be able to copy trees of
files using hardlinks. This turns out to be harder than you'd expect
since there is no good single command that does this well and handles
all file types correctly.

Abstracting this into a function therefore makes sense, cpio seems
as good an option as any other. We do require two passes due to the
way cpio handles symbolic links.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
index 0a533af..91895ec 100644
--- a/meta/classes/utils.bbclass
+++ b/meta/classes/utils.bbclass
@@ -292,6 +292,17 @@ END
 	chmod +x $cmd
 }
 
+# Copy files/directories from $1 to $2 but using hardlinks
+# Have to do this in two passes to handle symbolic links correctly due to
+# the way cpio handles this combination of options.
+hardlinkdir () {
+	from=$1
+	to=$2
+	(cd $from; find . -print0 | cpio --null -pdlu $to)
+	(cd $from; find . -type l -print0 | cpio -pd0mLu --no-preserve-owner $to)
+}
+
+
 def check_app_exists(app, d):
     app = d.expand(app)
     path = d.getVar('PATH', d, True)




                 reply	other threads:[~2014-04-24  9:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398331038.16672.171.camel@ted \
    --to=richard.purdie@linuxfoundation.org \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox