Skip to content

Commit

Permalink
Clarify intent of savepoint loading code.
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Jan 6, 2018
1 parent f9c6cb2 commit 3a60fa1
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,24 @@ private void processItemSets(File formMediaDir) {
private boolean initializeForm(FormDef formDef, FormEntryController fec) {
final InstanceInitializationFactory instanceInit = new InstanceInitializationFactory();
boolean usedSavepoint = false;

if (instancePath != null) {
File instance = new File(instancePath);
final File shadowInstance = SaveToDiskTask.getSavepointFile(instance.getName());
if (shadowInstance.exists() && (shadowInstance.lastModified()
> instance.lastModified())) {
// the savepoint is newer than the saved value of the instance.
// use it.
File instanceXml = new File(instancePath);

// Use the savepoint file only if it's newer than the last manual save
final File savepointFile = SaveToDiskTask.getSavepointFile(instanceXml.getName());
if (savepointFile.exists()
&& savepointFile.lastModified() > instanceXml.lastModified()) {
usedSavepoint = true;
instance = shadowInstance;
Timber.w("Loading instance from shadow file: %s", shadowInstance.getAbsolutePath());
instanceXml = savepointFile;
Timber.w("Loading instance from savepoint file: %s",
savepointFile.getAbsolutePath());
}
if (instance.exists()) {

if (instanceXml.exists()) {
// This order is important. Import data, then initialize.
try {
importData(instance, fec);
importData(instanceXml, fec);
formDef.initialize(false, instanceInit);
} catch (RuntimeException e) {
Timber.e(e);
Expand Down

0 comments on commit 3a60fa1

Please sign in to comment.