1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-27 10:55:33 +02:00

[385630] [dstore] backup files created during upload should be removed when upload successful

This commit is contained in:
David McKnight 2012-08-01 15:41:07 +00:00
parent 57850d9ac3
commit 5d0ce36db8

View file

@ -67,7 +67,9 @@ public class ByteStreamHandler implements IByteStreamHandler
if (_doBackups){ if (_doBackups){
String keepBackups = System.getProperty("keepbackupfiles"); //$NON-NLS-1$ String keepBackups = System.getProperty("keepbackupfiles"); //$NON-NLS-1$
_keepBackups = (keepBackups == null || keepBackups.equals("true")); //$NON-NLS-1$
// default is not NOT keep backups
_keepBackups = (keepBackups != null && keepBackups.equals("true")); //$NON-NLS-1$
} }
} }
@ -90,27 +92,35 @@ public class ByteStreamHandler implements IByteStreamHandler
public void run(){ public void run(){
super.run(); super.run();
boolean doneDelete = false; boolean doneDelete = false;
while (!doneDelete){ while (!doneDelete){
try { try {
Thread.sleep(10000); // wait 10 seconds Thread.sleep(10000); // wait 10 seconds
} }
catch (InterruptedException e){ catch (InterruptedException e){
} }
long curLength = _currentFile.length(); // make sure there was no disconnect
if (curLength == _initialLength){ // looks like total upload is complete if (!_dataStore.isConnected()){
_backupFile.delete(); // keep the backup
doneDelete = true; doneDelete = true;
} }
else { else {
_initialLength = curLength; long curLength = _currentFile.length();
if (curLength == _initialLength){ // looks like total upload is complete
_backupFile.delete();
doneDelete = true;
}
else {
_initialLength = curLength;
}
} }
} }
} }
} }
private void deleteBackupFile(File currentFile, File backupFile){ private void deleteBackupFile(File currentFile, File backupFile){
if (backupFile != null && _keepBackups){ // only matters if there is a backup file if (backupFile != null && !_keepBackups){ // only matters if there is a backup file
DeleteBackupThread thread = new DeleteBackupThread(_dataStore, currentFile, backupFile); DeleteBackupThread thread = new DeleteBackupThread(_dataStore, currentFile, backupFile);
thread.start(); thread.start();
} }