[edk2-devel] [Patch] BaseTools: use shutil.copyfile instead shutil.copy2

Bob Feng posted 1 patch 3 years, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/20210728114523.687-1-bob.c.feng@intel.com
BaseTools/Source/Python/Split/Split.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[edk2-devel] [Patch] BaseTools: use shutil.copyfile instead shutil.copy2
Posted by Bob Feng 3 years, 4 months ago
In Split tool, the copy file actions only need to
copy file content but not need to copy file metadata.

copy2() copies the file metadata that causes split
unit test failed under edk2-basetools CI environment.

So this patch changes the call of copy2() to copyfile().

Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
---
 BaseTools/Source/Python/Split/Split.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/Split/Split.py b/BaseTools/Source/Python/Split/Split.py
index e223a72a94..e70d5c22c4 100644
--- a/BaseTools/Source/Python/Split/Split.py
+++ b/BaseTools/Source/Python/Split/Split.py
@@ -146,18 +146,18 @@ def splitFile(inputfile, position, outputdir=None, outputfile1=None, outputfile2
         logger.error("Can't make dir: %s" % outputfolder)
         raise(e)
 
     if position <= 0:
         if outputfile2 != os.path.abspath(inputfile):
-            shutil.copy2(os.path.abspath(inputfile), outputfile2)
+            shutil.copyfile(os.path.abspath(inputfile), outputfile2)
         with open(outputfile1, "wb") as fout:
             fout.write(b'')
     else:
         inputfilesize = getFileSize(inputfile)
         if position >= inputfilesize:
             if outputfile1 != os.path.abspath(inputfile):
-                shutil.copy2(os.path.abspath(inputfile), outputfile1)
+                shutil.copyfile(os.path.abspath(inputfile), outputfile1)
             with open(outputfile2, "wb") as fout:
                 fout.write(b'')
         else:
             try:
                 tempdir = tempfile.mkdtemp()
@@ -169,12 +169,12 @@ def splitFile(inputfile, position, outputdir=None, outputfile1=None, outputfile2
                         fout1.write(content1)
 
                     content2 = fin.read(inputfilesize - position)
                     with open(tempfile2, "wb") as fout2:
                         fout2.write(content2)
-                shutil.copy2(tempfile1, outputfile1)
-                shutil.copy2(tempfile2, outputfile2)
+                shutil.copyfile(tempfile1, outputfile1)
+                shutil.copyfile(tempfile2, outputfile2)
             except Exception as e:
                 logger.error("Split file failed")
                 raise(e)
             finally:
                 if os.path.exists(tempdir):
-- 
2.29.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#78282): https://edk2.groups.io/g/devel/message/78282
Mute This Topic: https://groups.io/mt/84503147/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [Patch] BaseTools: use shutil.copyfile instead shutil.copy2
Posted by Yuwei Chen 3 years, 3 months ago
Reviewed-by: Yuwei Chen<yuwei.chen@intel.com>

> -----Original Message-----
> From: Feng, Bob C <bob.c.feng@intel.com>
> Sent: Wednesday, July 28, 2021 7:45 PM
> To: devel@edk2.groups.io
> Cc: Liming Gao <gaoliming@byosoft.com.cn>; Chen, Christine
> <yuwei.chen@intel.com>
> Subject: [Patch] BaseTools: use shutil.copyfile instead shutil.copy2
> 
> In Split tool, the copy file actions only need to copy file content but not need
> to copy file metadata.
> 
> copy2() copies the file metadata that causes split unit test failed under edk2-
> basetools CI environment.
> 
> So this patch changes the call of copy2() to copyfile().
> 
> Signed-off-by: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Yuwei Chen <yuwei.chen@intel.com>
> ---
>  BaseTools/Source/Python/Split/Split.py | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/BaseTools/Source/Python/Split/Split.py
> b/BaseTools/Source/Python/Split/Split.py
> index e223a72a94..e70d5c22c4 100644
> --- a/BaseTools/Source/Python/Split/Split.py
> +++ b/BaseTools/Source/Python/Split/Split.py
> @@ -146,18 +146,18 @@ def splitFile(inputfile, position, outputdir=None,
> outputfile1=None, outputfile2
>          logger.error("Can't make dir: %s" % outputfolder)         raise(e)      if
> position <= 0:         if outputfile2 != os.path.abspath(inputfile):-
> shutil.copy2(os.path.abspath(inputfile), outputfile2)+
> shutil.copyfile(os.path.abspath(inputfile), outputfile2)         with
> open(outputfile1, "wb") as fout:             fout.write(b'')     else:
> inputfilesize = getFileSize(inputfile)         if position >= inputfilesize:             if
> outputfile1 != os.path.abspath(inputfile):-
> shutil.copy2(os.path.abspath(inputfile), outputfile1)+
> shutil.copyfile(os.path.abspath(inputfile), outputfile1)             with
> open(outputfile2, "wb") as fout:                 fout.write(b'')         else:             try:
> tempdir = tempfile.mkdtemp()@@ -169,12 +169,12 @@ def splitFile(inputfile,
> position, outputdir=None, outputfile1=None, outputfile2
>                          fout1.write(content1)                      content2 =
> fin.read(inputfilesize - position)                     with open(tempfile2, "wb") as
> fout2:                         fout2.write(content2)-                shutil.copy2(tempfile1,
> outputfile1)-                shutil.copy2(tempfile2, outputfile2)+
> shutil.copyfile(tempfile1, outputfile1)+                shutil.copyfile(tempfile2,
> outputfile2)             except Exception as e:                 logger.error("Split file
> failed")                 raise(e)             finally:                 if os.path.exists(tempdir):--
> 2.29.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#78475): https://edk2.groups.io/g/devel/message/78475
Mute This Topic: https://groups.io/mt/84503147/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [Patch] BaseTools: use shutil.copyfile instead shutil.copy2
Posted by Philippe Mathieu-Daudé 3 years, 3 months ago
On 7/28/21 1:45 PM, Bob Feng wrote:
> In Split tool, the copy file actions only need to
> copy file content but not need to copy file metadata.
> 
> copy2() copies the file metadata that causes split
> unit test failed under edk2-basetools CI environment.
> 
> So this patch changes the call of copy2() to copyfile().
> 
> Signed-off-by: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Yuwei Chen <yuwei.chen@intel.com>
> ---
>  BaseTools/Source/Python/Split/Split.py | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#78933): https://edk2.groups.io/g/devel/message/78933
Mute This Topic: https://groups.io/mt/84503147/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-