All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bitbake: lib/bb/utils: fix movefile() copy to dir fallback
@ 2017-09-21 14:33 Mardegan, Alberto
  0 siblings, 0 replies; 4+ messages in thread
From: Mardegan, Alberto @ 2017-09-21 14:33 UTC (permalink / raw)
  To: bitbake-devel

When the destination is a directory, building the the destination file
path is always needed.  That's because even if the copy fallback is
taken, it's always followed by a rename.

Signed-off-by: Alberto Mardegan <amardegan@luxoft.com>
---
 bitbake/lib/bb/utils.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 8550af3..c540b49 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -771,13 +771,14 @@ def movefile(src, dest, newmtime = None, sstat = None):
             return None

     renamefailed = 1
+    # 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
+
     if sstat[stat.ST_DEV] == dstat[stat.ST_DEV]:
         try:
-            # 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:
@@ -791,8 +792,8 @@ def movefile(src, dest, newmtime = None, sstat = None):
         didcopy = 0
         if stat.S_ISREG(sstat[stat.ST_MODE]):
             try: # For safety copy then move it over.
-                shutil.copyfile(src, dest + "#new")
-                os.rename(dest + "#new", dest)
+                shutil.copyfile(src, destpath + "#new")
+                os.rename(destpath + "#new", destpath)
                 didcopy = 1
             except Exception as e:
                 print('movefile: copy', src, '->', dest, 'failed.', e)
@@ -813,9 +814,9 @@ def movefile(src, dest, newmtime = None, sstat = None):
             return None

     if newmtime:
-        os.utime(dest, (newmtime, newmtime))
+        os.utime(destpath, (newmtime, newmtime))
     else:
-        os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME]))
+        os.utime(destpath, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME]))
         newmtime = sstat[stat.ST_MTIME]
     return newmtime

--
2.7.4

________________________________

This e-mail and any attachment(s) are intended only for the recipient(s) named above and others who have been specifically authorized to receive them. They may contain confidential information. If you are not the intended recipient, please do not read this email or its attachment(s). Furthermore, you are hereby notified that any dissemination, distribution or copying of this e-mail and any attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by replying to this e-mail and then delete this e-mail and any attachment(s) or copies thereof from your system. Thank you.


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

* Re: [PATCH] bitbake: lib/bb/utils: fix movefile() copy to dir fallback
  2017-09-21 14:12 ` Alexander Kanavin
@ 2017-09-21 14:23   ` Mardegan, Alberto
  0 siblings, 0 replies; 4+ messages in thread
From: Mardegan, Alberto @ 2017-09-21 14:23 UTC (permalink / raw)
  To: poky

On 09/21/2017 04:12 PM, Alexander Kanavin wrote:
[...]
> This patch should go to bitbake-devel list. Also, please use git
> send-email :)

Oops! Will do :-)

Ciao,
   Alberto

________________________________

This e-mail and any attachment(s) are intended only for the recipient(s) named above and others who have been specifically authorized to receive them. They may contain confidential information. If you are not the intended recipient, please do not read this email or its attachment(s). Furthermore, you are hereby notified that any dissemination, distribution or copying of this e-mail and any attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by replying to this e-mail and then delete this e-mail and any attachment(s) or copies thereof from your system. Thank you.

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

* Re: [PATCH] bitbake: lib/bb/utils: fix movefile() copy to dir fallback
  2017-09-21 14:08 Mardegan, Alberto
@ 2017-09-21 14:12 ` Alexander Kanavin
  2017-09-21 14:23   ` Mardegan, Alberto
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Kanavin @ 2017-09-21 14:12 UTC (permalink / raw)
  To: Mardegan, Alberto, poky

On 09/21/2017 05:08 PM, Mardegan, Alberto wrote:
> 
> ________________________________
> 
> This e-mail and any attachment(s) are intended only for the recipient(s) named above and others who have been specifically authorized to receive them. They may contain confidential information. If you are not the intended recipient, please do not read this email or its attachment(s). Furthermore, you are hereby notified that any dissemination, distribution or copying of this e-mail and any attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by replying to this e-mail and then delete this e-mail and any attachment(s) or copies thereof from your system. Thank you.

This patch should go to bitbake-devel list. Also, please use git 
send-email :)


Alex


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

* [PATCH] bitbake: lib/bb/utils: fix movefile() copy to dir fallback
@ 2017-09-21 14:08 Mardegan, Alberto
  2017-09-21 14:12 ` Alexander Kanavin
  0 siblings, 1 reply; 4+ messages in thread
From: Mardegan, Alberto @ 2017-09-21 14:08 UTC (permalink / raw)
  To: poky

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]


________________________________

This e-mail and any attachment(s) are intended only for the recipient(s) named above and others who have been specifically authorized to receive them. They may contain confidential information. If you are not the intended recipient, please do not read this email or its attachment(s). Furthermore, you are hereby notified that any dissemination, distribution or copying of this e-mail and any attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by replying to this e-mail and then delete this e-mail and any attachment(s) or copies thereof from your system. Thank you.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-bitbake-lib-bb-utils-fix-movefile-copy-to-dir-fallba.patch --]
[-- Type: text/x-patch; name="0001-bitbake-lib-bb-utils-fix-movefile-copy-to-dir-fallba.patch", Size: 2664 bytes --]

From 685373a2d78af23de8e29bf4f771af6b7f28fdf0 Mon Sep 17 00:00:00 2001
From: Alberto Mardegan <amardegan@luxoft.com>
Date: Wed, 20 Sep 2017 16:35:00 +0200
Subject: [PATCH] bitbake: lib/bb/utils: fix movefile() copy to dir fallback

When the destination is a directory, building the the destination file
path is always needed.  That's because even if the copy fallback is
taken, it's always followed by a rename.

Signed-off-by: Alberto Mardegan <amardegan@luxoft.com>
---
 bitbake/lib/bb/utils.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 8550af3..c540b49 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -771,13 +771,14 @@ def movefile(src, dest, newmtime = None, sstat = None):
             return None
 
     renamefailed = 1
+    # 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
+
     if sstat[stat.ST_DEV] == dstat[stat.ST_DEV]:
         try:
-            # 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:
@@ -791,8 +792,8 @@ def movefile(src, dest, newmtime = None, sstat = None):
         didcopy = 0
         if stat.S_ISREG(sstat[stat.ST_MODE]):
             try: # For safety copy then move it over.
-                shutil.copyfile(src, dest + "#new")
-                os.rename(dest + "#new", dest)
+                shutil.copyfile(src, destpath + "#new")
+                os.rename(destpath + "#new", destpath)
                 didcopy = 1
             except Exception as e:
                 print('movefile: copy', src, '->', dest, 'failed.', e)
@@ -813,9 +814,9 @@ def movefile(src, dest, newmtime = None, sstat = None):
             return None
 
     if newmtime:
-        os.utime(dest, (newmtime, newmtime))
+        os.utime(destpath, (newmtime, newmtime))
     else:
-        os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME]))
+        os.utime(destpath, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME]))
         newmtime = sstat[stat.ST_MTIME]
     return newmtime
 
-- 
2.7.4


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

end of thread, other threads:[~2017-09-21 14:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-21 14:33 [PATCH] bitbake: lib/bb/utils: fix movefile() copy to dir fallback Mardegan, Alberto
  -- strict thread matches above, loose matches on Subject: below --
2017-09-21 14:08 Mardegan, Alberto
2017-09-21 14:12 ` Alexander Kanavin
2017-09-21 14:23   ` Mardegan, Alberto

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.