summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorDevendra Tewari <devendra.tewari@gmail.com>2021-04-19 11:23:58 -0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-04-23 10:12:12 +0100
commit8d48138e9b1f3577cfba64b4757b576c27c6ef04 (patch)
tree9c67de3630ffde438b70e92cf6864103233bc149 /meta/lib
parentf2d1523b19cb066a4a06609f036822fe4a8b43f0 (diff)
downloadopenembedded-core-contrib-8d48138e9b1f3577cfba64b4757b576c27c6ef04.tar.gz
classes/lib/scripts: Use shutil.move when os.rename fails
Incremental build in Docker fails with: OSError: [Errno 18] Invalid cross-device link when source and destination are on different overlay filesystems. This change handles error with os.rename and retries with shutil.move. The reason os.rename is still used is because shutil.move is too slow for speed sensitive sections of code. [YOCTO #14301] Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/package_manager/deb/__init__.py18
-rw-r--r--meta/lib/oe/package_manager/ipk/__init__.py5
-rw-r--r--meta/lib/oe/rootfs.py15
-rw-r--r--meta/lib/oeqa/selftest/cases/wic.py16
4 files changed, 44 insertions, 10 deletions
diff --git a/meta/lib/oe/package_manager/deb/__init__.py b/meta/lib/oe/package_manager/deb/__init__.py
index 2ee68fefb1..8edc653dff 100644
--- a/meta/lib/oe/package_manager/deb/__init__.py
+++ b/meta/lib/oe/package_manager/deb/__init__.py
@@ -5,6 +5,7 @@
import re
import subprocess
from oe.package_manager import *
+import shutil
class DpkgIndexer(Indexer):
def _create_configs(self):
@@ -214,7 +215,10 @@ class DpkgPM(OpkgDpkgPM):
tmp_sf.write(status)
- os.rename(status_file + ".tmp", status_file)
+ try:
+ os.rename(status_file + ".tmp", status_file)
+ except OSError:
+ shutil.move(status_file + ".tmp", status_file)
def run_pre_post_installs(self, package_name=None):
"""
@@ -299,13 +303,21 @@ class DpkgPM(OpkgDpkgPM):
for dir in dirs:
new_dir = re.sub(r"\.dpkg-new", "", dir)
if dir != new_dir:
- os.rename(os.path.join(root, dir),
+ try:
+ os.rename(os.path.join(root, dir),
+ os.path.join(root, new_dir))
+ except OSError:
+ shutil.move(os.path.join(root, dir),
os.path.join(root, new_dir))
for file in files:
new_file = re.sub(r"\.dpkg-new", "", file)
if file != new_file:
- os.rename(os.path.join(root, file),
+ try:
+ os.rename(os.path.join(root, file),
+ os.path.join(root, new_file))
+ except OSError:
+ shutil.move(os.path.join(root, file),
os.path.join(root, new_file))
diff --git a/meta/lib/oe/package_manager/ipk/__init__.py b/meta/lib/oe/package_manager/ipk/__init__.py
index da488c1c7f..2aa21949f3 100644
--- a/meta/lib/oe/package_manager/ipk/__init__.py
+++ b/meta/lib/oe/package_manager/ipk/__init__.py
@@ -213,7 +213,10 @@ class OpkgPM(OpkgDpkgPM):
tmp_sf.write(status)
- os.rename(status_file + ".tmp", status_file)
+ try:
+ os.rename(status_file + ".tmp", status_file)
+ except OSError:
+ shutil.move(status_file + ".tmp", status_file)
def _create_custom_config(self):
bb.note("Building from feeds activated!")
diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py
index 5f81023040..ef00010047 100644
--- a/meta/lib/oe/rootfs.py
+++ b/meta/lib/oe/rootfs.py
@@ -114,7 +114,10 @@ class Rootfs(object, metaclass=ABCMeta):
shutil.rmtree(self.image_rootfs + '-orig')
except:
pass
- os.rename(self.image_rootfs, self.image_rootfs + '-orig')
+ try:
+ os.rename(self.image_rootfs, self.image_rootfs + '-orig')
+ except OSError:
+ shutil.move(self.image_rootfs, self.image_rootfs + '-orig')
bb.note(" Creating debug rootfs...")
bb.utils.mkdirhier(self.image_rootfs)
@@ -165,10 +168,16 @@ class Rootfs(object, metaclass=ABCMeta):
shutil.rmtree(self.image_rootfs + '-dbg')
except:
pass
- os.rename(self.image_rootfs, self.image_rootfs + '-dbg')
+ try:
+ os.rename(self.image_rootfs, self.image_rootfs + '-dbg')
+ except OSError:
+ shutil.move(self.image_rootfs, self.image_rootfs + '-dbg')
bb.note(" Restoreing original rootfs...")
- os.rename(self.image_rootfs + '-orig', self.image_rootfs)
+ try:
+ os.rename(self.image_rootfs + '-orig', self.image_rootfs)
+ except OSError:
+ shutil.move(self.image_rootfs + '-orig', self.image_rootfs)
def _exec_shell_cmd(self, cmd):
fakerootcmd = self.d.getVar('FAKEROOT')
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index fa81584a8c..fa93973087 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -1269,6 +1269,7 @@ class Wic2(WicTestCase):
def test_expand_mbr_image(self):
"""Test wic write --expand command for mbr image"""
+ import shutil
# build an image
config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n'
self.append_config(config)
@@ -1306,8 +1307,14 @@ class Wic2(WicTestCase):
result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path))
self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output)
- os.rename(image_path, image_path + '.bak')
- os.rename(new_image_path, image_path)
+ try:
+ os.rename(image_path, image_path + '.bak')
+ except OSError:
+ shutil.move(image_path, image_path + '.bak')
+ try:
+ os.rename(new_image_path, image_path)
+ except OSError:
+ shutil.move(new_image_path, image_path)
# Check if it boots in qemu
with runqemu('core-image-minimal', ssh=False) as qemu:
@@ -1318,7 +1325,10 @@ class Wic2(WicTestCase):
if os.path.exists(new_image_path):
os.unlink(new_image_path)
if os.path.exists(image_path + '.bak'):
- os.rename(image_path + '.bak', image_path)
+ try:
+ os.rename(image_path + '.bak', image_path)
+ except OSError:
+ shutil.move(image_path + '.bak', image_path)
def test_wic_ls_ext(self):
"""Test listing content of the ext partition using 'wic ls'"""