diff --git a/pom.xml b/pom.xml index 251778b..cdbe3ae 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ SyncTool synctool - 1.3 + 1.4 jar SyncTool diff --git a/src/main/java/de/tilman/synctool/SyncTool.java b/src/main/java/de/tilman/synctool/SyncTool.java index 1668ac9..96290d7 100644 --- a/src/main/java/de/tilman/synctool/SyncTool.java +++ b/src/main/java/de/tilman/synctool/SyncTool.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.lang.reflect.Array; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -30,7 +31,9 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; @@ -91,6 +94,8 @@ public class SyncTool { private long filesCopied; private long filesDeleted; + private List ignoredFiles = null; + public SyncTool(JSAPResult config) { this.dryRun = config.getBoolean("dry-run"); @@ -109,6 +114,11 @@ public class SyncTool { if (hashing) log.info("Using MD5 hashes to compare files"); + if (config.getString("ignore file") != null) { + ignoredFiles = Arrays.asList(config.getStringArray("ignore file")); + } + + try { log.info("Connecting to database \"" + config.getString("database file") + "\""); Class.forName("org.h2.Driver"); @@ -265,6 +275,14 @@ public class SyncTool { File srcFile = srcFiles[i]; srcFiles[i] = null; File destFile = destMap.remove(srcFile.getName()); + + // check for files to ignore + if (ignoredFiles != null) { + if (ignoredFiles.contains(srcFile.getPath())) { + log.info(" Ignoring file " + srcFile.getPath()); + continue; + } + } // check synchronization history log.debug(" get source history from database"); @@ -457,7 +475,7 @@ public class SyncTool { public static void main(String[] args) { BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{ISO8601} - %m%n"))); - log.info("Starting SyncTool version 1.3"); + log.info("Starting SyncTool version 1.4"); JSAP jsap = new JSAP(); @@ -517,6 +535,11 @@ public class SyncTool { jabberPassword.setHelp("the jabber password used for logging in to the server"); jsap.registerParameter(jabberPassword); + FlaggedOption ignoredFile = new FlaggedOption("ignore file").setStringParser(JSAP.STRING_PARSER).setLongFlag( + "ignore").setShortFlag('g').setAllowMultipleDeclarations(true); + jabberPassword.setHelp("path to a file that should be ignored during synchronization"); + jsap.registerParameter(ignoredFile); + Switch dryRunSwitch = new Switch("dry-run").setLongFlag("dry-run").setShortFlag('d'); dryRunSwitch.setHelp("perform a trial run with no changes made"); jsap.registerParameter(dryRunSwitch);