1414
1515import java .io .File ;
1616import java .io .IOException ;
17+ import java .nio .file .Files ;
18+ import java .nio .file .Path ;
1719import java .sql .SQLException ;
1820
1921import org .apache .logging .log4j .LogManager ;
2022import org .apache .logging .log4j .Logger ;
2123import org .dspace .content .DSpaceObject ;
2224import org .dspace .core .Constants ;
2325import org .dspace .core .Context ;
26+ import org .dspace .core .PluginConfigurationError ;
27+ import org .dspace .core .PluginInstantiationException ;
2428import org .dspace .core .factory .CoreServiceFactory ;
2529import org .dspace .core .service .PluginService ;
2630import org .dspace .handle .factory .HandleServiceFactory ;
@@ -64,22 +68,31 @@ public class ReplicaManager {
6468
6569
6670 private ReplicaManager () throws IOException {
67- objStore = (ObjectStore ) pluginService .getSinglePlugin (ObjectStore .class );
68- if (objStore == null ) {
71+ try {
72+ objStore = (ObjectStore ) pluginService .getSinglePlugin (ObjectStore .class );
73+ } catch (PluginConfigurationError | PluginInstantiationException ex ) {
6974 log .error ("No ObjectStore configured in 'replicate.cfg'!" );
7075 throw new IOException ("No ObjectStore configured in 'replicate.cfg'!" );
7176 }
7277
7378 objStore .init ();
7479
75- // create directory structures
76- new File (repDir ).mkdirs ();
80+ // create directory structure
81+ Path repPath = Path .of (repDir );
82+ try {
83+ Files .createDirectories (repPath );
84+ System .out .println ("Successfully created replicate directory: " + repPath );
85+ } catch (IOException e ) {
86+ System .err .println ("Failed to create replicate.store.dir: " + e .getMessage ());
87+ throw e ;
88+ }
89+
7790 // load our odometer - writeable copy
7891 try {
7992 odometer = new Odometer (repDir , false );
8093 } catch (IOException ioE ) {
8194 // just log a warning
82- log .warn ("Unable to read odometer file in '" + repDir + "'" , ioE );
95+ log .warn ("Unable to read odometer file in '{}'" , repDir , ioE );
8396 }
8497 }
8598
@@ -94,7 +107,10 @@ public File stage(Context context, String group, String id) {
94107 // ensure path exists
95108 File stageDir = new File (repDir + File .separator + group );
96109 if (!stageDir .isDirectory ()) {
97- stageDir .mkdirs ();
110+ boolean successful = stageDir .mkdirs ();
111+ if (!successful ) {
112+ log .error ("Creating staging directory {} failed!" , stageDir );
113+ }
98114 }
99115 return new File (stageDir , storageId (context , id , null ));
100116 }
0 commit comments