Skip to content

Commit

Permalink
0001440: Implement simple conflict resolution for file sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanes committed Oct 15, 2013
1 parent c2b408e commit f8b35cd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Expand Up @@ -231,11 +231,11 @@ public void end(Batch batch, boolean inError) {
// conflict resolution
FileConflictStrategy conflictStrategy = triggerRouter.getConflictStrategy();
if (conflictStrategy == FileConflictStrategy.TARGET_WINS ||
conflictStrategy == FileConflictStrategy.REPORT_ERROR) {
conflictStrategy == FileConflictStrategy.MANUAL) {
command.append(" if (targetFile.exists() && !targetFile.isDirectory()) {\n");
command.append(" long targetChecksum = org.apache.commons.io.FileUtils.checksumCRC32(targetFile);\n");
command.append(" if (targetChecksum != " + snapshot.getOldCrc32Checksum() + ") {\n");
if (conflictStrategy == FileConflictStrategy.REPORT_ERROR) {
if (conflictStrategy == FileConflictStrategy.MANUAL) {
command.append(" throw new org.jumpmind.symmetric.file.FileConflictException(targetFileName + \" was in conflict \");\n");
} else {
command.append(" processFile = false;\n");
Expand Down
Expand Up @@ -23,6 +23,6 @@

public enum FileConflictStrategy {

SOURCE_WINS, TARGET_WINS, REPORT_ERROR
SOURCE_WINS, TARGET_WINS, MANUAL

}
2 changes: 1 addition & 1 deletion symmetric-core/src/main/resources/symmetric-schema.xml
Expand Up @@ -709,7 +709,7 @@
<column name="enabled" type="BOOLEANINT" size="1" required="true" default="1" description="Indicates whether this file trigger router is enabled or not."/>
<column name="initial_load_enabled" type="BOOLEANINT" size="1" required="true" default="1" description="Indicates whether this file trigger should be initial loaded."/>
<column name="target_base_dir" type="VARCHAR" size="255" description="The base directory on the destination that files will be synchronized to." />
<column name="conflict_strategy" type="VARCHAR" size="128" default="source_wins" required="true" description="The strategy to employ when a file has been modified at both the client and the server. Possible values are: source_wins, target_wins, report_error" />
<column name="conflict_strategy" type="VARCHAR" size="128" default="source_wins" required="true" description="The strategy to employ when a file has been modified at both the client and the server. Possible values are: source_wins, target_wins, manual" />
<column name="create_time" type="TIMESTAMP" required="true" description="Timestamp when this entry was created." />
<column name="last_update_by" type="VARCHAR" size="50" description="The user who last updated this entry." />
<column name="last_update_time" type="TIMESTAMP" required="true" description="Timestamp when a user last updated this entry." />
Expand Down
Expand Up @@ -84,7 +84,7 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)

testTargetWins(rootServer, clientServer);

testReportError(rootServer, clientServer);
testManual(rootServer, clientServer);

}

Expand Down Expand Up @@ -261,17 +261,17 @@ protected void testTargetWins(ISymmetricEngine rootServer,

}

protected void testReportError(ISymmetricEngine rootServer,
protected void testManual(ISymmetricEngine rootServer,
ISymmetricEngine clientServer) throws Exception {

IFileSyncService fileSyncService = rootServer.getFileSyncService();
FileTriggerRouter fileTriggerRouter = fileSyncService.getFileTriggerRouter("all","server_2_client");
fileTriggerRouter.setConflictStrategy(FileConflictStrategy.REPORT_ERROR);
fileTriggerRouter.setConflictStrategy(FileConflictStrategy.MANUAL);
fileSyncService.saveFileTriggerRouter(fileTriggerRouter);

pull("client");

File allFile1 = new File(allSvrSourceDir, "report_error/test.txt");
File allFile1 = new File(allSvrSourceDir, "manual/test.txt");
allFile1.getParentFile().mkdirs();
FileUtils.write(allFile1, "server value");

Expand Down

0 comments on commit f8b35cd

Please sign in to comment.