Skip to content

Commit

Permalink
0001580: Expose the relative target directory as a variable that can …
Browse files Browse the repository at this point in the history
…be scripted in order to flatten the directory structure in file sync
  • Loading branch information
chenson42 committed Feb 14, 2014
1 parent af62c74 commit 635398e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
18 changes: 18 additions & 0 deletions symmetric-assemble/src/docbook/file-sync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ overwritten in <xref linkend="table_file_trigger_router" xrefstyle="table" />. T
</varlistentry>
<varlistentry>
<term>
<command>targetRelativeDir</command>
</term>
<listitem>
<para> The name of a directory relative to the target base directory to which the target file will be copied. The
default value of this variable is the relative directory of the source. For example, if the source base directory is
<literal>/src</literal> and the target base directory is <literal>/tgt</literal> and the file <literal>/src/subfolder/1.txt</literal>
is changed, then the default targetRelativeDir will be <literal>subfolder</literal>.
This variable can be overwritten by the
<literal>before_copy_script</literal> to change the relative directory at the target. In the above example, if the variable is
set to blank using the following script, then the target file will be copied to <literal>/tgt/1.txt</literal>.
<programlisting>
targetRelativeDir = "";
</programlisting>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<command>processFile</command>
</term>
<listitem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ public void end(Batch batch, boolean inError) {
command.append("processFile = true;\n");
command.append("sourceFileName = \"").append(snapshot.getFileName())
.append("\";\n");
command.append("targetRelativeDir = \"");
if (!snapshot.getRelativeDir().equals(".")) {
command.append(StringEscapeUtils.escapeJava(snapshot
.getRelativeDir()));
command.append("\";\n");
} else {
command.append("\";\n");
}
command.append("targetFileName = sourceFileName;\n");
command.append("sourceFilePath = \"");
command.append(StringEscapeUtils.escapeJava(snapshot.getRelativeDir()))
Expand All @@ -193,9 +201,10 @@ public void end(Batch batch, boolean inError) {
if (StringUtils.isNotBlank(fileTrigger.getBeforeCopyScript())) {
command.append(fileTrigger.getBeforeCopyScript()).append("\n");
}

command.append("if (processFile) {\n");

String targetFile = "targetBaseDir + \"/\" + targetRelativeDir + \"/\" + targetFileName";

switch (eventType) {
case CREATE:
case MODIFY:
Expand All @@ -212,14 +221,6 @@ public void end(Batch batch, boolean inError) {
command.append(");\n");

command.append(" java.io.File targetFile = new java.io.File(");
StringBuilder targetFile = new StringBuilder(
"targetBaseDir + \"/");
if (!snapshot.getRelativeDir().equals(".")) {
targetFile.append(StringEscapeUtils.escapeJava(snapshot
.getRelativeDir()));
targetFile.append("/");
}
targetFile.append("\" + targetFileName");
command.append(targetFile);
command.append(");\n");

Expand Down Expand Up @@ -259,13 +260,6 @@ public void end(Batch batch, boolean inError) {
break;
case DELETE:
command.append(" org.apache.commons.io.FileUtils.deleteQuietly(new java.io.File(");
StringBuilder targetFile = new StringBuilder("targetBaseDir + \"/");
if (!snapshot.getRelativeDir().equals(".")) {
targetFile.append(StringEscapeUtils.escapeJava(snapshot
.getRelativeDir()));
targetFile.append("/");
}
targetFile.append("\" + targetFileName");
command.append(targetFile);
command.append("));\n");
command.append(" fileList.put(").append(targetFile).append(",\"");
Expand Down

0 comments on commit 635398e

Please sign in to comment.