mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-22 20:47:57 +01:00
Add FileUtils.maybeDeleteFileOrThrow(File)
This commit is contained in:
parent
affdcb0557
commit
a70ae7ab8e
4 changed files with 15 additions and 25 deletions
|
@ -196,4 +196,15 @@ public final class FileUtils {
|
|||
throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void maybeDeleteFileOrThrow(File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean successfullyDeleted = file.delete();
|
||||
if (!successfullyDeleted) {
|
||||
throw new IOException("Could not delete file " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.jivesoftware.smackx.ox.store.filebased;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Date;
|
||||
|
@ -68,12 +67,7 @@ public class FileBasedOpenPgpKeyStore extends AbstractOpenPgpKeyStore {
|
|||
File file = getPublicKeyRingPath(owner);
|
||||
|
||||
if (publicKeys == null) {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
if (!file.delete()) {
|
||||
throw new IOException("Could not delete file " + file.getAbsolutePath());
|
||||
}
|
||||
FileUtils.maybeDeleteFileOrThrow(file);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -91,12 +85,7 @@ public class FileBasedOpenPgpKeyStore extends AbstractOpenPgpKeyStore {
|
|||
File file = getSecretKeyRingPath(owner);
|
||||
|
||||
if (secretKeys == null) {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
if (!file.delete()) {
|
||||
throw new IOException("Could not delete file " + file.getAbsolutePath());
|
||||
}
|
||||
FileUtils.maybeDeleteFileOrThrow(file);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,12 +122,7 @@ public class FileBasedOpenPgpMetadataStore extends AbstractOpenPgpMetadataStore
|
|||
throws IOException {
|
||||
|
||||
if (data == null || data.isEmpty()) {
|
||||
if (!destination.exists()) {
|
||||
return;
|
||||
}
|
||||
if (!destination.delete()) {
|
||||
throw new IOException("Cannot delete file " + destination.getAbsolutePath());
|
||||
}
|
||||
FileUtils.maybeDeleteFileOrThrow(destination);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,12 +99,7 @@ public class FileBasedOpenPgpTrustStore extends AbstractOpenPgpTrustStore {
|
|||
File file = getTrustPath(owner, fingerprint);
|
||||
|
||||
if (trust == null || trust == Trust.undecided) {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
if (!file.delete()) {
|
||||
throw new IOException("Could not delete file " + file.getAbsolutePath());
|
||||
}
|
||||
FileUtils.maybeDeleteFileOrThrow(file);
|
||||
}
|
||||
|
||||
File parent = file.getParentFile();
|
||||
|
|
Loading…
Reference in a new issue