diff options
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r-- | bitbake/lib/bb/utils.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index b282d09abf..6ba1d2a376 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -782,7 +782,7 @@ def movefile(src, dest, newmtime = None, sstat = None): | |||
782 | 782 | ||
783 | if sstat[stat.ST_DEV] == dstat[stat.ST_DEV]: | 783 | if sstat[stat.ST_DEV] == dstat[stat.ST_DEV]: |
784 | try: | 784 | try: |
785 | os.rename(src, destpath) | 785 | bb.utils.rename(src, destpath) |
786 | renamefailed = 0 | 786 | renamefailed = 0 |
787 | except Exception as e: | 787 | except Exception as e: |
788 | if e.errno != errno.EXDEV: | 788 | if e.errno != errno.EXDEV: |
@@ -796,7 +796,7 @@ def movefile(src, dest, newmtime = None, sstat = None): | |||
796 | if stat.S_ISREG(sstat[stat.ST_MODE]): | 796 | if stat.S_ISREG(sstat[stat.ST_MODE]): |
797 | try: # For safety copy then move it over. | 797 | try: # For safety copy then move it over. |
798 | shutil.copyfile(src, destpath + "#new") | 798 | shutil.copyfile(src, destpath + "#new") |
799 | os.rename(destpath + "#new", destpath) | 799 | bb.utils.rename(destpath + "#new", destpath) |
800 | didcopy = 1 | 800 | didcopy = 1 |
801 | except Exception as e: | 801 | except Exception as e: |
802 | print('movefile: copy', src, '->', dest, 'failed.', e) | 802 | print('movefile: copy', src, '->', dest, 'failed.', e) |
@@ -874,7 +874,7 @@ def copyfile(src, dest, newmtime = None, sstat = None): | |||
874 | 874 | ||
875 | # For safety copy then move it over. | 875 | # For safety copy then move it over. |
876 | shutil.copyfile(src, dest + "#new") | 876 | shutil.copyfile(src, dest + "#new") |
877 | os.rename(dest + "#new", dest) | 877 | bb.utils.rename(dest + "#new", dest) |
878 | except Exception as e: | 878 | except Exception as e: |
879 | logger.warning("copyfile: copy %s to %s failed (%s)" % (src, dest, e)) | 879 | logger.warning("copyfile: copy %s to %s failed (%s)" % (src, dest, e)) |
880 | return False | 880 | return False |
@@ -1669,3 +1669,15 @@ def is_semver(version): | |||
1669 | return False | 1669 | return False |
1670 | 1670 | ||
1671 | return True | 1671 | return True |
1672 | |||
1673 | # Wrapper around os.rename which can handle cross device problems | ||
1674 | # e.g. from container filesystems | ||
1675 | def rename(src, dst): | ||
1676 | try: | ||
1677 | os.rename(src, dst) | ||
1678 | except OSError as err: | ||
1679 | if err.errno == 18: | ||
1680 | # Invalid cross-device link error | ||
1681 | shutil.move(src, dst) | ||
1682 | else: | ||
1683 | raise err | ||