[Zope-dev] DirectoryStorage 0.03

Petru Paler ppetru@coltronix.com
Thu, 8 Jun 2000 14:28:52 +0300 (EEST)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

---1463811836-866396627-960463732=:7515
Content-Type: TEXT/PLAIN; charset=US-ASCII


   Note that this version (experimentally) uses a dbm database for storing
serials. If you don't have/don't want to use gdbm, replace all occurences
of gdbm with dbhash or dumbdbm. I didn't used anydbm because it has some
strange problems with my python installation :) (but it will be fixed
soon).

Changelog:
0.03:
        - don't die if posix.fsync is not available
        - base class renamed to DirectoryStorage
        - added directory (re)creation and locking
        - added a 'magic' file
        - last oid file open/close bug
        - moved serials to an gdbm database

0.02:
        - converted to using os.path.join

0.01:
        - initial release


-Petru

---1463811836-866396627-960463732=:7515
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="DirectoryStorage.py"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.10.10006081428520.7515@oliver.local.coltronix.com>
Content-Description: 
Content-Disposition: attachment; filename="DirectoryStorage.py"

IyBDb3B5cmlnaHQgKGMpIDIwMDAgUGV0cnUgUGFsZXIgKHBwZXRydUBjb2x0
cm9uaXguY29tKSBBbGwgcmlnaHRzIHJlc2VydmVkLg0KDQoNCiMgVG8tZG8g
bGlzdDoNCiMgQ3JpdGljYWw6DQojICAgIC0gTW9zdCBJL08gb3BlcmF0aW9u
cyBhcmUgbm90IGF0b21pYy4gVGhpcyBtZWFucyB0aGF0IEkvTyBlcnJvcnMg
KGFuZCwgZm9yDQojICAgIHRoYXQgbWF0dGVyLCBhbnkgZXhjZXB0aW9ucyBv
Y2N1cmVkIGluIF9maW5pc2gpIGxlYXZlIHRoZSBzdG9yYWdlIGluIGFuDQoj
ICAgIHVuZGVmaW5lZCBzdGF0ZQ0KIw0KIyBOb3QgY3JpdGljYWw6DQojICAg
IC0gUGVyZm9ybWFuY2UgdHVuaW5nIC0tIGFkZC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