--- core/src/classpath/java/java/io/VMFile.java +++ core/src/classpath/java/java/io/VMFile.java @@ -88,7 +88,22 @@ */ static boolean renameTo(String targetpath, String destpath) { try{ - //todo improve it + targetPath = getNormalizedPath(targetPath); + destpath = getNormalizedPath(destpath); + /* + * Check if the destination file exists, if it does fail + */ + if(VMIOUtils.getAPI().fileExists(destpath)) + return false; + /* + * If source and dest have the same parent, simply rename the file + */ + if(targetpath.substring(0, targetpath.lastIndexOf("/")).compareTo(destpath.substring(0, destpath.lastIndexOf("/"))) == 0) { + /* Same parent, let's rename */ + return new File(targetpath).renameTo(destpath); + } + /* Different parents, determine if they are on the same file system */ + /* NOTE: Could not figure out way to determine if on different filesystem */ FileInputStream fis = new FileInputStream(targetpath); FileOutputStream fos = new FileOutputStream(destpath); byte[] buf = new byte[64*1024];