Changeset 9296 in josm
- Timestamp:
- 2016-01-04T01:06:23+01:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java
r9280 r9296 163 163 } finally { 164 164 if (tempFile) { 165 if (!file.delete()) { 166 file.deleteOnExit(); 167 } 165 Utils.deleteFile(file); 168 166 file = null; 169 167 } -
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r8870 r9296 2 2 package org.openstreetmap.josm.data; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 40 41 import org.openstreetmap.josm.io.OsmExporter; 41 42 import org.openstreetmap.josm.io.OsmImporter; 43 import org.openstreetmap.josm.tools.Utils; 42 44 43 45 /** … … 194 196 while (info.backupFiles.size() > PROP_FILES_PER_LAYER.get()) { 195 197 File oldFile = info.backupFiles.remove(); 196 if (!oldFile.delete()) { 197 Main.warn(tr("Unable to delete old backup file {0}", oldFile.getAbsolutePath())); 198 } else { 199 File pidFile = getPidFile(oldFile); 200 if (!pidFile.delete()) { 201 Main.warn(tr("Unable to delete old backup file {0}", pidFile.getAbsolutePath())); 202 } 198 if (Utils.deleteFile(oldFile, marktr("Unable to delete old backup file {0}"))) { 199 Utils.deleteFile(getPidFile(oldFile), marktr("Unable to delete old backup file {0}")); 203 200 } 204 201 } … … 273 270 } 274 271 for (File file: info.backupFiles) { 275 if ( file.delete()) {276 getPidFile(file).delete();272 if (Utils.deleteFile(file)) { 273 Utils.deleteFile(getPidFile(file)); 277 274 } 278 275 } … … 369 366 if (backupFile.exists()) { 370 367 deletedLayers.remove(backupFile); 371 if (!backupFile.delete()) { 372 Main.warn(String.format("Could not delete old backup file %s", backupFile)); 373 } 368 Utils.deleteFile(backupFile, marktr("Unable to delete old backup file {0}")); 374 369 } 375 370 if (f.renameTo(backupFile)) { 376 371 deletedLayers.add(backupFile); 377 pidFile.delete();372 Utils.deleteFile(pidFile); 378 373 } else { 379 374 Main.warn(String.format("Could not move autosaved file %s to %s folder", f.getName(), deletedLayersDir.getName())); 380 375 // we cannot move to deleted folder, so just try to delete it directly 381 if (!f.delete()) { 382 Main.warn(String.format("Could not delete backup file %s", f)); 383 } else if (!pidFile.delete()) { 384 Main.warn(String.format("Could not delete PID file %s", pidFile)); 376 if (Utils.deleteFile(f, marktr("Unable to delete backup file {0}"))) { 377 Utils.deleteFile(pidFile, marktr("Unable to delete PID file {0}")); 385 378 } 386 379 } … … 390 383 break; 391 384 } 392 if (!next.delete()) { 393 Main.warn(String.format("Could not delete archived backup file %s", next)); 394 } 385 Utils.deleteFile(next, marktr("Unable to delete archived backup file {0}")); 395 386 } 396 387 } -
trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
r9243 r9296 314 314 } 315 315 } 316 try { 317 f.delete(); 318 } catch (Exception e) { 319 log("Warning: Can not delete file "+f.getPath()+": "+e.getMessage()); 316 if (!Utils.deleteFile(f)) { 317 log("Warning: Can not delete file "+f.getPath()); 320 318 } 321 319 } -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r9246 r9296 2 2 package org.openstreetmap.josm.data; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 872 873 File tmpFile = new File(prefFile + "_tmp"); 873 874 Utils.copyFile(tmpFile, prefFile); 874 if (!tmpFile.delete()) { 875 Main.warn(tr("Unable to delete temporary file {0}", tmpFile.getAbsolutePath())); 876 } 875 Utils.deleteFile(tmpFile, marktr("Unable to delete temporary file {0}")); 877 876 878 877 setCorrectPermissions(prefFile); -
trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java
r9280 r9296 23 23 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 24 24 import org.openstreetmap.josm.tools.HttpClient; 25 import org.openstreetmap.josm.tools.Utils; 25 26 import org.xml.sax.SAXException; 26 27 … … 132 133 Main.info(tr("Unpacking {0} into {1}", file.getAbsolutePath(), file.getParent())); 133 134 unzipFileRecursively(file, file.getParent()); 134 file.delete();135 Utils.deleteFile(file); 135 136 } 136 137 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r9270 r9296 666 666 } 667 667 668 if ( toDelete.getFile().delete()) {668 if (Utils.deleteFile(toDelete.getFile())) { 669 669 Main.info("File "+toDelete.getFile()+" deleted. "); 670 670 } else { -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r9280 r9296 335 335 File lfile = new File(localPath.get(1)); 336 336 if (lfile.exists()) { 337 lfile.delete();337 Utils.deleteFile(lfile); 338 338 } 339 339 } -
trunk/src/org/openstreetmap/josm/io/OsmExporter.java
r8846 r9296 93 93 if (noBackup || !Main.pref.getBoolean("save.keepbackup", false)) { 94 94 if (tmpFile != null) { 95 tmpFile.delete();95 Utils.deleteFile(tmpFile); 96 96 } 97 97 } -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r9171 r9296 326 326 // remove old stuff or whole update process is broken 327 327 for (File file: siteCacheFiles) { 328 file.delete();328 Utils.deleteFile(file); 329 329 } 330 330 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r8923 r9296 2 2 package org.openstreetmap.josm.tools; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 366 367 Main.info("Copying old preferences file to new location"); 367 368 Utils.copyFile(oldPref, newPref); 368 if (!oldPref.delete()) { 369 Main.warn("Unable to delete old preferences file: "+oldPref.getPath()); 370 } 369 Utils.deleteFile(oldPref, marktr("Unable to delete old preferences file {0}")); 371 370 } catch (IOException e) { 372 371 Main.error(e); -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r9073 r9296 190 190 public boolean rename(File from, File to) { 191 191 if (to.exists()) 192 to.delete();192 Utils.deleteFile(to); 193 193 return from.renameTo(to); 194 194 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9280 r9296 2 2 package org.openstreetmap.josm.tools; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static org.openstreetmap.josm.tools.I18n.trn; … … 446 447 if (file.isDirectory()) { 447 448 deleteDirectory(file); 448 } else if (!file.delete()){449 Main.warn("Unable to delete file: "+file.getPath());449 } else { 450 deleteFile(file); 450 451 } 451 452 } … … 453 454 } 454 455 return path.delete(); 456 } 457 458 /** 459 * Deletes a file and log a default warning if the deletion fails. 460 * @param file file to delete 461 * and must contain a single parameter <code>{0}</code> for the file path 462 * @return {@code true} if and only if the file is successfully deleted; {@code false} otherwise 463 * @since XXXX 464 */ 465 public static boolean deleteFile(File file) { 466 return deleteFile(file, marktr("Unable to delete file {0}")); 467 } 468 469 /** 470 * Deletes a file and log a configurable warning if the deletion fails. 471 * @param file file to delete 472 * @param warnMsg warning message. It will be translated with {@code tr()} 473 * and must contain a single parameter <code>{0}</code> for the file path 474 * @return {@code true} if and only if the file is successfully deleted; {@code false} otherwise 475 * @since XXXX 476 */ 477 public static boolean deleteFile(File file, String warnMsg) { 478 boolean result = file.delete(); 479 if (!result) { 480 Main.warn(tr(warnMsg, file.getPath())); 481 } 482 return result; 455 483 } 456 484 -
trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java
r8876 r9296 28 28 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 29 29 import org.openstreetmap.josm.tools.MultiMap; 30 import org.openstreetmap.josm.tools.Utils; 30 31 31 32 /** … … 108 109 } finally { 109 110 if (file.exists()) { 110 file.delete();111 Utils.deleteFile(file); 111 112 } 112 113 }
Note:
See TracChangeset
for help on using the changeset viewer.