* Fixed a bug in Ottoman: the parameterless constructor didn't initialize _file, leaving it garbage and leading to a crash if you deleted the object without saving.
* This bug was being hidden by another bug in saveAs which didn't delete the old _file.
* Also added a versionsChanged hook that subclasses can override.
1.1 --- a/include/Ottoman.h Thu Sep 24 10:28:50 2009 -0700
1.2 +++ b/include/Ottoman.h Thu Sep 24 10:36:08 2009 -0700
1.3 @@ -79,6 +79,10 @@
1.4 bool scavenge (bool repair =false);
1.5
1.6 ChunkIterator* chunkIterator() const; // for testing purposes
1.7 +
1.8 + protected:
1.9 + /** Hook for subclassers: Called when new versions are added. */
1.10 + virtual void versionsChanged() { }
1.11
1.12 private:
1.13 Ottoman(const Ottoman&); // forbid copying/assignment
2.1 --- a/src/Ottoman.cpp Thu Sep 24 10:28:50 2009 -0700
2.2 +++ b/src/Ottoman.cpp Thu Sep 24 10:36:08 2009 -0700
2.3 @@ -42,6 +42,7 @@
2.4
2.5 Ottoman::Ottoman()
2.6 :_writeable(true),
2.7 + _file(NULL),
2.8 _filename(NULL),
2.9 _lastVersion(NULL),
2.10 _current( new OverlayDictionary(&Dictionary::kEmpty) )
2.11 @@ -96,6 +97,9 @@
2.12 delete _file;
2.13 _file = curFile;
2.14 }
2.15 +
2.16 + if (changed)
2.17 + versionsChanged();
2.18 return changed;
2.19 }
2.20
2.21 @@ -196,11 +200,12 @@
2.22 if (!lastVersion)
2.23 lastVersion = new VersionDictionary(dstFile);
2.24 VersionDictionary *saved = lastVersion->_appendAndOpen(_current->overlay(),
2.25 - dstFile,
2.26 - _current->baseReplaced());
2.27 + dstFile,
2.28 + _current->baseReplaced());
2.29 // (don't delete _lastVersion: saved->_previousVersion now points to it.)
2.30 _lastVersion = saved;
2.31 _current->revertTo(_lastVersion);
2.32 + versionsChanged();
2.33 }
2.34
2.35 bool Ottoman::save() {
2.36 @@ -235,6 +240,7 @@
2.37 File *dstFile = _writeTo(dstFileName, overwriteAllowed);
2.38 free(_filename);
2.39 _filename = strdup(dstFileName);
2.40 + delete _file;
2.41 _file = dstFile;
2.42 }
2.43