1 package org
.argeo
.cms
.acr
.fs
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.FileVisitResult
;
5 import java
.nio
.file
.Files
;
6 import java
.nio
.file
.Path
;
7 import java
.nio
.file
.SimpleFileVisitor
;
8 import java
.nio
.file
.attribute
.BasicFileAttributes
;
10 public class FsSyncUtils
{
11 /** Sync a source path with a target path. */
12 public static void sync(Path sourceBasePath
, Path targetBasePath
) {
13 sync(sourceBasePath
, targetBasePath
, false);
16 /** Sync a source path with a target path. */
17 public static void sync(Path sourceBasePath
, Path targetBasePath
, boolean delete
) {
18 sync(new BasicSyncFileVisitor(sourceBasePath
, targetBasePath
, delete
, true));
21 public static void sync(BasicSyncFileVisitor syncFileVisitor
) {
23 Files
.walkFileTree(syncFileVisitor
.getSourceBasePath(), syncFileVisitor
);
24 } catch (Exception e
) {
25 throw new RuntimeException("Cannot sync " + syncFileVisitor
.getSourceBasePath() + " with "
26 + syncFileVisitor
.getTargetBasePath(), e
);
31 * Deletes this path, recursively if needed. Does nothing if the path does not
34 public static void delete(Path path
) {
36 if (!Files
.exists(path
))
38 Files
.walkFileTree(path
, new SimpleFileVisitor
<Path
>() {
40 public FileVisitResult
postVisitDirectory(Path directory
, IOException e
) throws IOException
{
43 Files
.delete(directory
);
44 return FileVisitResult
.CONTINUE
;
48 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
50 return FileVisitResult
.CONTINUE
;
53 } catch (IOException e
) {
54 throw new RuntimeException("Cannot delete " + path
, e
);
59 private FsSyncUtils() {