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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.