22
33import java .io .Closeable ;
44import java .io .File ;
5- import java .io .IOException ;
65import java .text .MessageFormat ;
76import java .util .ArrayList ;
87import java .util .Collection ;
98import java .util .HashMap ;
109import java .util .HashSet ;
11- import java .util .Iterator ;
1210import java .util .List ;
1311import java .util .Map ;
1412import java .util .Map .Entry ;
1513import java .util .Set ;
1614
17- import org .apache .commons .io .FileUtils ;
1815import org .apache .commons .io .IOUtils ;
1916import org .apache .commons .logging .Log ;
2017import org .apache .commons .logging .LogFactory ;
@@ -544,25 +541,24 @@ public void removePayloadDirectory(String filepath) {
544541 filepath = bagConstants .getDataDirectory () + "/" + filepath ;
545542 }
546543
547- log .debug ("remove all the files under " + filepath );
548- //remove all the files. Need to create list so there is no concurrentModificationException
544+ if ((bagConstants .getDataDirectory () + "/" ).equals (filepath )) {
545+ return ;
546+ }
547+
548+ log .debug ("Removing payload directory " + filepath );
549+
549550 List <String > deleteFilepaths = new ArrayList <String >();
550- for (BagFile bagFile : this .getPayload ()) {
551- if (bagFile .getFilepath ().startsWith (filepath )) {
552- deleteFilepaths .add (bagFile .getFilepath ());
553- }
554- }
555- for (String deleteFilepath : deleteFilepaths ) {
556- log .debug ("Removing " + deleteFilepath );
557- this .removeBagFile (deleteFilepath );
558- }
559551
560- //now remove the empty directories
561- try {
562- FileUtils .deleteDirectory (new File (filepath ));
563- } catch (IOException e ) {
564- log .error ("Could not delete payload directory [" + filepath + "]!" , e );
565- }
552+ for (BagFile bagFile : this .getPayload ()) {
553+ if (bagFile .getFilepath ().startsWith (filepath )) {
554+ deleteFilepaths .add (bagFile .getFilepath ());
555+ }
556+ }
557+
558+ for (String deleteFilepath : deleteFilepaths ) {
559+ log .debug ("Removing " + deleteFilepath );
560+ this .removeBagFile (deleteFilepath );
561+ }
566562 }
567563
568564 @ Override
@@ -574,27 +570,21 @@ public void removeTagDirectory(String filepath) {
574570 if (filepath .startsWith (bagConstants .getDataDirectory ())) {
575571 throw new RuntimeException ("Trying to remove payload" );
576572 }
577-
578- log .debug ("remove all the files under " + filepath );
579- //remove all the files. Need to create list so there is no concurrentModificationException
580- List <String > deleteFilepaths = new ArrayList <String >();
581- for (BagFile bagFile : this .getTags ()) {
582- if (bagFile .getFilepath ().startsWith (filepath )) {
583- deleteFilepaths .add (bagFile .getFilepath ());
584- }
585- }
586- for (String deleteFilepath : deleteFilepaths ) {
587- log .debug ("Removing " + deleteFilepath );
588- this .removeBagFile (deleteFilepath );
589- }
590573
591574 log .debug ("Removing tag directory " + filepath );
592- //now remove the empty directories
593- try {
594- FileUtils .deleteDirectory (new File (filepath ));
595- } catch (IOException e ) {
596- log .error ("Could not delete tag directory [" + filepath + "]!" , e );
597- }
575+
576+ List <String > deleteFilepaths = new ArrayList <String >();
577+
578+ for (BagFile bagFile : this .getTags ()) {
579+ if (bagFile .getFilepath ().startsWith (filepath )) {
580+ deleteFilepaths .add (bagFile .getFilepath ());
581+ }
582+ }
583+
584+ for (String deleteFilepath : deleteFilepaths ) {
585+ log .debug ("Removing " + deleteFilepath );
586+ this .removeBagFile (deleteFilepath );
587+ }
598588 }
599589
600590
0 commit comments