public static void mv(String src, String dest) { try { FileUtils.moveFile(new File(src), new File(dest)); } catch (IOException ignored) { } }
public static void mv(String src, String dest) { try { FileUtils.moveFile(new File(src), new File(dest)); } catch (IOException ignored) { } }
public static void mv(String src, String dest) { try { FileUtils.moveFile(new File(src), new File(dest)); } catch (Exception ignored) { } } }
/** * Deletes the destination file if it exists then calls org.apache.commons moveFile. * @param srcFile * @param destFile */ public static void moveFileWithOverwrite(File srcFile, File destFile) throws IOException { if (destFile.exists()) { org.apache.commons.io.FileUtils.deleteQuietly(destFile); } org.apache.commons.io.FileUtils.moveFile(srcFile, destFile); }
public File createTmpMetaFile() throws IOException { File metafile = File.createTempFile("meta", ".json"); File destFile = new File(metafile.getParent(), "meta.json"); if (destFile.exists()) destFile.delete(); FileUtils.moveFile(metafile, destFile); return destFile; }
throw new IOException("Destination '" + destDir + "' is not a directory"); moveFile(srcFile, new File(destDir, srcFile.getName()));
private void renameJarWithOldNamingConvention(File oldJar) throws IOException { Matcher matcher = oldNamingPattern.matcher(oldJar.getName()); if (!matcher.matches()) { throw new IllegalArgumentException("The given jar " + oldJar.getCanonicalPath() + " does not match the old naming convention"); } String unversionedJarNameWithoutExtension = matcher.group(1); String jarVersion = matcher.group(2); String newJarName = unversionedJarNameWithoutExtension + ".v" + jarVersion + ".jar"; File newJar = new File(this.deployDirectory, newJarName); logger.debug("Renaming deployed jar from {} to {}", oldJar.getCanonicalPath(), newJar.getCanonicalPath()); FileUtils.moveFile(oldJar, newJar); }
@Override void createCachedFile(ArtifactFolder artifactFolder) throws IOException { File originalFolder = artifactFolder.getRootFolder(); File cachedZip = cachedFile(artifactFolder); File cachedTempZip = zipToTempFile(cachedZip); cachedTempZip.getParentFile().mkdirs(); try { zipUtil.zip(originalFolder, cachedTempZip, Deflater.DEFAULT_COMPRESSION); } catch (IOException e) { cachedTempZip.delete(); throw e; } FileUtils.moveFile(cachedTempZip, cachedZip); }
public void moveConsoleArtifacts(LocatableEntity locatableEntity) { try { File from = chooser.temporaryConsoleFile(locatableEntity); // Job cancellation skips temporary file creation. Force create one if it does not exist. FileUtils.touch(from); File to = consoleLogArtifact(locatableEntity); FileUtils.moveFile(from, to); } catch (IOException | IllegalArtifactLocationException e) { throw new RuntimeException(e); } } }
private static State saveTmpFile(File tmpFile, String path) { State state = null; File targetFile = new File(path); if (targetFile.canWrite()) { return new BaseState(false, AppInfo.PERMISSION_DENIED); } try { FileUtils.moveFile(tmpFile, targetFile); } catch (IOException e) { return new BaseState(false, AppInfo.IO_ERROR); } state = new BaseState(true); state.putInfo("size", targetFile.length()); state.putInfo("title", targetFile.getName()); return state; }
private FileAndMd5 moveToCache(String pluginKey, FileAndMd5 jar) throws IOException { File jarInCache = new File(userHome, "cache/" + jar.md5 + "/sonar-" + pluginKey + "-plugin.jar"); moveFile(jar.file, jarInCache); return new FileAndMd5(jarInCache, jar.md5); }
@Test public void testMoveFile_CopyDelete() throws Exception { final File destination = new File(getTestDirectory(), "move2.txt"); final File src = new File(testFile1.getAbsolutePath()) { private static final long serialVersionUID = 1L; // Force renameTo to fail, as if destination is on another // filesystem @Override public boolean renameTo(final File f) { return false; } }; FileUtils.moveFile(src, destination); assertTrue("Check Exist", destination.exists()); assertTrue("Original deleted", !src.exists()); }
@Test public void testMoveFile_Rename() throws Exception { final File destination = new File(getTestDirectory(), "move1.txt"); FileUtils.moveFile(testFile1, destination); assertTrue("Check Exist", destination.exists()); assertTrue("Original deleted", !testFile1.exists()); }
@Override public void move(RemoteFile sourceFile, RemoteFile targetFile) throws StorageException { connect(); File sourceRemoteFile = getRemoteFile(sourceFile); File targetRemoteFile = getRemoteFile(targetFile); if (!sourceRemoteFile.exists()) { throw new StorageMoveException("Unable to move file " + sourceFile + " because it does not exist."); } try { FileUtils.moveFile(sourceRemoteFile, targetRemoteFile); } catch (IOException ex) { throw new StorageException("Unable to move file " + sourceRemoteFile + " to destination " + targetRemoteFile, ex); } }
@Test public void testMoveFile_Errors() throws Exception { try { FileUtils.moveFile(null, new File("foo")); fail("Expected NullPointerException when source is null"); } catch (final NullPointerException e) { FileUtils.moveFile(new File("foo"), null); fail("Expected NullPointerException when destination is null"); } catch (final NullPointerException e) { FileUtils.moveFile(new File("nonexistant"), new File("foo")); fail("Expected FileNotFoundException for source"); } catch (final FileNotFoundException e) { FileUtils.moveFile(getTestDirectory(), new File("foo")); fail("Expected IOException when source is a directory"); } catch (final IOException e) { FileUtils.moveFile(testSourceFile, testDestFile); fail("Expected FileExistsException when dest already exists"); } catch (final FileExistsException e) {
@Test public void testMoveFile_CopyDelete_Failed() throws Exception { final File destination = new File(getTestDirectory(), "move3.txt"); final File src = new File(testFile1.getAbsolutePath()) { private static final long serialVersionUID = 1L; // Force renameTo to fail, as if destination is on another // filesystem @Override public boolean renameTo(final File f) { return false; } // Force delete failure @Override public boolean delete() { return false; } }; try { FileUtils.moveFile(src, destination); fail("move should have failed as src has not been deleted"); } catch (final IOException e) { // exepected assertTrue("Check Rollback", !destination.exists()); assertTrue("Original exists", src.exists()); } }
public void moveFile(String fileFrom, String fileTo) throws Exception { File fromLocalFile = getLocalFile(fileFrom); File toLocalFile = getLocalFile(fileTo); try { if (fromLocalFile.isDirectory()) { FileUtils.moveDirectory(fromLocalFile, toLocalFile); } else { FileUtils.moveFile(fromLocalFile, toLocalFile); } } catch (Exception e) { throw new Exception("Move failed: " + fileFrom + " --> " + fileTo, e); } }
@Test public void shouldNotifyRemoveEventBeforeAddEventInCaseOfFileRename() throws Exception { monitor.addPluginJarChangeListener(changeListener); monitor.start(); copyPluginToThePluginDirectory(bundledPluginDir, "descriptor-aware-test-plugin-1.jar"); waitUntilNextRun(monitor); PluginFileDetails orgFile = pluginFileDetails(bundledPluginDir, "descriptor-aware-test-plugin-1.jar", true); verify(changeListener).pluginJarAdded(orgFile); PluginFileDetails newFile = pluginFileDetails(bundledPluginDir, "descriptor-aware-test-plugin-1-new.jar", true); FileUtils.moveFile(orgFile.file(), newFile.file()); waitUntilNextRun(monitor); InOrder inOrder = inOrder(changeListener); inOrder.verify(changeListener).pluginJarRemoved(orgFile); inOrder.verify(changeListener).pluginJarAdded(newFile); verifyNoMoreInteractions(changeListener); }
@Test public void shouldNotifyRemoveEventBeforeAddEventInCaseOfFileRename() throws Exception { monitor.addPluginJarChangeListener(changeListener); monitor.start(); copyPluginToThePluginDirectory(pluginExternalDir, "descriptor-aware-test-external-plugin-1.jar"); waitUntilNextRun(monitor); PluginFileDetails orgExternalFile = pluginFileDetails(pluginExternalDir, "descriptor-aware-test-external-plugin-1.jar", false); verify(changeListener).pluginJarAdded(orgExternalFile); PluginFileDetails newExternalFile = pluginFileDetails(pluginExternalDir, "descriptor-aware-test-external-plugin-1-new.jar", false); FileUtils.moveFile(orgExternalFile.file(), newExternalFile.file()); waitUntilNextRun(monitor); InOrder inOrder = inOrder(changeListener); inOrder.verify(changeListener).pluginJarRemoved(orgExternalFile); inOrder.verify(changeListener).pluginJarAdded(newExternalFile); verifyNoMoreInteractions(changeListener); }
@Test public void shouldCreatePluginZipIfPluginJarIsUpdated() throws Exception { monitor.addPluginJarChangeListener(changeListener); monitor.start(); copyPluginToThePluginDirectory(bundledPluginDir, "descriptor-aware-test-plugin-1.jar"); waitUntilNextRun(monitor); PluginFileDetails orgFile = pluginFileDetails(bundledPluginDir, "descriptor-aware-test-plugin-1.jar", true); verify(changeListener).pluginJarAdded(orgFile); PluginFileDetails newFile = pluginFileDetails(bundledPluginDir, "descriptor-aware-test-plugin-1-new.jar", true); FileUtils.moveFile(orgFile.file(), newFile.file()); waitUntilNextRun(monitor); }