diff options
author | nea <romangraef@gmail.com> | 2022-10-14 22:23:16 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-10-14 22:23:16 +0200 |
commit | 500a04df7a3d15d858bce6732767476c5b5a69a7 (patch) | |
tree | 50593c981caf4f3e7a42231a69b12a341285f812 /updater | |
parent | f4e8a8b343125744a80bb49a433f7796bda2fe4a (diff) | |
download | libautoupdate-500a04df7a3d15d858bce6732767476c5b5a69a7.tar.gz libautoupdate-500a04df7a3d15d858bce6732767476c5b5a69a7.tar.bz2 libautoupdate-500a04df7a3d15d858bce6732767476c5b5a69a7.zip |
Javadocs
Diffstat (limited to 'updater')
-rw-r--r-- | updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java b/updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java index d143fee..cf9a820 100644 --- a/updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java +++ b/updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java @@ -8,7 +8,7 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; public class PostExitMain { - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, InterruptedException { File outputFile = new File(".autoupdates", "postexit.log"); outputFile.getParentFile().mkdirs(); PrintStream printStream = new PrintStream(new FileOutputStream(outputFile, true)); @@ -18,13 +18,15 @@ public class PostExitMain { for (int i = 0; i < args.length; i++) { switch (args[i].intern()) { case "delete": - File file = new File(args[++i]); + File file = unlockedFile(args[++i]); System.out.println("Deleting " + file); - file.delete(); + if (!file.delete()) { + System.out.println("Failed to delete " + file); + } break; case "move": - File from = new File(args[++i]); - File to = new File(args[++i]); + File from = unlockedFile(args[++i]); + File to = unlockedFile(args[++i]); System.out.println("Moving " + from + " to " + to); // Use Files.move instead of File.renameTo, since renameTo is not well-defined. Files.move(from.toPath(), to.toPath(), StandardCopyOption.REPLACE_EXISTING); @@ -36,11 +38,14 @@ public class PostExitMain { } } - public void unlockedFile(File file) throws InterruptedException { - while (!file.exists() || !file.renameTo(file)) { + public static File unlockedFile(String name) throws InterruptedException { + File file = new File(name); + while (file.exists() && !file.renameTo(file)) { + System.out.println("Waiting on a process to relinquish access to " + file); Thread.sleep(1000L); } file.getParentFile().mkdirs(); + return file; } } |