1 package org
.argeo
.sync
.fs
;
4 import java
.nio
.file
.FileSystems
;
5 import java
.nio
.file
.Files
;
6 import java
.nio
.file
.Path
;
7 import java
.nio
.file
.Paths
;
8 import java
.nio
.file
.spi
.FileSystemProvider
;
10 import org
.argeo
.jackrabbit
.fs
.DavexFsProvider
;
11 import org
.argeo
.ssh
.Sftp
;
12 import org
.argeo
.sync
.SyncException
;
14 /** Synchronises two paths. */
15 public class PathSync
implements Runnable
{
16 private final URI sourceUri
, targetUri
;
17 private boolean delete
= false;
19 public PathSync(URI sourceUri
, URI targetUri
) {
20 this.sourceUri
= sourceUri
;
21 this.targetUri
= targetUri
;
27 Path sourceBasePath
= createPath(sourceUri
);
28 Path targetBasePath
= createPath(targetUri
);
29 SyncFileVisitor syncFileVisitor
= new SyncFileVisitor(sourceBasePath
, targetBasePath
, delete
);
30 Files
.walkFileTree(sourceBasePath
, syncFileVisitor
);
31 } catch (Exception e
) {
36 private static Path
createPath(URI uri
) {
38 if (uri
.getScheme() == null) {
39 path
= Paths
.get(uri
.getPath());
40 } else if (uri
.getScheme().equals("file")) {
41 FileSystemProvider fsProvider
= FileSystems
.getDefault().provider();
42 path
= fsProvider
.getPath(uri
);
43 } else if (uri
.getScheme().equals("davex")) {
44 FileSystemProvider fsProvider
= new DavexFsProvider();
45 path
= fsProvider
.getPath(uri
);
46 } else if (uri
.getScheme().equals("sftp")) {
47 Sftp sftp
= new Sftp(uri
);
48 path
= sftp
.getBasePath();
50 throw new SyncException("URI scheme not supported for " + uri
);