[bitbake-devel] [PATCH] bitbake: fixing a potential error in movefile

Benjamin Esquivel benjamin.esquivel at linux.intel.com
Thu Sep 3 07:10:45 UTC 2015


bitbake utils' movefile is now prone to malform the destination
file with duplicated file name strings. Fixing it to force a file
name append iff the dest argument is a dir not a file name

Signed-off-by: Benjamin Esquivel <benjamin.esquivel at linux.intel.com>
---
 bitbake/lib/bb/utils.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 5eec787..b62985d 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -741,9 +741,12 @@ def movefile(src, dest, newmtime = None, sstat = None):
     renamefailed = 1
     if sstat[stat.ST_DEV] == dstat[stat.ST_DEV]:
         try:
-            # os.rename needs to know the destination path with file name
-            destfile = os.path.join(dest, os.path.basename(src))
-            os.rename(src, destfile) 
+            # os.rename needs to know the dest path ending with file name
+            # so append the file name to a path only if it's a dir specified
+            srcfname = os.path.basename(src)
+            destpath = os.path.join(dest, srcfname) if os.path.isdir(dest) \
+                        else dest
+            os.rename(src, destpath)
             renamefailed = 0
         except Exception as e:
             if e[0] != errno.EXDEV:
-- 
2.3.0




More information about the bitbake-devel mailing list