Ignore file option

This commit is contained in:
2012-10-08 17:19:47 +02:00
parent a7887974e4
commit e09e3b7a85
2 changed files with 25 additions and 2 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<groupId>SyncTool</groupId>
<artifactId>synctool</artifactId>
<version>1.3</version>
<version>1.4</version>
<packaging>jar</packaging>
<name>SyncTool</name>
+24 -1
View File
@@ -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<String> 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");
@@ -266,6 +276,14 @@ public class SyncTool {
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");
selectFileSql.setString(1, srcFile.getCanonicalPath());
@@ -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);