[Zope-CVS] CVS: Products/Ape/lib/apelib/fs - connection.py:1.7.2.2
interfaces.py:1.4.2.2 structure.py:1.7.2.2
Shane Hathaway
shane at zope.com
Wed Feb 25 22:09:26 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/fs
In directory cvs.zope.org:/tmp/cvs-serv4850/lib/apelib/fs
Modified Files:
Tag: ape-fs-oid-branch
connection.py interfaces.py structure.py
Log Message:
Fixed bugs. All automated tests pass with the new filesystem OID code.
With this working, the _setOb patch became unnecessary. The TmpStore
monkey patch is also obsolete. Only one patch remains, and it's not
much of a problem. Yay!
=== Products/Ape/lib/apelib/fs/connection.py 1.7.2.1 => 1.7.2.2 ===
--- Products/Ape/lib/apelib/fs/connection.py:1.7.2.1 Wed Feb 25 11:03:28 2004
+++ Products/Ape/lib/apelib/fs/connection.py Wed Feb 25 22:08:54 2004
@@ -152,7 +152,7 @@
contents = self.afs.computeContents(dir_path)
fn_to_name, name_to_fn = contents
existing = self.table.getChildren(oid)
- for name, child_oid in children.items():
+ for name, child_oid in children:
assert child_oid
if existing.has_key(name) and existing[name] != child_oid:
raise FSReadError("assignNew() doesn't change existing OIDs")
@@ -293,7 +293,7 @@
new_filenames = {}
for objname, child_oid in data:
filename = objname
- if not reserved.has_key(objname):
+ if '.' not in filename and not reserved.has_key(objname):
# This object is eligible for an automatic extension.
fn = existing.get(objname)
if fn:
@@ -452,24 +452,37 @@
script.append(("clearTemp",))
return script
+ def _rmrf(self, path):
+ """Delete ala 'rm -rf'.
+
+ If it's a file, remove it. If it's a directory, remove all of it.
+ If it doesn't exist, quietly ignore it.
+ """
+ ops = self.ops
+ if ops.exists(path):
+ if ops.isdir(path):
+ ops.rmtree(path)
+ else:
+ ops.remove(path)
+
def _do_clearTemp(self):
"""Script command: zap the temporary directory.
"""
ops = self.ops
path = ops.join(self.basepath, '_tmp')
- if ops.exists(path):
- self.ops.rmtree(path)
+ self._rmrf(path)
self._tmp_subpaths.clear()
- def _moveContents(self, src, dest):
- """Move a directory's contents, but not the directory.
+ def _moveAppContents(self, src, dest):
+ """Move the application directory's contents, but not the directory.
Also leaves behind any file whose name starts with an underscore.
"""
ops = self.ops
- ops.makedirs(dest)
+ if not ops.exists(dest):
+ ops.makedirs(dest)
for fn in ops.listdir(src):
- if not fn.startswith('_'):
+ if fn not in ('_root', '_tmp'):
ops.rename(ops.join(src, fn), ops.join(dest, fn))
def _moveItem(self, src, dest):
@@ -477,7 +490,10 @@
For files, also moves annotations next to the file.
"""
- ops.makedirs(ops.dirname(dest))
+ ops = self.ops
+ parent = ops.dirname(dest)
+ if not ops.exists(parent):
+ ops.makedirs(parent)
if not ops.isdir(src):
# Move the annotation files also.
extra_src = self.afs.getAnnotationPaths(src)
@@ -491,13 +507,13 @@
"""Script command: move an object to the temporary directory.
"""
ops = self.ops
- path = self.getPath(oid)
- if path == self.basepath:
+ src = self.getPath(oid)
+ if src == self.basepath:
# Move the application root by moving most of the contents
# instead of the actual directory.
dest_sub = ('_tmp', 'app', 'data')
dest = ops.join(self.basepath, *dest_sub)
- self._moveContents(src, dest)
+ self._moveAppContents(src, dest)
else:
# Move an object.
dest_sub = ('_tmp', 'oid.%s' % oid, 'data')
@@ -514,9 +530,9 @@
ops = self.ops
dest = self.getPath(oid)
src_sub = self._tmp_subpaths[oid]
- src = ops.join(self.basepath, src_sub)
+ src = ops.join(self.basepath, *src_sub)
if dest == self.basepath:
- self._moveContents(src, dest)
+ self._moveAppContents(src, dest)
else:
self._moveItem(src, dest)
del self._tmp_subpaths[oid]
@@ -530,7 +546,7 @@
# Delete the application root.
for fn in ops.listdir(path):
if not fn.startswith('_'):
- ops.rmtree(ops.join(self.basepath, fn))
+ self._rmrf(ops.join(self.basepath, fn))
else:
# Delete an object.
if not ops.isdir(path):
@@ -538,8 +554,8 @@
extra = self.afs.getAnnotationPaths(path)
for s in extra:
if ops.exists(s):
- ops.rmtree(s)
- ops.rmtree(path)
+ ops.remove(s)
+ self._rmrf(path)
if self._tmp_subpaths.has_key(oid):
del self._tmp_subpaths[oid]
parents = self.table.getParents(oid)
@@ -633,8 +649,9 @@
return self.basepath
def connect(self):
- if not self.ops.exists(self.basepath):
- self.ops.makedirs(self.basepath)
+ ops = self.ops
+ if not ops.exists(self.basepath):
+ ops.makedirs(self.basepath)
def begin(self):
self.afs.clearCache()
=== Products/Ape/lib/apelib/fs/interfaces.py 1.4.2.1 => 1.4.2.2 ===
--- Products/Ape/lib/apelib/fs/interfaces.py:1.4.2.1 Wed Feb 25 11:03:28 2004
+++ Products/Ape/lib/apelib/fs/interfaces.py Wed Feb 25 22:08:54 2004
@@ -75,7 +75,7 @@
def assignNew(oid, children):
"""Assigns OIDs to newly found objects.
- See readDirectory().
+ See readDirectory(). children is a list of (object_name, child_oid).
"""
def getExtension(oid):
=== Products/Ape/lib/apelib/fs/structure.py 1.7.2.1 => 1.7.2.2 ===
--- Products/Ape/lib/apelib/fs/structure.py:1.7.2.1 Wed Feb 25 11:03:28 2004
+++ Products/Ape/lib/apelib/fs/structure.py Wed Feb 25 22:08:54 2004
@@ -56,7 +56,8 @@
class FSAutoId (FSGatewayBase):
- """Automatic ID gateway based on the key of the item."""
+ """Automatic ID gateway based on the object name in the primary parent.
+ """
__implements__ = IGateway
@@ -64,11 +65,12 @@
def load(self, event):
id = self.getConnection(event).readObjectName(event.oid)
- return id, id
+ # Disable conflict checking by returning None as the hash value.
+ return id, None
def store(self, event, state):
# Ignore.
- return state
+ return None
def getPollSources(self, event):
fs_conn = self.getConnection(event)
@@ -91,18 +93,23 @@
raise LoadError("Not a directory")
data = list(c.readDirectory(event.oid))
data.sort()
- res = []
- assigned = []
+ # Assign new OIDs.
+ assigned = {}
for objname, child_oid in data:
if child_oid is None:
child_oid = event.conf.oid_gen.new_oid(event, objname, True)
- assigned.append((objname, child_oid))
+ assigned[objname] = child_oid
+ if assigned:
+ # Saw new objects. Tell the connection what their OIDs are.
+ c.assignNew(event.oid, assigned.items())
+ # Return the results.
+ res = []
+ for objname, child_oid in data:
+ if child_oid is None:
+ child_oid = assigned[objname]
classification = event.classify(child_oid)
# Return info about each subobject.
res.append((objname, child_oid, classification))
- if assigned:
- # Saw new objects. Tell the connection what their OIDs are.
- c.assignNew(event.oid, assigned)
return res, tuple(data)
def store(self, event, state):
More information about the Zope-CVS
mailing list