Openembedded Bitbake Development
 help / color / mirror / Atom feed
* [Fwd: [PATCH] utils.movefile: specify dest file name]
@ 2015-09-01 17:25 Esquivel, Benjamin
  2015-09-03  7:10 ` [PATCH] bitbake: fixing a potential error in movefile Benjamin Esquivel
  0 siblings, 1 reply; 2+ messages in thread
From: Esquivel, Benjamin @ 2015-09-01 17:25 UTC (permalink / raw)
  To: bitbake-devel@lists.openembedded.org

Sending this to the right list.

Benjamin

-------- Forwarded Message --------
From: Benjamin Esquivel <benjamin.esquivel@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Cc: paul.eggleton@linux.intel.com, Benjamin Esquivel <
benjamin.esquivel@linux.intel.com>
Subject: [PATCH] utils.movefile: specify dest file name
Date: Thu, 20 Aug 2015 13:59:58 +0000

>  When moving a file via the os.rename function, it was missing the
>  destination file name which caused an OSError
> 
>  [YOCTO#8180]
> 
> Signed-off-by: Benjamin Esquivel <benjamin.esquivel@linux.intel.com>
> ---
>  bitbake/lib/bb/utils.py | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
> index 5b94432..5eec787 100644
> --- a/bitbake/lib/bb/utils.py
> +++ b/bitbake/lib/bb/utils.py
> @@ -741,7 +741,9 @@ def movefile(src, dest, newmtime = None, sstat =
> None):
>      renamefailed = 1
>      if sstat[stat.ST_DEV] == dstat[stat.ST_DEV]:
>          try:
> -            os.rename(src, dest)
> +            # os.rename needs to know the destination path with file
> name
> +            destfile = os.path.join(dest, os.path.basename(src))
> +            os.rename(src, destfile) 
>              renamefailed = 0
>          except Exception as e:
>              if e[0] != errno.EXDEV:
> -- 
> 2.3.0
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] bitbake: fixing a potential error in movefile
  2015-09-01 17:25 [Fwd: [PATCH] utils.movefile: specify dest file name] Esquivel, Benjamin
@ 2015-09-03  7:10 ` Benjamin Esquivel
  0 siblings, 0 replies; 2+ messages in thread
From: Benjamin Esquivel @ 2015-09-03  7:10 UTC (permalink / raw)
  To: bitbake-devel

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@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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-09-03 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-01 17:25 [Fwd: [PATCH] utils.movefile: specify dest file name] Esquivel, Benjamin
2015-09-03  7:10 ` [PATCH] bitbake: fixing a potential error in movefile Benjamin Esquivel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox