1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-12-26 06:45:33 +00:00

Trying to rename downloaded files more than once. This could help against aggressive anti virus tools.

This commit is contained in:
Fabian Schlenz 2016-09-15 06:23:10 +02:00
parent 7e26ff0849
commit 3db48864bc
2 changed files with 20 additions and 1 deletions

View File

@ -40,6 +40,9 @@ public class Config {
public static int DELAY_AFTER_GET_MESSAGES = 100;
public static int DELAY_AFTER_GET_FILE = 100;
public static int RENAMING_MAX_TRIES = 5;
public static int RENAMING_DELAY = 1000;
public static final String SECRET_GMAPS = "AIzaSyBEtUDhCQKEH6i2Mn1GAiQ9M_tLN0vxHIs";
static {

View File

@ -311,7 +311,23 @@ public class DownloadManager {
System.exit(1);
}
logger.trace("Renaming {} to {}", temp_filename, target);
Files.move(new File(temp_filename).toPath(), new File(target).toPath(), StandardCopyOption.REPLACE_EXISTING);
int rename_tries = 0;
IOException last_exception = null;
while (rename_tries <= Config.RENAMING_MAX_TRIES) {
rename_tries++;
try {
Files.move(new File(temp_filename).toPath(), new File(target).toPath(), StandardCopyOption.REPLACE_EXISTING);
last_exception = null;
break;
} catch (IOException e) {
logger.debug("Exception during move. rename_tries: {}. Exception: {}", rename_tries, e);
last_exception = e;
try { Thread.sleep(Config.RENAMING_DELAY); } catch (InterruptedException e2) {}
}
}
if (last_exception != null) {
throw last_exception;
}
last_download_succeeded = true;
return true;
} catch (java.io.IOException ex) {