- Timestamp:
- 2012-11-04T13:28:58+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r5459 r5566 22 22 * @since 32 23 23 */ 24 public class ExtensionFileFilter extends FileFilter {24 public class ExtensionFileFilter extends FileFilter implements java.io.FileFilter { 25 25 26 26 /** -
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r5512 r5566 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.BufferedReader; 6 7 import java.io.File; 8 import java.io.FileFilter; 9 import java.io.FileInputStream; 7 10 import java.io.IOException; 11 import java.io.InputStreamReader; 12 import java.io.PrintStream; 13 import java.lang.management.ManagementFactory; 8 14 import java.util.ArrayList; 9 15 import java.util.Date; … … 31 37 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 32 38 import org.openstreetmap.josm.io.OsmExporter; 39 import org.openstreetmap.josm.io.OsmImporter; 33 40 34 41 /** … … 141 148 Date now = new Date(); 142 149 while (true) { 143 File result = new File(autosaveDir, String.format("%1$s_%2$tY%2$tm%2$td_%2$tH%2$tM%3$s.osm", layer.layerFileName, now, index == 0?"":"_" + index)); 150 String filename = String.format("%1$s_%2$tY%2$tm%2$td_%2$tH%2$tM%3$s", layer.layerFileName, now, index == 0?"":"_" + index); 151 File result = new File(autosaveDir, filename+".osm"); 144 152 try { 145 if (result.createNewFile()) 153 if (result.createNewFile()) { 154 try { 155 File pidFile = new File(autosaveDir, filename+".pid"); 156 PrintStream ps = new PrintStream(pidFile); 157 ps.println(ManagementFactory.getRuntimeMXBean().getName()); 158 ps.close(); 159 } catch (Throwable t) { 160 System.err.println(t.getMessage()); 161 } 146 162 return result; 147 else {163 } else { 148 164 System.out.println(tr("Unable to create file {0}, other filename will be used", result.getAbsolutePath())); 149 165 if (index > PROP_INDEX_LIMIT.get()) … … 174 190 if (!oldFile.delete()) { 175 191 System.out.println(tr("Unable to delete old backup file {0}", oldFile.getAbsolutePath())); 192 } else { 193 getPidFile(oldFile).delete(); 176 194 } 177 195 } … … 233 251 } 234 252 for (File file: info.backupFiles) { 235 file.delete(); 253 if (file.delete()) { 254 getPidFile(file).delete(); 255 } 236 256 } 237 257 } catch (IOException e) { … … 251 271 } 252 272 273 private final File getPidFile(File osmFile) { 274 return new File(autosaveDir, osmFile.getName().replaceFirst("[.][^.]+$", ".pid")); 275 } 276 277 /** 278 * Replies the list of .osm files still present in autosave dir, that are not currently managed by another instance of JOSM. 279 * These files are hence unsaved layers from an old instance of JOSM that crashed and may be recovered by this instance. 280 * @return The list of .osm files still present in autosave dir, that are not currently managed by another instance of JOSM 281 */ 253 282 public List<File> getUnsavedLayersFiles() { 254 283 List<File> result = new ArrayList<File>(); 255 File[] files = autosaveDir.listFiles( );284 File[] files = autosaveDir.listFiles(OsmImporter.FILE_FILTER); 256 285 if (files == null) 257 286 return result; 258 287 for (File file: files) { 259 288 if (file.isFile()) { 260 result.add(file); 289 boolean skipFile = false; 290 File pidFile = getPidFile(file); 291 if (pidFile.exists()) { 292 try { 293 BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(pidFile))); 294 try { 295 String jvmId = reader.readLine(); 296 String pid = jvmId.split("@")[0]; 297 skipFile = jvmPerfDataFileExists(pid); 298 } catch (Throwable t) { 299 System.err.println(t.getClass()+":"+t.getMessage()); 300 } finally { 301 reader.close(); 302 } 303 } catch (Throwable t) { 304 System.err.println(t.getClass()+":"+t.getMessage()); 305 } 306 } 307 if (!skipFile) { 308 result.add(file); 309 } 261 310 } 262 311 } 263 312 return result; 313 } 314 315 private boolean jvmPerfDataFileExists(final String jvmId) { 316 File jvmDir = new File(System.getProperty("java.io.tmpdir") + File.separator + "hsperfdata_" + System.getProperty("user.name")); 317 if (jvmDir.exists() && jvmDir.canRead()) { 318 File[] files = jvmDir.listFiles(new FileFilter() { 319 @Override 320 public boolean accept(File file) { 321 return file.getName().equals(jvmId) && file.isFile(); 322 } 323 }); 324 return files != null && files.length == 1; 325 } 326 return false; 264 327 } 265 328 … … 287 350 private void moveToDeletedLayersFolder(File f) { 288 351 File backupFile = new File(deletedLayersDir, f.getName()); 289 352 File pidFile = getPidFile(f); 353 290 354 if (backupFile.exists()) { 291 355 deletedLayers.remove(backupFile); … … 296 360 if (f.renameTo(backupFile)) { 297 361 deletedLayers.add(backupFile); 362 pidFile.delete(); 298 363 } else { 299 364 System.err.println(String.format("Warning: Could not move autosaved file %s to %s folder", f.getName(), deletedLayersDir.getName())); … … 301 366 if (!f.delete()) { 302 367 System.err.println(String.format("Warning: Could not delete backup file %s", f)); 368 } else { 369 pidFile.delete(); 303 370 } 304 371 }
Note:
See TracChangeset
for help on using the changeset viewer.