[poky] [PATCH 2/3] sstate.bbclass: Use hard link when staging files into sysroots
Dongxiao Xu
dongxiao.xu at intel.com
Mon Dec 6 04:36:15 PST 2010
Use hard link instead of copy when staging files from sysroot-destdir
into sysroots directory. This can save about 10% disk space for
poky-image-minimal.
If fail, it will fall back to copy function
Signed-off-by: Dongxiao Xu <dongxiao.xu at intel.com>
---
meta/classes/sstate.bbclass | 2 +-
meta/lib/oe/path.py | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/meta/classes/sstate.bbclass b/meta/classes/sstate.bbclass
index 3696a8c..b6c477b 100644
--- a/meta/classes/sstate.bbclass
+++ b/meta/classes/sstate.bbclass
@@ -115,7 +115,7 @@ def sstate_install(ss, d):
locks.append(bb.utils.lockfile(lock))
for state in ss['dirs']:
- oe.path.copytree(state[1], state[2])
+ oe.path.hardlink(state[1], state[2])
for walkroot, dirs, files in os.walk(state[1]):
for file in files:
srcpath = os.path.join(walkroot, file)
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index f42faea..589b524 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -106,3 +106,31 @@ def symlink(source, destination, force=False):
except OSError, e:
if e.errno != errno.EEXIST or os.readlink(destination) != source:
raise
+
+def hardlink(src, dst):
+ names = os.listdir(src)
+
+ bb.mkdirhier(dst)
+
+ errors = []
+ for name in names:
+ srcname = os.path.join(src, name)
+ dstname = os.path.join(dst, name)
+ try:
+ if os.path.islink(srcname):
+ linkto = os.readlink(srcname)
+ if os.path.lexists(dstname):
+ os.unlink(dstname)
+ os.symlink(linkto, dstname)
+ elif os.path.isdir(srcname):
+ hardlink(srcname, dstname)
+ else:
+ ret = os.system("ln -f %s %s" % (srcname, dstname))
+ if ret is False:
+ bb.utils.copyfile(srcname, dstname)
+ except (IOError, os.error), why:
+ errors.append((srcname, dstname, str(why)))
+ except Error, err:
+ errors.extend(err.args[0])
+ if errors:
+ raise Error, errors
--
1.6.3.3
More information about the poky
mailing list