Ignore file option
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>SyncTool</groupId>
|
<groupId>SyncTool</groupId>
|
||||||
<artifactId>synctool</artifactId>
|
<artifactId>synctool</artifactId>
|
||||||
<version>1.3</version>
|
<version>1.4</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>SyncTool</name>
|
<name>SyncTool</name>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -30,7 +31,9 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
@@ -91,6 +94,8 @@ public class SyncTool {
|
|||||||
private long filesCopied;
|
private long filesCopied;
|
||||||
private long filesDeleted;
|
private long filesDeleted;
|
||||||
|
|
||||||
|
private List<String> ignoredFiles = null;
|
||||||
|
|
||||||
public SyncTool(JSAPResult config) {
|
public SyncTool(JSAPResult config) {
|
||||||
|
|
||||||
this.dryRun = config.getBoolean("dry-run");
|
this.dryRun = config.getBoolean("dry-run");
|
||||||
@@ -109,6 +114,11 @@ public class SyncTool {
|
|||||||
if (hashing)
|
if (hashing)
|
||||||
log.info("Using MD5 hashes to compare files");
|
log.info("Using MD5 hashes to compare files");
|
||||||
|
|
||||||
|
if (config.getString("ignore file") != null) {
|
||||||
|
ignoredFiles = Arrays.asList(config.getStringArray("ignore file"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info("Connecting to database \"" + config.getString("database file") + "\"");
|
log.info("Connecting to database \"" + config.getString("database file") + "\"");
|
||||||
Class.forName("org.h2.Driver");
|
Class.forName("org.h2.Driver");
|
||||||
@@ -266,6 +276,14 @@ public class SyncTool {
|
|||||||
srcFiles[i] = null;
|
srcFiles[i] = null;
|
||||||
File destFile = destMap.remove(srcFile.getName());
|
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
|
// check synchronization history
|
||||||
log.debug(" get source history from database");
|
log.debug(" get source history from database");
|
||||||
selectFileSql.setString(1, srcFile.getCanonicalPath());
|
selectFileSql.setString(1, srcFile.getCanonicalPath());
|
||||||
@@ -457,7 +475,7 @@ public class SyncTool {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{ISO8601} - %m%n")));
|
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();
|
JSAP jsap = new JSAP();
|
||||||
|
|
||||||
@@ -517,6 +535,11 @@ public class SyncTool {
|
|||||||
jabberPassword.setHelp("the jabber password used for logging in to the server");
|
jabberPassword.setHelp("the jabber password used for logging in to the server");
|
||||||
jsap.registerParameter(jabberPassword);
|
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');
|
Switch dryRunSwitch = new Switch("dry-run").setLongFlag("dry-run").setShortFlag('d');
|
||||||
dryRunSwitch.setHelp("perform a trial run with no changes made");
|
dryRunSwitch.setHelp("perform a trial run with no changes made");
|
||||||
jsap.registerParameter(dryRunSwitch);
|
jsap.registerParameter(dryRunSwitch);
|
||||||
|
|||||||
Reference in New Issue
Block a user