Delete a directory and its contents. WARNING: Java APIs do not let us distinguish directories from symbolic links to directories. Consequently, if the directory contains symbolic links to directories, we will attempt to delete the contents of pointed-to directories. @param file File or director
(File file)
| 127 | * @throws IOException IOException |
| 128 | */ |
| 129 | public static void dumbDelete(File file) throws IOException { |
| 130 | Stack<File> filesStack = new Stack<>(); |
| 131 | filesStack.push(file); |
| 132 | ArrayList<File> dirsToDelete = new ArrayList<>(); |
| 133 | while (!filesStack.isEmpty()) { |
| 134 | File currentFile = filesStack.pop(); |
| 135 | if (!currentFile.isDirectory()) { |
| 136 | deleteOrThrow(currentFile); |
| 137 | continue; |
| 138 | } |
| 139 | dirsToDelete.add(currentFile); |
| 140 | File[] fileList = currentFile.listFiles(); |
| 141 | if (fileList == null) { |
| 142 | continue; |
| 143 | } |
| 144 | for (File entry : fileList) { |
| 145 | filesStack.push(entry); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | for (int i = dirsToDelete.size() - 1; i >= 0; --i) { |
| 150 | deleteOrThrow(dirsToDelete.get(i)); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Encapsulate Lollipop-specific calls into an independent class so we don't fail preverification |
no test coverage detected