delete fs state if failed to write the file

This commit is contained in:
Eugene Zhuravlev
2012-05-24 21:31:22 +02:00
parent 5d22bd4e1a
commit 6a285450a4
@@ -324,32 +324,25 @@ final class BuildSession implements Runnable, CanceledStatus {
private static void saveFsState(File dataStorageRoot, BuildFSState state, long lastEventOrdinal) {
final File file = new File(dataStorageRoot, FS_STATE_FILE);
BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
try {
final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
final DataOutputStream out = new DataOutputStream(bytes);
out.writeLong(lastEventOrdinal);
try {
out.writeLong(lastEventOrdinal);
state.save(out);
}
finally {
out.close();
}
}
catch (IOException e) {
LOG.error(e);
return;
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
}
catch (FileNotFoundException e) {
FileUtil.createIfDoesntExist(file);
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
}
catch (FileNotFoundException e) {
FileUtil.createIfDoesntExist(file);
}
try {
if (fos == null) {
fos = new FileOutputStream(file);
}
@@ -359,8 +352,9 @@ final class BuildSession implements Runnable, CanceledStatus {
finally {
fos.close();
}
}
catch (IOException e) {
catch (Throwable e) {
LOG.error(e);
FileUtil.delete(file);
}