Skip to content

Commit 6c31db5

Browse files
committed
improved error handling when creating ObjectStore; other fixes
1 parent 3ec7be4 commit 6c31db5

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

src/main/java/org/dspace/ctask/replicate/ReplicaManager.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414

1515
import java.io.File;
1616
import java.io.IOException;
17+
import java.nio.file.Files;
18+
import java.nio.file.Path;
1719
import java.sql.SQLException;
1820

1921
import org.apache.logging.log4j.LogManager;
2022
import org.apache.logging.log4j.Logger;
2123
import org.dspace.content.DSpaceObject;
2224
import org.dspace.core.Constants;
2325
import org.dspace.core.Context;
26+
import org.dspace.core.PluginConfigurationError;
27+
import org.dspace.core.PluginInstantiationException;
2428
import org.dspace.core.factory.CoreServiceFactory;
2529
import org.dspace.core.service.PluginService;
2630
import 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

Comments
 (0)