ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 12632] - [PATCH] New <lsync> to synchronize a local directory from one or more <fileset>s
Date Fri, 17 Jan 2003 17:50:06 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12632>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12632

[PATCH] New <lsync> to synchronize a local directory from one or more <fileset>s





------- Additional Comments From daniel.armbrust@mayo.edu  2003-01-17 17:50 -------
I have finished my mucking to repair pass 2 (removing orphaned files - on second
thought, its not really a repair, but an extension.  In my opinion, if you ask
it to removed orphaned files, it should remove orphaned files and orphaned
directories).

I have attached the class in its entirity.

Here are the changes in diff format:

<         int removedFileCount = removeOrphanFiles(allFiles, toDir);
<         logRemovedCount(removedFileCount, "dangling file", "", "s");
---
>               int[] removedFileCount = removeOrphanFiles(allFiles, toDir);
>               logRemovedCount(removedFileCount[0], "dangling director", "y",
"ies");
>               logRemovedCount(removedFileCount[1], "dangling file", "", "s");
110c111
<      * Removes all files not found as keyes of a table (used as a set!).
---
>        * Removes all files and folders not found as keyes of a table (used as
a set!).
114a116,117
>        * If the directory is an orphan, it will also be removed.
>        *
117c120,123
<      * @return the number of orphaned files actually removed.
---
>        * @return the number of orphaned files and directories actually removed.
>        * Position 0 of the array is the number of orphaned directories.
>        * Position 1 of the array is the number or orphaned files.
>        * Position 2 is meaningless.
119,120c125,126
<     private int removeOrphanFiles(Hashtable nonOrphans, File file) {
<         int removedCount = 0;
---
>       private int[] removeOrphanFiles(Hashtable nonOrphans, File file) {
>               int[] removedCount = new int[]{0, 0, 0};
124c130,154
<                 removedCount += removeOrphanFiles(nonOrphans, children[i]);
---
>                               int[] temp = removeOrphanFiles(nonOrphans,
children[i]);
>                               removedCount[0] += temp[0];
>                               removedCount[1] += temp[1];
>                               removedCount[2] += temp[2];
>                       }
>                       if (nonOrphans.get(file) == null && removedCount[2] ==
0) {
>                               log("Removing orphan directory: "+file,
Project.MSG_DEBUG);
>                               file.delete();
>                               ++removedCount[0];
>                       }
>                       else {
>                               /*
>                               Contrary to what is said above, position 2 is
not meaningless inside the recursion.
>                               Position 2 is used to carry information back up
the recursion about whether or not
>                               a directory contains a directory or file at any
depth that is not an orphan
>                               This has to be done, because if you have the
following directory structure:
>                               c:\src\a\file
>                               and your mapper src files were constructed like so:
>                               <include name="**\a\**\*"/>
>                               The folder 'a' will not be in the hashtable of
nonorphans.  So, before deleting it as
>                               an orphan, we have to know whether or not any of
its children at any level are orphans.
>                               If no, then this folder is also an orphan, and
may be deleted.  I do this by changing
>                               position 2 to a '1'.
>                               */
>                               removedCount[2] = 1;
131c161,164
<                 ++removedCount;
---
>                               ++removedCount[1];
>                       }
>                       else {
>                               removedCount[2] = 1;


The way I implemented this felt like sort of a hack.  But I don't know a better
way to do it.  It has tested correctly in all of my use cases, but I am not well
versed in ANT, so there may be problems that I have introduced in other use cases.  

Feedback welcome!  Especially if you can think of a better way to implement my
changes.

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message