JAL-4308 reduce number of refs to 5, always have canonical reference first.
[jalview.git] / src / jalview / io / BackupFiles.java
index 88524d1..c67c307 100644 (file)
@@ -166,25 +166,33 @@ public class BackupFiles
 
   public static boolean hasSavesInProgress()
   {
-    return savesInProgress.size() > 0;
+    boolean has = false;
+    for (CompletableFuture cf : savesInProgressCompletableFutures(true))
+    {
+      has |= !cf.isDone();
+    }
+    return has;
   }
 
-  public static List<File> savesInProgressFiles()
+  public static List<File> savesInProgressFiles(boolean all)
   {
     List<File> files = new ArrayList<>();
     for (BackupFiles bfile : savesInProgress)
     {
-      files.add(bfile.getFile());
+      if (all || !bfile.getMyFuture().isDone())
+        files.add(bfile.getFile());
     }
     return files;
   }
 
-  public static List<CompletableFuture<Boolean>> savesInProgressCompletableFutures()
+  public static List<CompletableFuture<Boolean>> savesInProgressCompletableFutures(
+          boolean all)
   {
     List<CompletableFuture<Boolean>> cfs = new ArrayList<>();
     for (BackupFiles bfile : savesInProgress)
     {
-      cfs.add(bfile.getMyFuture());
+      if (all || !bfile.getMyFuture().isDone())
+        cfs.add(bfile.getMyFuture());
     }
     return cfs;
   }
@@ -224,6 +232,12 @@ public class BackupFiles
   public BackupFiles(File file)
   {
     classInit();
+    if (file.getParentFile() == null)
+    {
+      // filename probably in pwd represented with no parent -- fix it before
+      // it's a problem
+      file = file.getAbsoluteFile();
+    }
     this.file = file;
 
     // add this file from the save in progress stack
@@ -244,7 +258,8 @@ public class BackupFiles
       if (file != null)
       {
         String tempfilename = file.getName();
-        File tempdir = file.getParentFile();
+        File tempdir = file.getAbsoluteFile().getParentFile();
+        tempdir.mkdirs();
         Console.trace(
                 "BACKUPFILES [file!=null] attempting to create temp file for "
                         + tempfilename + " in dir " + tempdir);
@@ -274,7 +289,7 @@ public class BackupFiles
     this.setTempFile(temp);
   }
 
-  public static void classInit()
+  private static void classInit()
   {
     Console.initLogger();
     Console.trace("BACKUPFILES classInit");