Changeset 7835 in josm


Ignore:
Timestamp:
2014-12-19T16:15:43+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #10026 - migrate preferences and plugins from old ~/.josm directory to new directories on OSX, then delete old directory

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r7834 r7835  
    8080     *  <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li>
    8181     *  <li>{@code josmdir://SOME/FILE} file inside josm user data directory (since r7058)</li></ul>
    82      *  <li>{@code josmplugindir://SOME/FILE} file inside josm plugin directory (since r7832)</li></ul>
     82     *  <li>{@code josmplugindir://SOME/FILE} file inside josm plugin directory (since r7834)</li></ul>
    8383     */
    8484    public CachedFile(String name) {
     
    9494     *  <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li>
    9595     *  <li>{@code josmdir://SOME/FILE} file inside josm user data directory (since r7058)</li></ul>
    96      *  <li>{@code josmplugindir://SOME/FILE} file inside josm plugin directory (since r7832)</li></ul>
     96     *  <li>{@code josmplugindir://SOME/FILE} file inside josm plugin directory (since r7834)</li></ul>
    9797     * @return this object
    9898     */
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r7834 r7835  
    3838        // They just insist on painting themselves...
    3939        Preferences.updateSystemProperty("apple.laf.useScreenMenuBar", "true");
     40        migrateOldDirectory();
    4041    }
    4142
     
    338339        return new File(System.getProperty("user.home")+"/Library/Application Support", "JOSM");
    339340    }
     341
     342    /***
     343     * Prior to r7834, JOSM used the same Unix directory ~/.josm for all local files (preferences,
     344     * caches, user data). This method migrates the existing preferences and plugins to new directories
     345     * if applicable. Old directory, including cache, is deleted.
     346     * Method to remove end of 2015.
     347     * @since 7835
     348     */
     349    public static void migrateOldDirectory() {
     350        File oldDir = new File(System.getProperty("user.home"), ".josm");
     351        if (oldDir.exists()) {
     352            boolean error = false;
     353
     354            File oldPref = new File(oldDir, "preferences.xml");
     355            if (oldPref.exists()) {
     356                File newPref = Main.pref.getPreferenceFile();
     357                if (!newPref.exists()) {
     358                    try {
     359                        Main.pref.getPreferencesDirectory().mkdirs();
     360                        Main.info("Copying old preferences file to new location");
     361                        Utils.copyFile(oldPref, newPref);
     362                        if (!oldPref.delete()) {
     363                            Main.warn("Unable to delete old preferences file: "+oldPref.getPath());
     364                        }
     365                    } catch (IOException e) {
     366                        Main.error(e);
     367                        error = true;
     368                    }
     369                }
     370            }
     371
     372            File oldPlugins = new File(oldDir, "plugins");
     373            if (oldPlugins.exists()) {
     374                File newPlugins = Main.pref.getPluginsDirectory();
     375                if (!newPlugins.exists()) {
     376                    try {
     377                        Utils.copyDirectory(oldPlugins, newPlugins);
     378                    } catch (IOException e) {
     379                        Main.error(e);
     380                        error = true;
     381                    }
     382                }
     383            }
     384
     385            if (!error) {
     386                Main.info("Deleting old preferences directory");
     387                if (!Utils.deleteDirectory(oldDir)) {
     388                    Main.warn("Unable to delete old preferences directory");
     389                }
     390            }
     391        }
     392    }
    340393}
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r7556 r7835  
    324324
    325325    /**
    326      * Simple file copy function that will overwrite the target file.<br>
     326     * Simple file copy function that will overwrite the target file.
    327327     * @param in The source file
    328328     * @param out The destination file
     
    332332     * @since 7003
    333333     */
    334     public static Path copyFile(File in, File out) throws IOException, IllegalArgumentException {
     334    public static Path copyFile(File in, File out) throws IOException {
    335335        CheckParameterUtil.ensureParameterNotNull(in, "in");
    336336        CheckParameterUtil.ensureParameterNotNull(out, "out");
    337337        return Files.copy(in.toPath(), out.toPath(), StandardCopyOption.REPLACE_EXISTING);
     338    }
     339
     340    /**
     341     * Recursive directory copy function
     342     * @param in The source directory
     343     * @param out The destination directory
     344     * @throws IOException If any I/O error ooccurs
     345     * @throws IllegalArgumentException If {@code in} or {@code out} is {@code null}
     346     * @since 7835
     347     */
     348    public static void copyDirectory(File in, File out) throws IOException {
     349        CheckParameterUtil.ensureParameterNotNull(in, "in");
     350        CheckParameterUtil.ensureParameterNotNull(out, "out");
     351        if (!out.exists() && !out.mkdirs()) {
     352            Main.warn("Unable to create directory "+out.getPath());
     353        }
     354        for (File f : in.listFiles()) {
     355            File target = new File(out, f.getName());
     356            if (f.isDirectory()) {
     357                copyDirectory(f, target);
     358            } else {
     359                copyFile(f, target);
     360            }
     361        }
    338362    }
    339363
     
    349373    }
    350374
     375    /**
     376     * Deletes a directory recursively.
     377     * @param path The directory to delete
     378     * @return  <code>true</code> if and only if the file or directory is
     379     *          successfully deleted; <code>false</code> otherwise
     380     */
    351381    public static boolean deleteDirectory(File path) {
    352382        if( path.exists() ) {
     
    355385                if (file.isDirectory()) {
    356386                    deleteDirectory(file);
    357                 } else {
    358                     file.delete();
     387                } else if (!file.delete()) {
     388                    Main.warn("Unable to delete file: "+file.getPath());
    359389                }
    360390            }
    361391        }
    362         return( path.delete() );
     392        return path.delete();
    363393    }
    364394
Note: See TracChangeset for help on using the changeset viewer.