BaseTools: Fix the bug to handle the read-only file
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> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
@ -101,7 +101,7 @@ class FileStatement (FileStatementClassObject) :
|
|||||||
MaxAlignValue = 1
|
MaxAlignValue = 1
|
||||||
for Index, File in enumerate(self.FileName):
|
for Index, File in enumerate(self.FileName):
|
||||||
try:
|
try:
|
||||||
f = open(File, 'r+b')
|
f = open(File, 'rb')
|
||||||
except:
|
except:
|
||||||
GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))
|
GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))
|
||||||
Content = f.read()
|
Content = f.read()
|
||||||
|
@ -182,7 +182,7 @@ class FV (FvClassObject):
|
|||||||
# Write the Fv contents to Buffer
|
# Write the Fv contents to Buffer
|
||||||
#
|
#
|
||||||
if os.path.isfile(FvOutputFile):
|
if os.path.isfile(FvOutputFile):
|
||||||
FvFileObj = open ( FvOutputFile,'r+b')
|
FvFileObj = open ( FvOutputFile,'rb')
|
||||||
|
|
||||||
GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV Successfully" %self.UiFvName)
|
GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV Successfully" %self.UiFvName)
|
||||||
GenFdsGlobalVariable.SharpCounter = 0
|
GenFdsGlobalVariable.SharpCounter = 0
|
||||||
|
@ -64,7 +64,7 @@ class FvImageSection(FvImageSectionClassObject):
|
|||||||
for FvFileName in FileList:
|
for FvFileName in FileList:
|
||||||
FvAlignmentValue = 0
|
FvAlignmentValue = 0
|
||||||
if os.path.isfile(FvFileName):
|
if os.path.isfile(FvFileName):
|
||||||
FvFileObj = open (FvFileName,'r+b')
|
FvFileObj = open (FvFileName,'rb')
|
||||||
FvFileObj.seek(0)
|
FvFileObj.seek(0)
|
||||||
# PI FvHeader is 0x48 byte
|
# PI FvHeader is 0x48 byte
|
||||||
FvHeaderBuffer = FvFileObj.read(0x48)
|
FvHeaderBuffer = FvFileObj.read(0x48)
|
||||||
@ -109,7 +109,7 @@ class FvImageSection(FvImageSectionClassObject):
|
|||||||
if self.FvFileName != None:
|
if self.FvFileName != None:
|
||||||
FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)
|
FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)
|
||||||
if os.path.isfile(FvFileName):
|
if os.path.isfile(FvFileName):
|
||||||
FvFileObj = open (FvFileName,'r+b')
|
FvFileObj = open (FvFileName,'rb')
|
||||||
FvFileObj.seek(0)
|
FvFileObj.seek(0)
|
||||||
# PI FvHeader is 0x48 byte
|
# PI FvHeader is 0x48 byte
|
||||||
FvHeaderBuffer = FvFileObj.read(0x48)
|
FvHeaderBuffer = FvFileObj.read(0x48)
|
||||||
|
@ -148,7 +148,7 @@ class Region(RegionClassObject):
|
|||||||
EdkLogger.error("GenFds", GENFDS_ERROR,
|
EdkLogger.error("GenFds", GENFDS_ERROR,
|
||||||
"Size of FV File (%s) is larger than Region Size 0x%X specified." \
|
"Size of FV File (%s) is larger than Region Size 0x%X specified." \
|
||||||
% (RegionData, Size))
|
% (RegionData, Size))
|
||||||
BinFile = open(FileName, 'r+b')
|
BinFile = open(FileName, 'rb')
|
||||||
Buffer.write(BinFile.read())
|
Buffer.write(BinFile.read())
|
||||||
BinFile.close()
|
BinFile.close()
|
||||||
Size = Size - FileLength
|
Size = Size - FileLength
|
||||||
@ -201,7 +201,7 @@ class Region(RegionClassObject):
|
|||||||
EdkLogger.error("GenFds", GENFDS_ERROR,
|
EdkLogger.error("GenFds", GENFDS_ERROR,
|
||||||
"Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \
|
"Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \
|
||||||
% (FileLength, RegionData, Size))
|
% (FileLength, RegionData, Size))
|
||||||
BinFile = open(FileName, 'r+b')
|
BinFile = open(FileName, 'rb')
|
||||||
Buffer.write(BinFile.read())
|
Buffer.write(BinFile.read())
|
||||||
BinFile.close()
|
BinFile.close()
|
||||||
Size = Size - FileLength
|
Size = Size - FileLength
|
||||||
|
Reference in New Issue
Block a user