@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { // We are now in dir. We need to remove root of config files to have a relative path // If we are not walking in root dir, we might be able to copy its content // if it does not already exist if (configPathRootLevel != dir.getNameCount()) { Path subpath = dir.subpath(configPathRootLevel, dir.getNameCount()); Path path = buildPath(subpath); if (!Files.exists(path)) { // We just move the structure to new dir // we can't do atomic move here since src / dest might be on different mounts? move(dir, path); // We just ignore sub files from here return FileVisitResult.SKIP_SUBTREE; } } return FileVisitResult.CONTINUE; }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path subpath = null; if (configPathRootLevel != file.getNameCount()) { subpath = file.subpath(configPathRootLevel, file.getNameCount()); } Path path = buildPath(subpath); if (!Files.exists(path)) { // We just move the new file to new dir move(file, path); } else if (suffix != null) { if (!isSameFile(file, path)) { // If it already exists we try to copy this new version appending suffix to its name path = path.resolveSibling(path.getFileName().toString().concat(suffix)); // We just move the file to new dir but with a new name (appended with suffix) Files.move(file, path, StandardCopyOption.REPLACE_EXISTING); } } return FileVisitResult.CONTINUE; }
FileSystemUtils.move(sourcePluginBinDirectory, destPluginBinDirectory); } catch (IOException e) { throw new IOException("Could not move [" + sourcePluginBinDirectory + "] to [" + destPluginBinDirectory + "]", e);