Commit 24b1f8a9 authored by Jim Fulton's avatar Jim Fulton

Fixed numerous windows issues

parent 1c2e2768
...@@ -298,7 +298,7 @@ class FilesystemHelper: ...@@ -298,7 +298,7 @@ class FilesystemHelper:
# want to perform blob storage differently. # want to perform blob storage differently.
def __init__(self, base_dir, layout_name='automatic'): def __init__(self, base_dir, layout_name='automatic'):
self.base_dir = os.path.normpath(base_dir) + '/' self.base_dir = os.path.normpath(base_dir) + os.path.sep
self.temp_dir = os.path.join(base_dir, 'tmp') self.temp_dir = os.path.join(base_dir, 'tmp')
if layout_name == 'automatic': if layout_name == 'automatic':
...@@ -488,8 +488,8 @@ class BushyLayout(object): ...@@ -488,8 +488,8 @@ class BushyLayout(object):
""" """
blob_path_pattern = r'^' + (r'0x[0-9a-f]{1,2}/*'*8) + r'$' blob_path_pattern = re.compile(
blob_path_pattern = re.compile(blob_path_pattern) r'(0x[0-9a-f]{1,2}\%s){7,7}0x[0-9a-f]{1,2}$' % os.path.sep)
def oid_to_path(self, oid): def oid_to_path(self, oid):
directories = [] directories = []
...@@ -497,12 +497,12 @@ class BushyLayout(object): ...@@ -497,12 +497,12 @@ class BushyLayout(object):
# first # first
for byte in str(oid): for byte in str(oid):
directories.append('0x%s' % binascii.hexlify(byte)) directories.append('0x%s' % binascii.hexlify(byte))
return '/'.join(directories) return os.path.sep.join(directories)
def path_to_oid(self, path): def path_to_oid(self, path):
if self.blob_path_pattern.match(path) is None: if self.blob_path_pattern.match(path) is None:
raise ValueError("Not a valid OID path: `%s`" % path) raise ValueError("Not a valid OID path: `%s`" % path)
path = path.split('/') path = path.split(os.path.sep)
# Each path segment stores a byte in hex representation. Turn it into # Each path segment stores a byte in hex representation. Turn it into
# an int and then get the character for our byte string. # an int and then get the character for our byte string.
oid = ''.join(binascii.unhexlify(byte[2:]) for byte in path) oid = ''.join(binascii.unhexlify(byte[2:]) for byte in path)
......
...@@ -146,7 +146,7 @@ revision as well as the entire directory: ...@@ -146,7 +146,7 @@ revision as well as the entire directory:
Clean up our blob directory and database: Clean up our blob directory and database:
>>> shutil.rmtree(blob_dir) >>> rmtree(blob_dir)
>>> base_storage.close() >>> base_storage.close()
>>> os.unlink(storagefile) >>> os.unlink(storagefile)
>>> os.unlink(storagefile+".index") >>> os.unlink(storagefile+".index")
...@@ -273,4 +273,4 @@ knowledge that the underlying storage's pack method is also called: ...@@ -273,4 +273,4 @@ knowledge that the underlying storage's pack method is also called:
Clean up our blob directory: Clean up our blob directory:
>>> shutil.rmtree(blob_dir) >>> rmtree(blob_dir)
...@@ -381,6 +381,5 @@ We don't need the storage directory and databases anymore:: ...@@ -381,6 +381,5 @@ We don't need the storage directory and databases anymore::
>>> tm1.abort() >>> tm1.abort()
>>> tm2.abort() >>> tm2.abort()
>>> database.close() >>> database.close()
>>> import shutil >>> rmtree(blob_dir)
>>> shutil.rmtree(blob_dir) >>> rmtree(blob_dir2)
>>> shutil.rmtree(blob_dir2)
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
############################################################################## ##############################################################################
import base64, os, re, shutil, tempfile, unittest import base64, os, re, shutil, stat, sys, tempfile, unittest
import time import time
from zope.testing import doctest, renormalizing from zope.testing import doctest, renormalizing
import ZODB.tests.util import ZODB.tests.util
...@@ -473,6 +473,11 @@ def secure_blob_directory(): ...@@ -473,6 +473,11 @@ def secure_blob_directory():
""" """
# On windows, we can't create secure blob directories, at least not
# with APIs in the standard library, so there's no point in testing
# this.
if sys.platform == 'win32':
del secure_blob_directory
def loadblob_tmpstore(): def loadblob_tmpstore():
""" """
...@@ -520,13 +525,26 @@ def loadblob_tmpstore(): ...@@ -520,13 +525,26 @@ def loadblob_tmpstore():
>>> database.close() >>> database.close()
>>> import shutil >>> import shutil
>>> shutil.rmtree(blob_dir) >>> rmtree(blob_dir)
>>> os.unlink(storagefile) >>> os.unlink(storagefile)
>>> os.unlink(storagefile+".index") >>> os.unlink(storagefile+".index")
>>> os.unlink(storagefile+".tmp") >>> os.unlink(storagefile+".tmp")
""" """
def setUp(test):
ZODB.tests.util.setUp(test)
def rmtree(path):
for path, dirs, files in os.walk(path, False):
for fname in files:
fname = os.path.join(path, fname)
os.chmod(fname, stat.S_IWUSR)
os.remove(fname)
for dname in dirs:
dname = os.path.join(path, dname)
os.rmdir(dname)
test.globs['rmtree'] = rmtree
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
...@@ -536,22 +554,26 @@ def test_suite(): ...@@ -536,22 +554,26 @@ def test_suite():
"blob_packing.txt", "blob_importexport.txt", "blob_consume.txt", "blob_packing.txt", "blob_importexport.txt", "blob_consume.txt",
"blob_tempdir.txt", "blob_tempdir.txt",
optionflags=doctest.ELLIPSIS, optionflags=doctest.ELLIPSIS,
setUp=ZODB.tests.util.setUp, setUp=setUp,
tearDown=ZODB.tests.util.tearDown, tearDown=ZODB.tests.util.tearDown,
)) ))
suite.addTest(doctest.DocFileSuite( suite.addTest(doctest.DocFileSuite(
"blob_layout.txt", "blob_layout.txt",
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE, optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
setUp=ZODB.tests.util.setUp, setUp=setUp,
tearDown=ZODB.tests.util.tearDown, tearDown=ZODB.tests.util.tearDown,
checker = renormalizing.RENormalizing([ checker = renormalizing.RENormalizing([
(re.compile(r'[%(sep)s]' % dict(sep=os.path.sep)), '/'), (re.compile(r'\%(sep)s' % dict(sep=os.path.sep)), '/'),
(re.compile(r'\S+/((old|bushy|lawn)/\S+/foo[23456]?)'), r'\1'), (re.compile(r'\S+/((old|bushy|lawn)/\S+/foo[23456]?)'), r'\1'),
]), ]),
)) ))
suite.addTest(doctest.DocTestSuite( suite.addTest(doctest.DocTestSuite(
setUp=ZODB.tests.util.setUp, setUp=setUp,
tearDown=ZODB.tests.util.tearDown, tearDown=ZODB.tests.util.tearDown,
checker = renormalizing.RENormalizing([
(re.compile(r'\%(sep)s\%(sep)s' % dict(sep=os.path.sep)), '/'),
(re.compile(r'\%(sep)s' % dict(sep=os.path.sep)), '/'),
]),
)) ))
suite.addTest(unittest.makeSuite(BlobUndoTests)) suite.addTest(unittest.makeSuite(BlobUndoTests))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment