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
;
9 import java
.time
.ZonedDateTime
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.jackrabbit
.fs
.DavexFsProvider
;
14 import org
.argeo
.ssh
.Sftp
;
15 import org
.argeo
.sync
.SyncException
;
16 import org
.argeo
.util
.LangUtils
;
18 public class PathSync
implements Runnable
{
19 private final static Log log
= LogFactory
.getLog(PathSync
.class);
21 private final URI sourceUri
, targetUri
;
23 public PathSync(URI sourceUri
, URI targetUri
) {
24 this.sourceUri
= sourceUri
;
25 this.targetUri
= targetUri
;
31 Path sourceBasePath
= createPath(sourceUri
);
32 Path targetBasePath
= createPath(targetUri
);
33 SyncFileVisitor syncFileVisitor
= new SyncFileVisitor(sourceBasePath
, targetBasePath
);
34 ZonedDateTime begin
= ZonedDateTime
.now();
35 Files
.walkFileTree(sourceBasePath
, syncFileVisitor
);
36 if (log
.isDebugEnabled())
37 log
.debug("Sync from " + sourceBasePath
+ " to " + targetBasePath
+ " took " + LangUtils
.since(begin
));
38 } catch (Exception e
) {
43 private static Path
createPath(URI uri
) {
45 if (uri
.getScheme() == null) {
46 path
= Paths
.get(uri
.getPath());
47 } else if (uri
.getScheme().equals("file")) {
48 FileSystemProvider fsProvider
= FileSystems
.getDefault().provider();
49 path
= fsProvider
.getPath(uri
);
50 } else if (uri
.getScheme().equals("davex")) {
51 FileSystemProvider fsProvider
= new DavexFsProvider();
52 path
= fsProvider
.getPath(uri
);
53 } else if (uri
.getScheme().equals("sftp")) {
54 Sftp sftp
= new Sftp(uri
);
55 path
= sftp
.getBasePath();
57 throw new SyncException("URI scheme not supported for " + uri
);