1717import java .util .List ;
1818import java .util .Map ;
1919
20+ import gov .loc .repository .bagit .filesystem .filter .NotHiddenFileSystemNodeFilter ;
2021import org .apache .commons .io .IOUtils ;
2122import org .apache .commons .logging .Log ;
2223import org .apache .commons .logging .LogFactory ;
@@ -144,15 +145,16 @@ public class CommandLineBagDriver {
144145 public static final String PARAM_FAIL_MODE = "failmode" ;
145146 public static final String PARAM_COMPRESSION_LEVEL = "compressionlevel" ;
146147 public static final String PARAM_MOVE = "move" ;
147-
148+ public static final String PARAM_INCLUDE_HIDDEN = "includehiddenfiles" ;
149+
148150 public static final String VALUE_WRITER_FILESYSTEM = Format .FILESYSTEM .name ().toLowerCase ();
149151 public static final String VALUE_WRITER_ZIP = Format .ZIP .name ().toLowerCase ();
150152
151153 private static final Log log = LogFactory .getLog (CommandLineBagDriver .class );
152154
153155 private Map <String , Operation > operationMap = new HashMap <String , Operation >();
154- private BagFactory bagFactory = new BagFactory ();
155-
156+
157+
156158 public static void main (String [] args ) throws Exception {
157159 CommandLineBagDriver driver = new CommandLineBagDriver ();
158160 int ret = driver .execute (args );
@@ -372,6 +374,7 @@ private void addOperation(String name, String help, Parameter[] params, String[]
372374 jsap .registerParameter (new Switch ( PARAM_HELP , JSAP .NO_SHORTFLAG , PARAM_HELP , "Prints help." ));
373375 jsap .registerParameter (new Switch (PARAM_VERBOSE , JSAP .NO_SHORTFLAG , PARAM_VERBOSE , "Reports progress of the operation to the console." ));
374376 jsap .registerParameter (new Switch (PARAM_LOG_VERBOSE , JSAP .NO_SHORTFLAG , PARAM_LOG_VERBOSE , "Reports progress of the operation to the log." ));
377+ jsap .registerParameter (new Switch ( PARAM_INCLUDE_HIDDEN , JSAP .NO_SHORTFLAG , PARAM_INCLUDE_HIDDEN , "Include hidden files." ));
375378
376379 this .operationMap .put (name , new Operation (name , jsap , help , examples ));
377380 }
@@ -571,7 +574,8 @@ private static String argsToString(String[] args) {
571574 return sb .toString ();
572575 }
573576
574- private Bag getBag (File sourceFile , Version version , LoadOption loadOption ) {
577+ private Bag getBag (BagFactory bagFactory , File sourceFile , Version version , LoadOption loadOption ) {
578+
575579 if (version != null ) {
576580 if (sourceFile != null ) {
577581 return bagFactory .createBag (sourceFile , version , loadOption );
@@ -611,6 +615,15 @@ private int performOperation(Operation operation, JSAPResult config) {
611615 destFile = new File (config .getString (PARAM_DESTINATION ));
612616 }
613617
618+ BagFactory bagFactory = null ;
619+ if (config .getBoolean (PARAM_INCLUDE_HIDDEN )) {
620+ // null filter will include all nodes, including hidden ones
621+ bagFactory = new BagFactory (null );
622+ } else {
623+ // The default should filter out hidden files
624+ bagFactory = new BagFactory (new NotHiddenFileSystemNodeFilter ());
625+ }
626+
614627 Writer writer = null ;
615628 if (config .contains (PARAM_WRITER )) {
616629 Format format = Format .valueOf (config .getString (PARAM_WRITER ).toUpperCase ());
@@ -726,7 +739,7 @@ else if (fetchRetryString.equalsIgnoreCase("retry")){
726739 ValidVerifierImpl verifier = new ValidVerifierImpl (completeVerifier , checksumVerifier );
727740 verifier .addProgressListener (listener );
728741 verifier .setFailMode (FailMode .valueOf (config .getString (PARAM_FAIL_MODE ).toUpperCase ()));
729- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_MANIFESTS );
742+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_MANIFESTS );
730743 try {
731744 SimpleResult result = verifier .verify (bag );
732745 log .info (result .toString ());
@@ -745,7 +758,7 @@ else if (fetchRetryString.equalsIgnoreCase("retry")){
745758 completeVerifier .setIgnoreSymlinks (config .getBoolean (PARAM_EXCLUDE_SYMLINKS ));
746759 completeVerifier .addProgressListener (listener );
747760 completeVerifier .setFailMode (FailMode .valueOf (config .getString (PARAM_FAIL_MODE ).toUpperCase ()));
748- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_MANIFESTS );
761+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_MANIFESTS );
749762 try {
750763 SimpleResult result = completeVerifier .verify (bag );
751764 log .info (result .toString ());
@@ -758,7 +771,7 @@ else if (fetchRetryString.equalsIgnoreCase("retry")){
758771 bag .close ();
759772 }
760773 } else if (OPERATION_VERIFY_TAGMANIFESTS .equals (operation .name )) {
761- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_MANIFESTS );
774+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_MANIFESTS );
762775 try {
763776 ParallelManifestChecksumVerifier verifier = new ParallelManifestChecksumVerifier ();
764777 verifier .addProgressListener (listener );
@@ -774,7 +787,7 @@ else if (fetchRetryString.equalsIgnoreCase("retry")){
774787 bag .close ();
775788 }
776789 } else if (OPERATION_VERIFY_PAYLOADMANIFESTS .equals (operation .name )) {
777- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_MANIFESTS );
790+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_MANIFESTS );
778791 try {
779792 SimpleResult result ;
780793 if (bag .getPayloadManifests ().size () == 0 ) {
@@ -795,7 +808,7 @@ else if (fetchRetryString.equalsIgnoreCase("retry")){
795808 bag .close ();
796809 }
797810 } else if (OPERATION_MAKE_COMPLETE .equals (operation .name )) {
798- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_FILES );
811+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_FILES );
799812 try {
800813 Bag newBag = completer .complete (bag );
801814 try {
@@ -807,7 +820,7 @@ else if (fetchRetryString.equalsIgnoreCase("retry")){
807820 bag .close ();
808821 }
809822 } else if (OPERATION_UPDATE .equals (operation .name )) {
810- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_FILES );
823+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_FILES );
811824 try {
812825 UpdateCompleter updateCompleter = new UpdateCompleter (bagFactory );
813826 updateCompleter .setTagManifestAlgorithm (Algorithm .valueOfBagItAlgorithm (config .getString (PARAM_TAG_MANIFEST_ALGORITHM , Algorithm .MD5 .bagItAlgorithm )));
@@ -825,7 +838,7 @@ else if (fetchRetryString.equalsIgnoreCase("retry")){
825838 }
826839 }
827840 else if (OPERATION_UPDATE_TAGMANIFESTS .equals (operation .name )) {
828- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_FILES );
841+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_FILES );
829842 try {
830843 TagManifestCompleter tagManifestCompleter = new TagManifestCompleter (bagFactory );
831844 tagManifestCompleter .setTagManifestAlgorithm (Algorithm .valueOfBagItAlgorithm (config .getString (PARAM_TAG_MANIFEST_ALGORITHM , Algorithm .MD5 .bagItAlgorithm )));
@@ -842,8 +855,9 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
842855 bag .close ();
843856 }
844857 } else if (OPERATION_UPDATE_PAYLOAD_OXUM .equals (operation .name )) {
845- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_FILES );
858+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_FILES );
846859 try {
860+
847861 UpdatePayloadOxumCompleter updatePayloadOxumCompleter = new UpdatePayloadOxumCompleter (bagFactory );
848862 Bag newBag = updatePayloadOxumCompleter .complete (bag );
849863 try {
@@ -860,7 +874,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
860874 bag .close ();
861875 }
862876 } else if (OPERATION_BAG_IN_PLACE .equals (operation .name )) {
863- PreBag preBag = this . bagFactory .createPreBag (sourceFile );
877+ PreBag preBag = bagFactory .createPreBag (sourceFile );
864878 if (config .contains (PARAM_BAGINFOTXT )) {
865879 File bagInfoTxtFile = config .getFile (PARAM_BAGINFOTXT );
866880 if (! bagInfoTxtFile .getName ().equals (bagFactory .getBagConstants ().getBagInfoTxt ())) {
@@ -875,7 +889,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
875889 }
876890 preBag .makeBagInPlace (version != null ? version : BagFactory .LATEST , config .getBoolean (PARAM_RETAIN_BASE_DIR , false ), config .getBoolean (PARAM_KEEP_EMPTY_DIRS , false ), completer );
877891 } else if (OPERATION_CREATE .equals (operation .name )) {
878- Bag bag = this .getBag (sourceFile , version , null );
892+ Bag bag = this .getBag (bagFactory , sourceFile , version , null );
879893 try {
880894 for (String filepath : config .getStringArray (PARAM_PAYLOAD )) {
881895 if (filepath .endsWith (File .separator + "*" )) {
@@ -918,7 +932,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
918932
919933 } else if (OPERATION_MAKE_HOLEY .equals (operation .name )) {
920934 HolePuncherImpl puncher = new HolePuncherImpl (bagFactory );
921- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_MANIFESTS );
935+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_MANIFESTS );
922936 try {
923937 Bag newBag = puncher .makeHoley (bag , config .getString (PARAM_BASE_URL ), ! config .getBoolean (PARAM_EXCLUDE_PAYLOAD_DIR , false ), false , config .getBoolean (PARAM_RESUME ));
924938 try {
@@ -930,7 +944,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
930944 bag .close ();
931945 }
932946 } else if (OPERATION_GENERATE_PAYLOAD_OXUM .equals (operation .name )) {
933- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_MANIFESTS );
947+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_MANIFESTS );
934948 try {
935949 String oxum = BagHelper .generatePayloadOxum (bag );
936950 log .info ("Payload-Oxum is " + oxum );
@@ -939,7 +953,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
939953 bag .close ();
940954 }
941955 } else if (OPERATION_CHECK_PAYLOAD_OXUM .equals (operation .name )) {
942- Bag bag = this .getBag (sourceFile , version , LoadOption .BY_MANIFESTS );
956+ Bag bag = this .getBag (bagFactory , sourceFile , version , LoadOption .BY_MANIFESTS );
943957 try {
944958 String genOxum = BagHelper .generatePayloadOxum (bag );
945959 BagInfoTxt bagInfo = bag .getBagInfoTxt ();
@@ -971,7 +985,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
971985 }
972986 } else if (OPERATION_FILL_HOLEY .equals (operation .name )) {
973987 FileSystemFileDestination dest = new FileSystemFileDestination (sourceFile );
974- Bag bag = this .getBag (sourceFile , version , null );
988+ Bag bag = this .getBag (bagFactory , sourceFile , version , null );
975989 try {
976990 SimpleResult result = fetcher .fetch (bag , dest , config .getBoolean (PARAM_RESUME ), config .getBoolean (PARAM_VERIFY ));
977991 log .info (result .toString ());
@@ -996,7 +1010,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
9961010 || OPERATION_SPLIT_BAG_BY_FILE_TYPE .equals (operation .name )
9971011 || OPERATION_SPLIT_BAG_BY_SIZE_AND_FILE_TYPE .equals (operation .name )) {
9981012
999- Bag srcBag = this . bagFactory .createBag (sourceFile , BagFactory .LoadOption .BY_FILES );
1013+ Bag srcBag = bagFactory .createBag (sourceFile , BagFactory .LoadOption .BY_FILES );
10001014 try {
10011015 Double sourceBagSize = null ;
10021016 if (srcBag .getBagInfoTxt () != null && srcBag .getBagInfoTxt ().getPayloadOxum () != null ){
@@ -1030,7 +1044,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
10301044 return RETURN_FAILURE ;
10311045 }
10321046
1033- Splitter splitter = new SplitBySize (this . bagFactory , maxBagSize , keepLowestLevelDir , excludeDirs );
1047+ Splitter splitter = new SplitBySize (bagFactory , maxBagSize , keepLowestLevelDir , excludeDirs );
10341048 List <Bag > splitBags = splitter .split (srcBag );
10351049 try {
10361050 this .completeAndWriteBagToDisk (splitBags , completer , writer , srcBag , destBagFile , true );
@@ -1044,7 +1058,7 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
10441058 return RETURN_FAILURE ;
10451059 }
10461060
1047- Splitter splitter = new SplitByFileType (this . bagFactory , fileExtensionsIn , excludeDirs );
1061+ Splitter splitter = new SplitByFileType (bagFactory , fileExtensionsIn , excludeDirs );
10481062 List <Bag > splitBags = splitter .split (srcBag );
10491063 try {
10501064 this .completeAndWriteBagToDisk (splitBags , completer , writer , srcBag , destBagFile , false );
@@ -1058,9 +1072,9 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
10581072 return RETURN_FAILURE ;
10591073 }
10601074
1061- Splitter splitter1 = new SplitByFileType (this . bagFactory , fileExtensionsIn , excludeDirs );
1075+ Splitter splitter1 = new SplitByFileType (bagFactory , fileExtensionsIn , excludeDirs );
10621076 List <Bag > bags = splitter1 .split (srcBag );
1063- Splitter splitter2 = new SplitBySize (this . bagFactory , maxBagSize , keepLowestLevelDir , excludeDirs );
1077+ Splitter splitter2 = new SplitBySize (bagFactory , maxBagSize , keepLowestLevelDir , excludeDirs );
10641078 try {
10651079 for (Bag bag : bags ) {
10661080 List <Bag > bagsUnderMaxSize = new ArrayList <Bag >();
@@ -1104,7 +1118,8 @@ else if (OPERATION_UPDATE_TAGMANIFESTS.equals(operation.name)) {
11041118
11051119 private void completeAndWriteBagToDisk (List <Bag > bags , Completer completer , Writer writer , Bag srcBag , File destBagFile , boolean appendNumber ){
11061120
1107- int i = 0 ;
1121+ BagFactory bagFactory = srcBag .getBagFactory ();
1122+ int i = 0 ;
11081123 for (Bag bag : bags ) {
11091124 Bag newBag = completer .complete (bag );
11101125
0 commit comments