Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Caused updates to persist, cleaned out old props before storing new o…
…nes, proper logging, better exception messages
  • Loading branch information
ajs6f committed Apr 8, 2013
1 parent 8706ea4 commit e747b29
Showing 1 changed file with 14 additions and 16 deletions.
Expand Up @@ -47,24 +47,21 @@ protected BagItExtraPropertiesStore(BagItConnector connector) {

@Override
public void storeProperties(String id, Map<Name, Property> properties) {
PrintWriter out = null;
try {
try {
File bagInfo = bagInfoFile(id);
out = new PrintWriter(new FileWriter(bagInfo));
for (Map.Entry<Name, Property> entry : properties.entrySet()) {
Name name = entry.getKey();
Property prop = entry.getValue();
String line =
stringFactory.create(name) + ": " +
stringFactory.create(prop);
out.println(wrapLine(line));
}
} finally {
out.close();
File bagInfo = bagInfoFile(id);
bagInfo.delete();
try (PrintWriter out = new PrintWriter(new FileWriter(bagInfo))) {
for (Map.Entry<Name, Property> entry : properties.entrySet()) {
Name name = entry.getKey();
Property prop = entry.getValue();
String line =
stringFactory.create(name) + ": " +
stringFactory.create(prop);
out.println(wrapLine(line));
}
} catch (Exception ex) {
throw new DocumentStoreException(id, ex);
throw new DocumentStoreException(
"Error in storing properties for " + id + " at " +
connector.fileFor(id), ex);
}
}

Expand All @@ -80,6 +77,7 @@ public void updateProperties(String id, Map<Name, Property> properties) {
existing.put(name, prop);
}
}
storeProperties(id, existing);
}

@Override
Expand Down

0 comments on commit e747b29

Please sign in to comment.