public static void renameOrMoveByCopying(File from, File to) throws IOException { deleteFileIfExists(to); boolean renameFailed = !from.renameTo(to); if (renameFailed) { copyFile(from, to); boolean deleteFromFailed = !from.delete(); if (deleteFromFailed) { Timber.e("Unable to delete source file after copying to destination!"); } } }
private void moveTemporaryFile(File tempFile, String messagePartId) throws IOException { File destinationFile = localStore.getAttachmentFile(messagePartId); FileHelper.renameOrMoveByCopying(tempFile, destinationFile); }
private void checkSanitization(String expected, String actual) { assertEquals(expected, FileHelper.sanitizeFilename(actual)); } }
move(fromDir, toDir); for (File file : files) { if (file.isDirectory()) { moveRecursive(file, new File(toDir, file.getName())); if (!file.delete()) { Timber.d("Unable to delete file: %s", toDir.getAbsolutePath()); Timber.w("cannot rename %s to %s - moving instead", file.getAbsolutePath(), target.getAbsolutePath()); move(file, target);
public static boolean move(final File from, final File to) { if (to.exists()) { if (!to.delete()) { Timber.d("Unable to delete file: %s", to.getAbsolutePath()); } } if (!to.getParentFile().mkdirs()) { Timber.d("Unable to make directories: %s", to.getParentFile().getAbsolutePath()); } try { copyFile(from, to); boolean deleteFromFailed = !from.delete(); if (deleteFromFailed) { Timber.e("Unable to delete source file after copying to destination!"); } return true; } catch (Exception e) { Timber.w(e, "cannot move %s to %s", from.getAbsolutePath(), to.getAbsolutePath()); return false; } }
FileHelper.moveRecursive(oldDatabase, storageManager.getDatabase(uUid, newProviderId)); FileHelper.moveRecursive(storageManager.getAttachmentDirectory(uUid, oldProviderId), storageManager.getAttachmentDirectory(uUid, newProviderId));