Check ProfileFile existence first

Avoid java.nio.file.NoSuchFileException when readAttributes.
This commit is contained in:
JingMatrix 2023-07-20 12:21:42 +02:00
parent 87a765d65c
commit c3ee8bec23
1 changed files with 4 additions and 2 deletions

View File

@ -208,6 +208,10 @@ public class LSPApplication {
File curProfileFile = new File(profileDir, splitName == null ? "primary.prof" : splitName + ".split.prof").getAbsoluteFile();
Log.d(TAG, "Processing " + curProfileFile.getAbsolutePath());
try {
if (!curProfileFile.exists()) {
Files.createFile(curProfileFile.toPath(), attrs);
continue;
}
if (!curProfileFile.canWrite() && Files.size(curProfileFile.toPath()) == 0) {
Log.d(TAG, "Skip profile " + curProfileFile.getAbsolutePath());
continue;
@ -219,8 +223,6 @@ public class LSPApplication {
Log.e(TAG, "Failed to delete and clear profile file " + curProfileFile.getAbsolutePath(), e);
}
Os.chmod(curProfileFile.getAbsolutePath(), 00400);
} else {
Files.createFile(curProfileFile.toPath(), attrs);
}
} catch (Throwable e) {
Log.e(TAG, "Failed to disable profile file " + curProfileFile.getAbsolutePath(), e);