mirror of
https://github.com/nix-community/nix-on-droid-app.git
synced 2025-12-09 10:31:13 +01:00
deleteFolder(): check if passed argument is a symlink
Prevents possible data loss when user replaced directory '~/storage' with a symlink.
This commit is contained in:
parent
d1f0c76db3
commit
b7864d6ac2
1 changed files with 7 additions and 7 deletions
|
|
@ -209,18 +209,18 @@ final class TermuxInstaller {
|
|||
Arrays.toString(Build.SUPPORTED_ABIS));
|
||||
}
|
||||
|
||||
/** Delete a folder and all its content or throw. */
|
||||
/** Delete a folder and all its content or throw. Don't follow symlinks. */
|
||||
static void deleteFolder(File fileOrDirectory) throws IOException {
|
||||
File[] children = fileOrDirectory.listFiles();
|
||||
if (children != null) {
|
||||
for (File child : children) {
|
||||
if (child.getCanonicalFile().equals(child.getAbsoluteFile())) {
|
||||
if (fileOrDirectory.getCanonicalPath().equals(fileOrDirectory.getAbsolutePath()) && fileOrDirectory.isDirectory()) {
|
||||
File[] children = fileOrDirectory.listFiles();
|
||||
|
||||
if (children != null) {
|
||||
for (File child : children) {
|
||||
deleteFolder(child);
|
||||
} else {
|
||||
child.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!fileOrDirectory.delete()) {
|
||||
throw new RuntimeException("Unable to delete " + (fileOrDirectory.isDirectory() ? "directory " : "file ") + fileOrDirectory.getAbsolutePath());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue