diff options
author | Rasmus Villemoes <rasmus.villemoes@prevas.dk> | 2018-07-10 14:03:34 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-08-16 09:50:42 +0100 |
commit | d4011ce0a37083b19de1769d7f18aa42d7b98137 (patch) | |
tree | 16f444fc8f973faf039ae0ff30d060a0dff2a421 /bitbake/lib | |
parent | 762e6b7b454164a20b11cdf7a1d8c89e94b18e6b (diff) | |
download | poky-d4011ce0a37083b19de1769d7f18aa42d7b98137.tar.gz |
bitbake: 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.
(Bitbake rev: 7ae93cf40ab91965147055100432961436bce46c)
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index b20cdabcf0..56894f130f 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -906,6 +906,23 @@ def copyfile(src, dest, newmtime = None, sstat = None): | |||
906 | newmtime = sstat[stat.ST_MTIME] | 906 | newmtime = sstat[stat.ST_MTIME] |
907 | return newmtime | 907 | return newmtime |
908 | 908 | ||
909 | def break_hardlinks(src, sstat = None): | ||
910 | """ | ||
911 | Ensures src is the only hardlink to this file. Other hardlinks, | ||
912 | if any, are not affected (other than in their st_nlink value, of | ||
913 | course). Returns true on success and false on failure. | ||
914 | |||
915 | """ | ||
916 | try: | ||
917 | if not sstat: | ||
918 | sstat = os.lstat(src) | ||
919 | except Exception as e: | ||
920 | logger.warning("break_hardlinks: stat of %s failed (%s)" % (src, e)) | ||
921 | return False | ||
922 | if sstat[stat.ST_NLINK] == 1: | ||
923 | return True | ||
924 | return copyfile(src, src, sstat=sstat) | ||
925 | |||
909 | def which(path, item, direction = 0, history = False, executable=False): | 926 | def which(path, item, direction = 0, history = False, executable=False): |
910 | """ | 927 | """ |
911 | Locate `item` in the list of paths `path` (colon separated string like $PATH). | 928 | Locate `item` in the list of paths `path` (colon separated string like $PATH). |