1.1 --- a/WebStack/Repositories/Directory.py Tue Jun 12 23:51:27 2007 +0000
1.2 +++ b/WebStack/Repositories/Directory.py Tue Jun 12 23:51:49 2007 +0000
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Directory repositories for WebStack.
1.6
1.7 -Copyright (C) 2005, 2006 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This library is free software; you can redistribute it and/or
1.11 modify it under the terms of the GNU Lesser General Public
1.12 @@ -22,6 +22,7 @@
1.13
1.14 import os
1.15 import time
1.16 +import glob
1.17
1.18 class DirectoryRepository:
1.19
1.20 @@ -56,8 +57,7 @@
1.21
1.22 if not os.path.exists(path):
1.23 os.mkdir(path)
1.24 - f = open(self.full_path(self.new_filename), "wb")
1.25 - f.close()
1.26 + os.mkdir(self.full_path(self.new_filename))
1.27
1.28 # Guess the filesystem encoding.
1.29
1.30 @@ -207,15 +207,15 @@
1.31 try:
1.32 self.lock(self.new_filename)
1.33 except KeyError:
1.34 - f = open(self.edit_path(self.new_filename), "wb")
1.35 - f.close()
1.36 + os.mkdir(self.edit_path(self.new_filename))
1.37
1.38 try:
1.39 + os.mkdir(edit_path)
1.40 if opener is None:
1.41 - f = open(edit_path, "wb")
1.42 + f = open(os.path.join(edit_path, "data"), "wb")
1.43 f.close()
1.44 else:
1.45 - f = opener(edit_path)
1.46 + f = opener(os.path.join(edit_path, "data"))
1.47 f.close()
1.48 finally:
1.49 self.unlock(self.new_filename)
1.50 @@ -250,7 +250,9 @@
1.51 if os.path.exists(path) or os.path.exists(edit_path):
1.52 while 1:
1.53 try:
1.54 - os.remove(path)
1.55 + for filename in glob.glob(os.path.join(edit_path, "*")):
1.56 + os.remove(filename)
1.57 + os.rmdir(edit_path)
1.58 except OSError:
1.59 time.sleep(self.delay)
1.60 else:
1.61 @@ -264,7 +266,7 @@
1.62
1.63 edit_path = self.lock(key, create=0)
1.64 try:
1.65 - f = open(edit_path, "rb")
1.66 + f = open(os.path.join(edit_path, "data"), "rb")
1.67 s = ""
1.68 try:
1.69 s = f.read()
1.70 @@ -284,7 +286,7 @@
1.71
1.72 edit_path = self.lock(key, create=1)
1.73 try:
1.74 - f = open(edit_path, "wb")
1.75 + f = open(os.path.join(edit_path, "data"), "wb")
1.76 try:
1.77 f.write(value)
1.78 finally: