[OE-core] [PATCH] license.bbclass: try copyfile() as fallback when link() fails
Enrico Scholz
enrico.scholz at sigma-chemnitz.de
Thu Sep 10 16:50:16 UTC 2015
link() will fail with EXDEV when source and destination are on different mountpoints.
Unfortunately, stat().st_dev does not identify the mountpoint so that copy_license_files()
fails in bind-mount environments.
E.g.:
| # mkdir /tmp/a /tmp/b /tmp/X /tmp/X/a /tmp/X/b
| # touch /tmp/a/foo
| # mount --bind /tmp/a /tmp/X/a
| # mount --bind /tmp/b /tmp/X/b
|
| # python -c 'import os;
| print(os.stat("/tmp/X/a")).st_dev;
| print(os.stat("/tmp/X/b")).st_dev;
| os.link("/tmp/X/a/foo", "/tmp/X/b/foo")'
| 62
| 62
| Traceback (most recent call last):
| File "<string>", line 1, in <module>
| OSError: [Errno 18] Invalid cross-device link
Patch catches errno EXDEV and tries a plain copy then.
Signed-off-by: Enrico Scholz <enrico.scholz at sigma-chemnitz.de>
---
meta/classes/license.bbclass | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index 224d541..ba36c12 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -175,6 +175,7 @@ def add_package_and_files(d):
def copy_license_files(lic_files_paths, destdir):
import shutil
+ import errno
bb.utils.mkdirhier(destdir)
for (basename, path) in lic_files_paths:
@@ -183,8 +184,14 @@ def copy_license_files(lic_files_paths, destdir):
dst = os.path.join(destdir, basename)
if os.path.exists(dst):
os.remove(dst)
- if os.access(src, os.W_OK) and (os.stat(src).st_dev == os.stat(destdir).st_dev):
- os.link(src, dst)
+ if os.access(src, os.W_OK):
+ try:
+ os.link(src, dst)
+ except OSError as e:
+ if e.errno != errno.EXDEV:
+ raise e
+
+ shutil.copyfile(src, dst)
else:
shutil.copyfile(src, dst)
except Exception as e:
--
2.4.3
More information about the Openembedded-core
mailing list