[oe-commits] [bitbake] branch master updated: bb/utils.py: add break_hardlinks helper
git at git.openembedded.org
git at git.openembedded.org
Thu Aug 16 08:53:12 UTC 2018
This is an automated email from the git hooks/post-receive script.
rpurdie pushed a commit to branch master
in repository bitbake.
The following commit(s) were added to refs/heads/master by this push:
new 7ae93cf bb/utils.py: add break_hardlinks helper
7ae93cf is described below
commit 7ae93cf40ab91965147055100432961436bce46c
Author: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
AuthorDate: Tue Jul 10 14:03:34 2018 +0200
bb/utils.py: add break_hardlinks helper
bb.utils.copyfile is called in a few places with identical src and dst
in order to create an st_nlinks==1 version of the file. That that even
works relies on an implementation detail of copyfile (namely, that it
creates a temporary file and then does a rename). Moreover, it's a waste
of time if the file already has st_nlinks==1.
So create a helper that optimizes away the copy in the st_nlinks==1
case. Of course, this helper relies on the same implementation detail,
but that's now contained within bb.utils itself.
To test that we do at least sometimes hit the no-copy path, I tested
locally with
if sstat[stat.ST_NLINK] == 1:
+ bb.note("Woohoo, 2*%d bytes I/O avoided" % sstat[stat.ST_SIZE])
return True
(and the obvious places in oe-core patched), and the do_package log files
are indeed filled with woohoo notes.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
lib/bb/utils.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index b20cdab..56894f1 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -906,6 +906,23 @@ def copyfile(src, dest, newmtime = None, sstat = None):
newmtime = sstat[stat.ST_MTIME]
return newmtime
+def break_hardlinks(src, sstat = None):
+ """
+ Ensures src is the only hardlink to this file. Other hardlinks,
+ if any, are not affected (other than in their st_nlink value, of
+ course). Returns true on success and false on failure.
+
+ """
+ try:
+ if not sstat:
+ sstat = os.lstat(src)
+ except Exception as e:
+ logger.warning("break_hardlinks: stat of %s failed (%s)" % (src, e))
+ return False
+ if sstat[stat.ST_NLINK] == 1:
+ return True
+ return copyfile(src, src, sstat=sstat)
+
def which(path, item, direction = 0, history = False, executable=False):
"""
Locate `item` in the list of paths `path` (colon separated string like $PATH).
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Openembedded-commits
mailing list