From d1f871da10232f21e402ca0f3dffeabd65d3e196 Mon Sep 17 00:00:00 2001 From: Todor Boev Date: Tue, 4 Sep 2018 15:12:11 +0300 Subject: Bug 537757 - Always attempt to delete old file when moving to backup Since File.exist() is not a reliable check it is performed not as a guard against deleting a non-existent file, but as confirmation that the deletion indeed failed because the file was not there. Change-Id: I77233458892083b3049c323cb004d97e195f475a Signed-off-by: Todor Boev --- .../equinox/internal/p2/touchpoint/natives/BackupStore.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'bundles') diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/BackupStore.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/BackupStore.java index fc877d926..a02815cec 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/BackupStore.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/BackupStore.java @@ -113,12 +113,12 @@ public class BackupStore implements IBackupStore { /** * The name of the backup directory (no path - relative to the backup root). */ - private String backupName; + private final String backupName; /** * The name of a dummy file used to backup empty directories */ - private String dummyName; + private final String dummyName; /** * A server socket that is used to obtain a port (a shared resource on this machine) @@ -143,7 +143,7 @@ public class BackupStore implements IBackupStore { */ private boolean closed; - private Map renamedInPlace = new HashMap<>(); + private final Map renamedInPlace = new HashMap<>(); /** * Generates a BackupStore with a default prefix of ".p2bu" for backup directory and @@ -284,7 +284,9 @@ public class BackupStore implements IBackupStore { Util.copyStream(new FileInputStream(file), true, new FileOutputStream(buFile), true); backupCounter++; } - if (file.exists() && !file.delete()) + + // File.exists() is not reliable so always attempt to delete first and check why it may have failed second. + if (!file.delete() && file.exists()) throw new IOException(NLS.bind(Messages.BackupStore_can_not_delete_after_copy_0, file)); } -- cgit v1.2.3