■ ■ ■ ■ ■ ■
commons-utils/src/main/java/io/onedev/commons/utils/FileUtils.java
| skipped 201 lines |
202 | 202 | | } |
203 | 203 | | } |
204 | 204 | | |
| 205 | + | public static void deleteDir(File dir, int retries) { |
| 206 | + | int retried = 0; |
| 207 | + | while (dir.exists()) { |
| 208 | + | try { |
| 209 | + | deleteDir(dir); |
| 210 | + | break; |
| 211 | + | } catch (Exception e) { |
| 212 | + | if (retried++ < retries) { |
| 213 | + | logger.error("Error deleting directory '" + dir.getAbsolutePath() + "', will retry later...", e); |
| 214 | + | try { |
| 215 | + | Thread.sleep(5000); |
| 216 | + | } catch (InterruptedException e2) { |
| 217 | + | } |
| 218 | + | } else { |
| 219 | + | throw e; |
| 220 | + | } |
| 221 | + | } |
| 222 | + | } |
| 223 | + | } |
| 224 | + | |
205 | 225 | | public static void deleteFile(File file) { |
206 | 226 | | int maxTries = 10; |
207 | 227 | | int numTries = 1; |
| skipped 44 lines |
252 | 272 | | } |
253 | 273 | | |
254 | 274 | | public static File createTempDir(String prefix) { |
255 | | - | File temp; |
256 | | - | |
257 | | - | try { |
258 | | - | temp = File.createTempFile(prefix, ""); |
259 | | - | } catch (IOException e) { |
260 | | - | throw new RuntimeException(e); |
261 | | - | } |
262 | | - | |
263 | | - | if (!temp.delete()) |
264 | | - | throw new RuntimeException("Could not delete temp file: " + temp.getAbsolutePath()); |
265 | | - | |
266 | | - | if (!temp.mkdirs()) |
267 | | - | throw new RuntimeException("Could not create temp directory: " + temp.getAbsolutePath()); |
268 | | - | |
269 | | - | return temp; |
| 275 | + | return Bootstrap.createTempDir(prefix); |
270 | 276 | | } |
271 | 277 | | |
272 | 278 | | public static File createTempDir() { |
| skipped 311 lines |