From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 760381A1E60 for ; Wed, 14 Sep 2016 00:15:49 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP; 14 Sep 2016 00:15:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,332,1470726000"; d="scan'208";a="8351803" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga005.jf.intel.com with ESMTP; 14 Sep 2016 00:15:49 -0700 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 14 Sep 2016 00:15:48 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 14 Sep 2016 00:15:48 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.109]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.174]) with mapi id 14.03.0248.002; Wed, 14 Sep 2016 15:15:46 +0800 From: "Gao, Liming" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" Thread-Topic: [Patch V2] BaseTools: Fix the bug to handle the read-only file Thread-Index: AQHSDlCfSrQV31ejpk++2vk6xbasuKB4kvkw Date: Wed, 14 Sep 2016 07:15:46 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14B3E7C3B@shsmsx102.ccr.corp.intel.com> References: <1473834234-242960-1-git-send-email-yonghong.zhu@intel.com> <1473834234-242960-2-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1473834234-242960-2-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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 07:15:49 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Zhu, Yonghong > Sent: Wednesday, September 14, 2016 2:24 PM > To: edk2-devel@lists.01.org > Cc: Gao, Liming > Subject: [Patch V2] BaseTools: Fix the bug to handle the read-only file >=20 > 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 attribut= e > had been set to read-only. >=20 > 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(-) >=20 > 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 =3D '' > MaxAlignIndex =3D 0 > MaxAlignValue =3D 1 > for Index, File in enumerate(self.FileName): > try: > - f =3D open(File, 'r+b') > + f =3D open(File, 'rb') > except: > GenFdsGlobalVariable.ErrorLogger("Error open= ing RAW > file %s." % (File)) > Content =3D f.read() > f.close() > AlignValue =3D 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): >=20 > # > # Write the Fv contents to Buffer > # > if os.path.isfile(FvOutputFile): > - FvFileObj =3D open ( FvOutputFile,'r+b') > + FvFileObj =3D open ( FvOutputFile,'rb') >=20 > GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV > Successfully" %self.UiFvName) > GenFdsGlobalVariable.SharpCounter =3D 0 >=20 > 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): >=20 > MaxFvAlignment =3D 0 > for FvFileName in FileList: > FvAlignmentValue =3D 0 > if os.path.isfile(FvFileName): > - FvFileObj =3D open (FvFileName,'r+b') > + FvFileObj =3D open (FvFileName,'rb') > FvFileObj.seek(0) > # PI FvHeader is 0x48 byte > FvHeaderBuffer =3D FvFileObj.read(0x48) > # FV alignment position. > FvAlignmentValue =3D 1 << (ord (FvHeaderBuffer[0x2E]= ) & 0x1F) > @@ -107,11 +107,11 @@ class FvImageSection(FvImageSectionClassObject): > self.Alignment =3D Fv.FvAlignment > else: > if self.FvFileName !=3D None: > FvFileName =3D > GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName) > if os.path.isfile(FvFileName): > - FvFileObj =3D open (FvFileName,'r+b') > + FvFileObj =3D open (FvFileName,'rb') > FvFileObj.seek(0) > # PI FvHeader is 0x48 byte > FvHeaderBuffer =3D FvFileObj.read(0x48) > # FV alignment position. > FvAlignmentValue =3D 1 << (ord (FvHeaderBuffer[0= x2E]) & 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 =3D 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 =3D open(FileName, 'r+b') > + BinFile =3D open(FileName, 'rb') > Buffer.write(BinFile.read()) > BinFile.close() > Size =3D Size - FileLength > # > # Pad the left buffer > @@ -199,11 +199,11 @@ class Region(RegionClassObject): > FileLength =3D os.stat(FileName)[ST_SIZE] > if FileLength > Size: > EdkLogger.error("GenFds", GENFDS_ERROR, > "Size 0x%X of Capsule File (%s) is l= arger than Region Size > 0x%X specified." \ > % (FileLength, RegionData, Size)) > - BinFile =3D open(FileName, 'r+b') > + BinFile =3D open(FileName, 'rb') > Buffer.write(BinFile.read()) > BinFile.close() > Size =3D Size - FileLength > # > # Pad the left buffer > -- > 2.6.1.windows.1