Changeset 29107 in osm for applications/editors
- Timestamp:
- 2012-12-22T17:02:35+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java
r28696 r29107 60 60 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler; 61 61 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation; 62 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils; 62 63 import org.openstreetmap.josm.tools.Pair; 63 64 … … 95 96 // Add download task 96 97 Main.main.menu.openLocation.addDownloadTaskClass(DownloadDataTask.class); 98 // Delete previous temp dirs if any (old plugin versions did not remove them correctly) 99 OdUtils.deletePreviousTempDirs(); 97 100 } 98 101 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipReader.java
r28696 r29107 49 49 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.OdsReader; 50 50 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.XlsReader; 51 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils; 51 52 52 53 public class ZipReader extends AbstractReader implements OdConstants { … … 75 76 } 76 77 77 private static final File createTempDir() throws IOException {78 final File temp = File.createTempFile("josm_opendata_temp_", Long.toString(System.nanoTime()));79 80 if (!temp.delete()) {81 throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());82 }83 84 if (!temp.mkdir()) {85 throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());86 }87 88 return temp;89 }90 91 private static final void deleteDir(File dir) {92 for (File file : dir.listFiles()) {93 file.delete();94 }95 dir.delete();96 }97 98 78 public DataSet parseDoc(final ProgressMonitor progressMonitor) throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 99 79 100 final File temp = createTempDir();80 final File temp = OdUtils.createTempDir(); 101 81 final List<File> candidates = new ArrayList<File>(); 102 82 … … 217 197 System.err.println(e.getMessage()); 218 198 } finally { 219 199 OdUtils.deleteDir(temp); 220 200 if (progressMonitor != null) { 221 201 progressMonitor.finishTask(); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/util/OdUtils.java
r28364 r29107 16 16 package org.openstreetmap.josm.plugins.opendata.core.util; 17 17 18 import java.io.File; 19 import java.io.FilenameFilter; 20 import java.io.IOException; 18 21 import java.util.ArrayList; 19 22 import java.util.List; … … 31 34 public abstract class OdUtils { 32 35 36 private static final String TEMP_DIR_PREFIX = "josm_opendata_temp_"; 37 33 38 public static final boolean isMultipolygon(OsmPrimitive p) { 34 39 return p instanceof Relation && ((Relation) p).isMultipolygon(); … … 80 85 return degree + convertMinuteSecond(minute, second); 81 86 } 87 88 public static final File createTempDir() throws IOException { 89 final File temp = File.createTempFile(TEMP_DIR_PREFIX, Long.toString(System.nanoTime())); 90 91 if (!temp.delete()) { 92 throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); 93 } 94 95 if (!temp.mkdir()) { 96 throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); 97 } 98 99 return temp; 100 } 101 102 public static final void deleteDir(File dir) { 103 for (File file : dir.listFiles()) { 104 if (!file.delete()) { 105 file.deleteOnExit(); 106 } 107 } 108 if (!dir.delete()) { 109 dir.deleteOnExit(); 110 } 111 } 112 113 public static final void deletePreviousTempDirs() { 114 File tmpDir = new File(System.getProperty("java.io.tmpdir")); 115 if (tmpDir.exists() && tmpDir.isDirectory()) { 116 for (File dir : tmpDir.listFiles(new FilenameFilter() { 117 @Override 118 public boolean accept(File dir, String name) { 119 return name.startsWith(TEMP_DIR_PREFIX); 120 } 121 })) { 122 deleteDir(dir); 123 } 124 } 125 } 82 126 }
Note:
See TracChangeset
for help on using the changeset viewer.