Modify GenFfsFileTask.

If GenFfsFileTask is failed, the *.ffs file will not be create.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1598 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qouyang 2006-09-22 08:16:10 +00:00
parent 8554faeb7d
commit c493be6c9d
3 changed files with 34 additions and 16 deletions

View File

@ -150,7 +150,6 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
if (this.ffsFileType.equals("")) { if (this.ffsFileType.equals("")) {
throw new BuildException ("Must set ffsFileType!\n"); throw new BuildException ("Must set ffsFileType!\n");
} }
// //
// Create ffs file. File name = FfsFileGuid + BaseName + ffsSuffix. // Create ffs file. File name = FfsFileGuid + BaseName + ffsSuffix.
// If outputDir's value was set, file will output to the outputDir. // If outputDir's value was set, file will output to the outputDir.
@ -169,7 +168,16 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
String ffsFilePath = outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix; String ffsFilePath = outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix;
File ffsFile = new File (ffsFilePath); File ffsFile = new File (ffsFilePath);
try{
genFfs(ffsFile); genFfs(ffsFile);
}catch (BuildException e){
if (ffsFile != null && ffsFile.exists()){
ffsFile.deleteOnExit();
}
throw new BuildException(e.getMessage());
}
} }
/** /**
@ -742,7 +750,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
@param ffsFile Name of FFS file. @param ffsFile Name of FFS file.
@param isOrg Flag to indicate generate ORG ffs file or not. @param isOrg Flag to indicate generate ORG ffs file or not.
**/ **/
private void genFfs(File ffsFile) { private void genFfs(File ffsFile) throws BuildException {
Section sect; Section sect;
int fileSize; int fileSize;
int fileDataSize; int fileDataSize;
@ -772,6 +780,9 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
// //
sect.toBuffer((DataOutputStream)dataBuffer); sect.toBuffer((DataOutputStream)dataBuffer);
} catch (Exception e) { } catch (Exception e) {
if (dataBuffer != null){
dataBuffer.close();
}
throw new BuildException (e.getMessage()); throw new BuildException (e.getMessage());
} }
} }

View File

@ -303,11 +303,12 @@ public class GenSectionTask extends Task implements EfiDefine, Section, FfsTypes
System.out.print(e.getMessage()); System.out.print(e.getMessage());
throw new BuildException( throw new BuildException(
"Compress.toBuffer failed at section"); "Compress.toBuffer failed at section");
} } finally {
if (Do != null){
}
Do.close(); Do.close();
}
}
}
// //
// Call compress // Call compress
// //

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.tianocore.common.logger.EdkLog; import org.tianocore.common.logger.EdkLog;
@ -36,7 +37,7 @@ public class Tool implements EfiDefine, Section {
private Input inputFiles = new Input(); private Input inputFiles = new Input();
private Input tempInputFile = new Input(); private Input tempInputFile = new Input();
private String outputPath; private String outputPath;
private File outputFile ; private String outputFileName ;
private List<Section> gensectList = new ArrayList<Section>(); private List<Section> gensectList = new ArrayList<Section>();
/** /**
Call extern tool Call extern tool
@ -56,7 +57,7 @@ public class Tool implements EfiDefine, Section {
/// ///
/// check if file exist /// check if file exist
/// ///
//File OutputFile = new File (this.outPutFileName); File outputFile = new File (this.outputFileName);
if (!outputFile.exists()) { if (!outputFile.exists()) {
throw new BuildException("The file " + outputFile.getPath() + " does not exist!\n"); throw new BuildException("The file " + outputFile.getPath() + " does not exist!\n");
} }
@ -133,8 +134,12 @@ public class Tool implements EfiDefine, Section {
catch (BuildException e) { catch (BuildException e) {
EdkLog.log(e.getMessage()); EdkLog.log(e.getMessage());
throw new BuildException ("GenSection failed at Tool!"); throw new BuildException ("GenSection failed at Tool!");
} } finally {
if (Do != null){
Do.close(); Do.close();
}
}
this.tempInputFile.insFile(outputFile.getPath()); this.tempInputFile.insFile(outputFile.getPath());
} }
} catch (IOException e){ } catch (IOException e){
@ -142,10 +147,12 @@ public class Tool implements EfiDefine, Section {
} }
try { try {
outputFile = File.createTempFile("temp", null, new File(outputPath)); Random ran = new Random(9999);
this.outputFileName = "Temp" + ran.nextInt();
argument = toolArgList + inputFiles.toStringWithSinglepPrefix(" -i ") argument = toolArgList + inputFiles.toStringWithSinglepPrefix(" -i ")
+ tempInputFile.toString(" ")+ " -o " + outputFile.getPath(); + tempInputFile.toString(" ")+ " -o " + outputFileName;
EdkLog.log(this, EdkLog.EDK_VERBOSE, command + " " + argument); EdkLog.log(this, EdkLog.EDK_VERBOSE, command + " " + argument);
EdkLog.log(this, EdkLog.EDK_INFO, this.outputFileName);
/// ///
/// execute command line /// execute command line
/// ///
@ -158,8 +165,7 @@ public class Tool implements EfiDefine, Section {
file.delete(); file.delete();
} }
} }
} catch (Exception e) { } catch (Exception e) { EdkLog.log(e.getMessage());
EdkLog.log(e.getMessage());
throw new BuildException("Execution of externalTool task failed!\n"); throw new BuildException("Execution of externalTool task failed!\n");
} }
} }