Ignore:
Timestamp:
2018-04-19T20:37:16+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16204 - Allow to start and close JOSM in WebStart sandbox mode (where every external access is denied). This was very useful to reproduce some very tricky bugs that occured in real life but were almost impossible to diagnose.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java

    r13114 r13647  
    44import static org.openstreetmap.josm.tools.I18n.marktr;
    55import static org.openstreetmap.josm.tools.I18n.tr;
     6import static org.openstreetmap.josm.tools.Utils.getSystemProperty;
    67
    78import java.io.BufferedReader;
     
    383384    public List<File> getUnsavedLayersFiles() {
    384385        List<File> result = new ArrayList<>();
    385         File[] files = autosaveDir.listFiles((FileFilter)
    386                 pathname -> OsmImporter.FILE_FILTER.accept(pathname) || NoteImporter.FILE_FILTER.accept(pathname));
    387         if (files == null)
    388             return result;
    389         for (File file: files) {
    390             if (file.isFile()) {
    391                 boolean skipFile = false;
    392                 File pidFile = getPidFile(file);
    393                 if (pidFile.exists()) {
    394                     try (BufferedReader reader = Files.newBufferedReader(pidFile.toPath(), StandardCharsets.UTF_8)) {
    395                         String jvmId = reader.readLine();
    396                         if (jvmId != null) {
    397                             String pid = jvmId.split("@")[0];
    398                             skipFile = jvmPerfDataFileExists(pid);
     386        try {
     387            File[] files = autosaveDir.listFiles((FileFilter)
     388                    pathname -> OsmImporter.FILE_FILTER.accept(pathname) || NoteImporter.FILE_FILTER.accept(pathname));
     389            if (files == null)
     390                return result;
     391            for (File file: files) {
     392                if (file.isFile()) {
     393                    boolean skipFile = false;
     394                    File pidFile = getPidFile(file);
     395                    if (pidFile.exists()) {
     396                        try (BufferedReader reader = Files.newBufferedReader(pidFile.toPath(), StandardCharsets.UTF_8)) {
     397                            String jvmId = reader.readLine();
     398                            if (jvmId != null) {
     399                                String pid = jvmId.split("@")[0];
     400                                skipFile = jvmPerfDataFileExists(pid);
     401                            }
     402                        } catch (IOException | SecurityException t) {
     403                            Logging.error(t);
    399404                        }
    400                     } catch (IOException | SecurityException t) {
    401                         Logging.error(t);
    402405                    }
    403                 }
    404                 if (!skipFile) {
    405                     result.add(file);
    406                 }
    407             }
     406                    if (!skipFile) {
     407                        result.add(file);
     408                    }
     409                }
     410            }
     411        } catch (SecurityException e) {
     412            Logging.log(Logging.LEVEL_ERROR, "Unable to list unsaved layers files", e);
    408413        }
    409414        return result;
     
    411416
    412417    private static boolean jvmPerfDataFileExists(final String jvmId) {
    413         File jvmDir = new File(System.getProperty("java.io.tmpdir") + File.separator + "hsperfdata_" + System.getProperty("user.name"));
     418        File jvmDir = new File(getSystemProperty("java.io.tmpdir") + File.separator + "hsperfdata_" + getSystemProperty("user.name"));
    414419        if (jvmDir.exists() && jvmDir.canRead()) {
    415420            File[] files = jvmDir.listFiles((FileFilter) file -> file.getName().equals(jvmId) && file.isFile());
Note: See TracChangeset for help on using the changeset viewer.