public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Yonghong Zhu <yonghong.zhu@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>
Subject: [Patch V2] BaseTools: Fix the bug to handle the read-only file
Date: Wed, 14 Sep 2016 14:23:52 +0800	[thread overview]
Message-ID: <1473834234-242960-2-git-send-email-yonghong.zhu@intel.com> (raw)
In-Reply-To: <1473834234-242960-1-git-send-email-yonghong.zhu@intel.com>

change the 'r+b' to 'rb' for some file's open, since these files we only
read it and no need to write. It can fix the bug that the file's attribute
had been set to read-only.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
---
 BaseTools/Source/Python/GenFds/FfsFileStatement.py | 2 +-
 BaseTools/Source/Python/GenFds/Fv.py               | 2 +-
 BaseTools/Source/Python/GenFds/FvImageSection.py   | 4 ++--
 BaseTools/Source/Python/GenFds/Region.py           | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
index 690826b..f76ddf4 100644
--- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
@@ -99,11 +99,11 @@ class FileStatement (FileStatementClassObject) :
                     FileContent = ''
                     MaxAlignIndex = 0
                     MaxAlignValue = 1
                     for Index, File in enumerate(self.FileName):
                         try:
-                            f = open(File, 'r+b')
+                            f = open(File, 'rb')
                         except:
                             GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))
                         Content = f.read()
                         f.close()
                         AlignValue = 1
diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py
index 64d1709..ab3f8b2 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -180,11 +180,11 @@ class FV (FvClassObject):
 
         #
         # Write the Fv contents to Buffer
         #
         if os.path.isfile(FvOutputFile):
-            FvFileObj = open ( FvOutputFile,'r+b')
+            FvFileObj = open ( FvOutputFile,'rb')
 
             GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV Successfully" %self.UiFvName)
             GenFdsGlobalVariable.SharpCounter = 0
 
             Buffer.write(FvFileObj.read())
diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/Source/Python/GenFds/FvImageSection.py
index 748d02f..5989978 100644
--- a/BaseTools/Source/Python/GenFds/FvImageSection.py
+++ b/BaseTools/Source/Python/GenFds/FvImageSection.py
@@ -62,11 +62,11 @@ class FvImageSection(FvImageSectionClassObject):
 
             MaxFvAlignment = 0
             for FvFileName in FileList:
                 FvAlignmentValue = 0
                 if os.path.isfile(FvFileName):
-                    FvFileObj = open (FvFileName,'r+b')
+                    FvFileObj = open (FvFileName,'rb')
                     FvFileObj.seek(0)
                     # PI FvHeader is 0x48 byte
                     FvHeaderBuffer = FvFileObj.read(0x48)
                     # FV alignment position.
                     FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)
@@ -107,11 +107,11 @@ class FvImageSection(FvImageSectionClassObject):
                             self.Alignment = Fv.FvAlignment
             else:
                 if self.FvFileName != None:
                     FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)
                     if os.path.isfile(FvFileName):
-                        FvFileObj = open (FvFileName,'r+b')
+                        FvFileObj = open (FvFileName,'rb')
                         FvFileObj.seek(0)
                         # PI FvHeader is 0x48 byte
                         FvHeaderBuffer = FvFileObj.read(0x48)
                         # FV alignment position.
                         FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)
diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py
index e393286..945c548 100644
--- a/BaseTools/Source/Python/GenFds/Region.py
+++ b/BaseTools/Source/Python/GenFds/Region.py
@@ -146,11 +146,11 @@ class Region(RegionClassObject):
                     FileLength = os.stat(FileName)[ST_SIZE]
                     if FileLength > Size:
                         EdkLogger.error("GenFds", GENFDS_ERROR,
                                         "Size of FV File (%s) is larger than Region Size 0x%X specified." \
                                         % (RegionData, Size))
-                    BinFile = open(FileName, 'r+b')
+                    BinFile = open(FileName, 'rb')
                     Buffer.write(BinFile.read())
                     BinFile.close()
                     Size = Size - FileLength
             #
             # Pad the left buffer
@@ -199,11 +199,11 @@ class Region(RegionClassObject):
                 FileLength = os.stat(FileName)[ST_SIZE]
                 if FileLength > Size:
                     EdkLogger.error("GenFds", GENFDS_ERROR,
                                     "Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \
                                     % (FileLength, RegionData, Size))
-                BinFile = open(FileName, 'r+b')
+                BinFile = open(FileName, 'rb')
                 Buffer.write(BinFile.read())
                 BinFile.close()
                 Size = Size - FileLength
             #
             # Pad the left buffer
-- 
2.6.1.windows.1



  reply	other threads:[~2016-09-14  6:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-14  6:23 [Patch 0/2] Update the edk2.tianocore.org URL link Yonghong Zhu
2016-09-14  6:23 ` Yonghong Zhu [this message]
2016-09-14  7:15   ` [Patch V2] BaseTools: Fix the bug to handle the read-only file Gao, Liming
2016-09-14  6:23 ` [Patch 1/2] edksetup.sh: update the URL in edksetup.sh Yonghong Zhu
2016-09-14  6:23 ` [Patch 2/2] IntelFrameworkPkg/FrameworkSpecConformance.txt: Update the URL Yonghong Zhu
2016-09-14  7:04   ` Fan, Jeff
2016-09-14  7:14 ` [Patch 0/2] Update the edk2.tianocore.org URL link Gao, Liming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473834234-242960-2-git-send-email-yonghong.zhu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox