Commit 6ba02eba authored by 's avatar

merged fixes for MOVE, COPY Destination header handling

parent 2bf9a0b8
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""WebDAV support - resource objects.""" """WebDAV support - resource objects."""
__version__='$Revision: 1.40 $'[11:-2] __version__='$Revision: 1.41 $'[11:-2]
import sys, os, string, mimetypes, davcmds, ExtensionClass, Lockable import sys, os, string, mimetypes, davcmds, ExtensionClass, Lockable
from common import absattr, aq_base, urlfix, rfc1123_date, tokenFinder, urlbase from common import absattr, aq_base, urlfix, rfc1123_date, tokenFinder, urlbase
...@@ -339,20 +339,29 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem): ...@@ -339,20 +339,29 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
if not hasattr(aq_base(self), 'cb_isCopyable') or \ if not hasattr(aq_base(self), 'cb_isCopyable') or \
not self.cb_isCopyable(): not self.cb_isCopyable():
raise 'Method Not Allowed', 'This object may not be copied.' raise 'Method Not Allowed', 'This object may not be copied.'
depth=REQUEST.get_header('Depth', 'infinity') depth=REQUEST.get_header('Depth', 'infinity')
if not depth in ('0', 'infinity'): if not depth in ('0', 'infinity'):
raise 'Bad Request', 'Invalid Depth header.' raise 'Bad Request', 'Invalid Depth header.'
dest=REQUEST.get_header('Destination', '') dest=REQUEST.get_header('Destination', '')
while dest and dest[-1]=='/': while dest and dest[-1]=='/':
dest=dest[:-1] dest=dest[:-1]
if not dest: if not dest:
raise 'Bad Request', 'Invalid Destination header.' raise 'Bad Request', 'Invalid Destination header.'
path, (bad1, bad2, pct) = REQUEST.physicalPathFromURL(dest)
if pct < 1 or bad2:
raise 'Bad Request', 'Invalid Destination header'
name = path.pop()
parent_path = string.join(path, '/')
oflag=string.upper(REQUEST.get_header('Overwrite', 'F')) oflag=string.upper(REQUEST.get_header('Overwrite', 'F'))
if not oflag in ('T', 'F'): if not oflag in ('T', 'F'):
raise 'Bad Request', 'Invalid Overwrite header.' raise 'Bad Request', 'Invalid Overwrite header.'
path, name=os.path.split(dest)
name=unquote(name) try: parent=self.restrictedTraverse(path)
try: parent=REQUEST.resolve_url(path)
except ValueError: except ValueError:
raise 'Conflict', 'Attempt to copy to an unknown namespace.' raise 'Conflict', 'Attempt to copy to an unknown namespace.'
except 'Not Found': except 'Not Found':
...@@ -423,26 +432,27 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem): ...@@ -423,26 +432,27 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
if not hasattr(aq_base(self), 'cb_isMoveable') or \ if not hasattr(aq_base(self), 'cb_isMoveable') or \
not self.cb_isMoveable(): not self.cb_isMoveable():
raise 'Method Not Allowed', 'This object may not be moved.' raise 'Method Not Allowed', 'This object may not be moved.'
dest=REQUEST.get_header('Destination', '') dest=REQUEST.get_header('Destination', '')
while dest and dest[-1]=='/': path, (bad1, bad2, pct) = REQUEST.physicalPathFromURL(dest)
dest=dest[:-1] if pct < 1 or bad2:
if not dest:
raise 'Bad Request', 'No destination given' raise 'Bad Request', 'No destination given'
flag=REQUEST.get_header('Overwrite', 'F') flag=REQUEST.get_header('Overwrite', 'F')
flag=string.upper(flag) flag=string.upper(flag)
body=REQUEST.get('BODY', '')
path, name=os.path.split(dest) name = path.pop()
name=unquote(name) parent_path = string.join(path, '/')
try: parent=REQUEST.resolve_url(path)
try: parent = self.restrictedTraverse(path)
except ValueError: except ValueError:
raise 'Conflict', 'Attempt to move to an unknown namespace.' raise 'Conflict', 'Attempt to move to an unknown namespace.'
except 'Not Found': except 'Not Found':
raise 'Conflict', 'The resource %s must exist.' % path raise 'Conflict', 'The resource %s must exist.' % parent_path
except: except:
t, v, tb=sys.exc_info() t, v, tb=sys.exc_info()
raise t, v raise t, v
if hasattr(parent, '__null_resource__'): if hasattr(parent, '__null_resource__'):
raise 'Conflict', 'The resource %s must exist.' % path raise 'Conflict', 'The resource %s must exist.' % parent_path
existing=hasattr(aq_base(parent), name) existing=hasattr(aq_base(parent), name)
if existing and flag=='F': if existing and flag=='F':
raise 'Precondition Failed', 'Resource %s exists.' % dest raise 'Precondition Failed', 'Resource %s exists.' % dest
......
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