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 <thomas.wolf@paranor.ch>
This commit is contained in:
Thomas Wolf 2019-07-04 09:53:25 +02:00 committed by Matthias Sohn
parent f54db4a857
commit aefb11298c
1 changed files with 12 additions and 2 deletions

View File

@ -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);