From aefb11298c36960c4ae49fa830c8a93f1171f52f Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 4 Jul 2019 09:53:25 +0200 Subject: [PATCH] FS_POSIX: handle Files.getFileStore() failures Android unconditionally throws a SecurityException;[1] getFileStore() is not supported. Catch the exception and don't attempt the hard- linking atomic file mechanism. [1] https://android.googlesource.com/platform/libcore/+/21e6175e25 Bug: 548947 Change-Id: Idfba2d9dbcbc80ea15ab2ae7889e5142444c1581 Signed-off-by: Thomas Wolf --- .../src/org/eclipse/jgit/util/FS_POSIX.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java index faef9fd0f..6ec50c24e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java @@ -396,7 +396,12 @@ public boolean createNewFile(File lock) throws IOException { } Path lockPath = lock.toPath(); Path link = null; - FileStore store = Files.getFileStore(lockPath); + FileStore store = null; + try { + store = Files.getFileStore(lockPath); + } catch (SecurityException e) { + return true; + } try { Boolean canLink = CAN_HARD_LINK.computeIfAbsent(store, s -> Boolean.TRUE); @@ -462,7 +467,12 @@ public LockToken createNewFileAtomic(File file) throws IOException { } Path link = null; Path path = file.toPath(); - FileStore store = Files.getFileStore(path); + FileStore store = null; + try { + store = Files.getFileStore(path); + } catch (SecurityException e) { + return token(true, null); + } try { Boolean canLink = CAN_HARD_LINK.computeIfAbsent(store, s -> Boolean.TRUE);