From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A09CB1A1E67 for ; Tue, 13 Sep 2016 23:24:12 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP; 13 Sep 2016 23:24:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,332,1470726000"; d="scan'208";a="8121416" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.144]) by fmsmga005.fm.intel.com with ESMTP; 13 Sep 2016 23:24:07 -0700 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: Liming Gao Date: Wed, 14 Sep 2016 14:23:52 +0800 Message-Id: <1473834234-242960-2-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 In-Reply-To: <1473834234-242960-1-git-send-email-yonghong.zhu@intel.com> References: <1473834234-242960-1-git-send-email-yonghong.zhu@intel.com> Subject: [Patch V2] BaseTools: Fix the bug to handle the read-only file X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Sep 2016 06:24:12 -0000 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 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yonghong Zhu --- 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