[FIXED HUDSON-5066] avoid the use of deleteOnExit if the timing to delete the file is known.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24673 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2009-12-17 02:15:05 +00:00
1 parent db369c4444
commit bea7fbda4c
1 file changed
+45 -42
+45 -42
View File
@@ -110,57 +110,60 @@ public class Main {
// write the output to a temporary file first.
File tmpFile = File.createTempFile("hudson","log");
tmpFile.deleteOnExit();
FileOutputStream os = new FileOutputStream(tmpFile);
try {
FileOutputStream os = new FileOutputStream(tmpFile);
Writer w = new OutputStreamWriter(os,"UTF-8");
w.write("<?xml version='1.0' encoding='UTF-8'?>");
w.write("<run><log encoding='hexBinary' content-encoding='"+Charset.defaultCharset().name()+"'>");
w.flush();
Writer w = new OutputStreamWriter(os,"UTF-8");
w.write("<?xml version='1.0' encoding='UTF-8'?>");
w.write("<run><log encoding='hexBinary' content-encoding='"+Charset.defaultCharset().name()+"'>");
w.flush();
// run the command
long start = System.currentTimeMillis();
// run the command
long start = System.currentTimeMillis();
List<String> cmd = new ArrayList<String>();
for( int i=1; i<args.length; i++ )
cmd.add(args[i]);
Proc proc = new Proc.LocalProc(cmd.toArray(new String[0]),(String[])null,System.in,
new DualOutputStream(System.out,new EncodingStream(os)));
List<String> cmd = new ArrayList<String>();
for( int i=1; i<args.length; i++ )
cmd.add(args[i]);
Proc proc = new Proc.LocalProc(cmd.toArray(new String[0]),(String[])null,System.in,
new DualOutputStream(System.out,new EncodingStream(os)));
int ret = proc.join();
int ret = proc.join();
w.write("</log><result>"+ret+"</result><duration>"+(System.currentTimeMillis()-start)+"</duration></run>");
w.close();
w.write("</log><result>"+ret+"</result><duration>"+(System.currentTimeMillis()-start)+"</duration></run>");
w.close();
String location = home+"job/"+projectNameEnc+"/postBuildResult";
while(true) {
try {
// start a remote connection
HttpURLConnection con = (HttpURLConnection) new URL(location).openConnection();
if (auth != null) con.setRequestProperty("Authorization", auth);
con.setDoOutput(true);
// this tells HttpURLConnection not to buffer the whole thing
con.setFixedLengthStreamingMode((int)tmpFile.length());
con.connect();
// send the data
FileInputStream in = new FileInputStream(tmpFile);
Util.copyStream(in,con.getOutputStream());
in.close();
String location = home+"job/"+projectNameEnc+"/postBuildResult";
while(true) {
try {
// start a remote connection
HttpURLConnection con = (HttpURLConnection) new URL(location).openConnection();
if (auth != null) con.setRequestProperty("Authorization", auth);
con.setDoOutput(true);
// this tells HttpURLConnection not to buffer the whole thing
con.setFixedLengthStreamingMode((int)tmpFile.length());
con.connect();
// send the data
FileInputStream in = new FileInputStream(tmpFile);
Util.copyStream(in,con.getOutputStream());
in.close();
if(con.getResponseCode()!=200) {
Util.copyStream(con.getErrorStream(),System.err);
if(con.getResponseCode()!=200) {
Util.copyStream(con.getErrorStream(),System.err);
}
return ret;
} catch (HttpRetryException e) {
if(e.getLocation()!=null) {
// retry with the new location
location = e.getLocation();
continue;
}
// otherwise failed for reasons beyond us.
throw e;
}
return ret;
} catch (HttpRetryException e) {
if(e.getLocation()!=null) {
// retry with the new location
location = e.getLocation();
continue;
}
// otherwise failed for reasons beyond us.
throw e;
}
} finally {
tmpFile.delete();
}
}