Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libcore|App: Accessing persistent data in read-only or mutable mode
Timestamps get updated automatically if the Archive is accessed in
mutable mode. Fixes a problem with Refuge (Config) where timestamps
were not being preserved even though no one had written to the archive.
  • Loading branch information
skyjake committed Oct 27, 2014
1 parent 29c9c52 commit 809edb0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 9 additions & 1 deletion doomsday/libcore/include/de/core/app.h
Expand Up @@ -242,8 +242,16 @@ class DENG2_PUBLIC App : DENG2_OBSERVES(Clock, TimeChange)
*
* @return Persistent data archive.
*/
static Archive &persistentData();
static Archive const &persistentData();

/**
* Returns the persistent data as a mutable archive. Accessing the entries in
* a mutable archive will automatically update their timestamps.
*
* @return Persistent data archive (allowing changes).
*/
static Archive &mutablePersistentData();

static bool hasPersistentData();

/**
Expand Down
14 changes: 12 additions & 2 deletions doomsday/libcore/src/core/app.cpp
Expand Up @@ -519,15 +519,25 @@ NativePath App::nativeHomePath()
return (d->cachedHomePath = nativeHome);
}

Archive &App::persistentData()
Archive const &App::persistentData()
{
Archive *persist = DENG2_APP->d->persistentData;
Archive const *persist = DENG2_APP->d->persistentData;
if(!persist)
{
throw PersistentDataNotAvailable("App::persistentData", "Persistent data is disabled");
}
return *persist;
}

Archive &App::mutablePersistentData()
{
Archive *persist = DENG2_APP->d->persistentData;
if(!persist)
{
throw PersistentDataNotAvailable("App::mutablePersistentData", "Persistent data is disabled");
}
return *persist;
}

bool App::hasPersistentData()
{
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libcore/src/data/refuge.cpp
Expand Up @@ -76,7 +76,8 @@ void Refuge::write() const
{
if(App::hasPersistentData())
{
Writer(App::persistentData().entryBlock(d->persistentPath)).withHeader() << d->names;
Writer(App::mutablePersistentData().entryBlock(d->persistentPath)).withHeader()
<< d->names;
}
}

Expand Down

0 comments on commit 809edb0

Please sign in to comment.