99
1010import java .io .IOException ;
1111import java .nio .charset .StandardCharsets ;
12+ import java .nio .file .AtomicMoveNotSupportedException ;
1213import java .nio .file .Files ;
1314import java .nio .file .Path ;
1415import java .nio .file .StandardCopyOption ;
@@ -40,7 +41,8 @@ public QuickAccessService.QuickAccessEntry add(Path target, String displayName)
4041 var entries = Files .readAllLines (BOOKMARKS_FILE , StandardCharsets .UTF_8 );
4142 entries .add (entryLine );
4243 Files .write (TMP_FILE , entries , StandardCharsets .UTF_8 , StandardOpenOption .WRITE , StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING );
43- Files .move (TMP_FILE , BOOKMARKS_FILE , StandardCopyOption .REPLACE_EXISTING , StandardCopyOption .ATOMIC_MOVE );
44+
45+ persistTmpFile ();
4446 return new NautilusQuickAccessEntry (entryLine );
4547 } catch (IOException e ) {
4648 throw new QuickAccessServiceException ("Adding entry to Nautilus bookmarks file failed." , e );
@@ -71,7 +73,7 @@ public void remove() throws QuickAccessServiceException {
7173 var entries = Files .readAllLines (BOOKMARKS_FILE );
7274 if (entries .remove (line )) {
7375 Files .write (TMP_FILE , entries , StandardCharsets .UTF_8 , StandardOpenOption .WRITE , StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING );
74- Files . move ( TMP_FILE , BOOKMARKS_FILE , StandardCopyOption . REPLACE_EXISTING , StandardCopyOption . ATOMIC_MOVE );
76+ persistTmpFile ( );
7577 }
7678 isRemoved = true ;
7779 } catch (IOException e ) {
@@ -82,6 +84,14 @@ public void remove() throws QuickAccessServiceException {
8284 }
8385 }
8486
87+ static void persistTmpFile () throws IOException {
88+ try {
89+ Files .move (TMP_FILE , BOOKMARKS_FILE , StandardCopyOption .REPLACE_EXISTING , StandardCopyOption .ATOMIC_MOVE );
90+ } catch (AtomicMoveNotSupportedException e ) {
91+ Files .move (TMP_FILE , BOOKMARKS_FILE , StandardCopyOption .REPLACE_EXISTING );
92+ }
93+ }
94+
8595 @ CheckAvailability
8696 public static boolean isSupported () {
8797 return Files .exists (BOOKMARKS_FILE );
0 commit comments