示例#1
0
 def move_properties(self, srcurl, desturl, withChildren, environ=None):
     _logger.debug("move_properties({}, {}, {})".format(
         srcurl, desturl, withChildren))
     self._lock.acquire_write()
     try:
         if __debug__ and self._verbose >= 4:
             self._check()
         if not self._loaded:
             self._lazy_open()
         if withChildren:
             # Move srcurl\*
             for url in self._dict.keys():
                 if util.is_equal_or_child_uri(srcurl, url):
                     d = url.replace(srcurl, desturl)
                     self._dict[d] = self._dict[url]
                     del self._dict[url]
         elif srcurl in self._dict:
             # Move srcurl only
             self._dict[desturl] = self._dict[srcurl]
             del self._dict[srcurl]
         self._sync()
         if __debug__ and self._verbose >= 4:
             self._check("after move")
     finally:
         self._lock.release()
示例#2
0
 def copy_move_single(self, dest_path, is_move):
     """See DAVResource.copy_move_single() """
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
     assert not util.is_equal_or_child_uri(self.path, dest_path)
     # Create destination collection, if not exists
     if not os.path.exists(fpDest):
         os.mkdir(fpDest)
     try:
         # may raise: [Error 5] Permission denied:
         # u'C:\\temp\\litmus\\ccdest'
         shutil.copystat(self._file_path, fpDest)
     except Exception:
         _logger.exception("Could not copy folder stats: {}".format(self._file_path))
     # (Live properties are copied by copy2 or copystat)
     # Copy dead properties
     propMan = self.provider.prop_manager
     if propMan:
         destRes = self.provider.get_resource_inst(dest_path, self.environ)
         if is_move:
             propMan.move_properties(
                 self.get_ref_url(),
                 destRes.get_ref_url(),
                 with_children=False,
                 environ=self.environ,
             )
         else:
             propMan.copy_properties(
                 self.get_ref_url(), destRes.get_ref_url(), self.environ
             )
示例#3
0
 def move_properties(self, src_url, dest_url, with_children, environ=None):
     _logger.debug(
         "move_properties({}, {}, {})".format(src_url, dest_url, with_children)
     )
     self._lock.acquire_write()
     try:
         if __debug__ and self._verbose >= 4:
             self._check()
         if not self._loaded:
             self._lazy_open()
         if with_children:
             # Move src_url\*
             for url in self._dict.keys():
                 if util.is_equal_or_child_uri(src_url, url):
                     d = url.replace(src_url, dest_url)
                     self._dict[d] = self._dict[url]
                     del self._dict[url]
         elif src_url in self._dict:
             # Move src_url only
             self._dict[dest_url] = self._dict[src_url]
             del self._dict[src_url]
         self._sync()
         if __debug__ and self._verbose >= 4:
             self._check("after move")
     finally:
         self._lock.release()
示例#4
0
 def copy_move_single(self, dest_path, is_move):
     """See DAVResource.copy_move_single() """
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
     assert not util.is_equal_or_child_uri(self.path, dest_path)
     # Create destination collection, if not exists
     if not os.path.exists(fpDest):
         os.mkdir(fpDest)
     try:
         # may raise: [Error 5] Permission denied:
         # u'C:\\temp\\litmus\\ccdest'
         shutil.copystat(self._file_path, fpDest)
     except Exception:
         _logger.exception("Could not copy folder stats: {}".format(self._file_path))
     # (Live properties are copied by copy2 or copystat)
     # Copy dead properties
     propMan = self.provider.prop_manager
     if propMan:
         destRes = self.provider.get_resource_inst(dest_path, self.environ)
         if is_move:
             propMan.move_properties(
                 self.get_ref_url(),
                 destRes.get_ref_url(),
                 with_children=False,
                 environ=self.environ,
             )
         else:
             propMan.copy_properties(
                 self.get_ref_url(), destRes.get_ref_url(), self.environ
             )
示例#5
0
 def copy_move_single(self, dest_path, is_move):
     """See _DAVResource.copy_move_single() """
     assert not util.is_equal_or_child_uri(self.path, dest_path)
     self._check_write_access()
     if self.is_collection:
         # Create destination collection, if not exists
         if not fire_fs.exists(dest_path):
             fire_fs.mkdir(dest_path)
     else:
         # Copy file (overwrite, if exists)
         # fire_fs.copyfile(self.path, dest_path)
         fire_fs.copyfile(self.path_entity, dest_path)
     # shutil.copy2(self._file_path, fpDest)
     # (Live properties are copied by copy2 or copystat)
     # Copy dead properties
     prop_man = self.provider.prop_manager
     if prop_man:
         dest_res = self.provider.get_resource_inst(dest_path, self.environ)
         if is_move:
             prop_man.move_properties(self.get_ref_url(),
                                      dest_res.get_ref_url(),
                                      with_children=False)
         else:
             prop_man.copy_properties(self.get_ref_url(),
                                      dest_res.get_ref_url())
示例#6
0
 def move_recursive(self, dest_path):
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
     assert not util.is_equal_or_child_uri(self.path, dest_path)
     _logger.debug("move_recursive({}, {})".format(self._file_path, fpDest))
     self.db.file_copy_form_bcdbfs(self._file_path, fpDest)
     self.db.file_delete(self._file_path)
示例#7
0
 def copy_move_single(self, dest_path, is_move):
     """See DAVResource.copy_move_single() """
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
     assert not util.is_equal_or_child_uri(self.path, dest_path)
     self.db.file_copy_form_bcdbfs(self._file_path, fpDest)
     if is_move:
         self.db.file_delete(self._file_path)
示例#8
0
    def copy_move_single(self, dest_path, is_move):
        """See DAVResource.copy_move_single() """
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)
        fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
        self.db.dir_copy_from_bcdbfs(self._file_path, dest_path)
        assert not util.is_equal_or_child_uri(self.path, dest_path)
        # Create destination collection, if not exists

        if is_move:
            self.db.dir_remove(self._file_path)
示例#9
0
 def copy_move_single(self, dest_davPath, is_move):
     """See DAVResource.copy_move_single() """
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     assert dest_davPath[0] == '/'
     assert not dest_davPath[-1] != '/'
     assert not util.is_equal_or_child_uri(self.davPath, dest_davPath)
     self.s3Client.copy_object(
         Bucket=self.provider.bucket,
         CopySource=self.provider.root_prefix + self.davPath[1:],
         Key=self.provider.root_prefix + dest_davPath[1:])
     if is_move:
         self.delete()
示例#10
0
 def move_recursive(self, destPath):
     """See DAVResource.move_recursive() """
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     fpDest = self.provider._loc_to_file_path(destPath, self.environ)
     assert not util.is_equal_or_child_uri(self.path, destPath)
     assert not os.path.exists(fpDest)
     _logger.debug("move_recursive({}, {})".format(self._filePath, fpDest))
     shutil.move(self._filePath, fpDest)
     # (Live properties are copied by copy2 or copystat)
     # Move dead properties
     if self.provider.propManager:
         destRes = self.provider.get_resource_inst(destPath, self.environ)
         self.provider.propManager.move_properties(self.get_ref_url(),
                                                   destRes.get_ref_url(),
                                                   withChildren=True,
                                                   environ=self.environ)
示例#11
0
 def move_recursive(self, dest_path):
     """See DAVResource.move_recursive() """
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
     assert not util.is_equal_or_child_uri(self.path, dest_path)
     assert not os.path.exists(fpDest)
     _logger.debug("move_recursive({}, {})".format(self._file_path, fpDest))
     shutil.move(self._file_path, fpDest)
     # (Live properties are copied by copy2 or copystat)
     # Move dead properties
     if self.provider.prop_manager:
         destRes = self.provider.get_resource_inst(dest_path, self.environ)
         self.provider.prop_manager.move_properties(
             self.get_ref_url(),
             destRes.get_ref_url(),
             with_children=True,
             environ=self.environ,
         )
示例#12
0
 def copy_move_single(self, destPath, isMove):
     """See DAVResource.copy_move_single() """
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     fpDest = self.provider._loc_to_file_path(destPath, self.environ)
     assert not util.is_equal_or_child_uri(self.path, destPath)
     # Copy file (overwrite, if exists)
     shutil.copy2(self._filePath, fpDest)
     # (Live properties are copied by copy2 or copystat)
     # Copy dead properties
     propMan = self.provider.propManager
     if propMan:
         destRes = self.provider.get_resource_inst(destPath, self.environ)
         if isMove:
             propMan.move_properties(self.get_ref_url(),
                                     destRes.get_ref_url(),
                                     withChildren=False,
                                     environ=self.environ)
         else:
             propMan.copy_properties(self.get_ref_url(),
                                     destRes.get_ref_url(), self.environ)
示例#13
0
    def testBasics(self):
        """Test basic tool functions."""
        assert join_uri("/a/b", "c") == "/a/b/c"
        assert join_uri("/a/b/", "c") == "/a/b/c"
        assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
        assert join_uri("a/b", "c", "d") == "a/b/c/d"
        assert join_uri("/", "c") == "/c"
        assert join_uri("", "c") == "/c"

        assert not is_child_uri("/a/b", "/a/")
        assert not is_child_uri("/a/b", "/a/b")
        assert not is_child_uri("/a/b", "/a/b/")
        assert not is_child_uri("/a/b", "/a/bc")
        assert not is_child_uri("/a/b", "/a/bc/")
        assert is_child_uri("/a/b", "/a/b/c")
        assert is_child_uri("/a/b", "/a/b/c")

        assert not is_equal_or_child_uri("/a/b", "/a/")
        assert is_equal_or_child_uri("/a/b", "/a/b")
        assert is_equal_or_child_uri("/a/b", "/a/b/")
        assert not is_equal_or_child_uri("/a/b", "/a/bc")
        assert not is_equal_or_child_uri("/a/b", "/a/bc/")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")

        assert lstripstr("/dav/a/b", "/dav") == "/a/b"
        assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b"
        assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b"

        assert pop_path("/a/b/c") == ("a", "/b/c")
        assert pop_path("/a/b/") == ("a", "/b/")
        assert pop_path("/a/") == ("a", "/")
        assert pop_path("/a") == ("a", "/")
        assert pop_path("/") == ("", "")
        assert pop_path("") == ("", "")

        self.assertEqual(shift_path("", "/a/b/c"), ("a", "/a", "/b/c"))
        self.assertEqual(shift_path("/a", "/b/c"), ("b", "/a/b", "/c"))
        self.assertEqual(shift_path("/a/b", "/c"), ("c", "/a/b/c", ""))
        self.assertEqual(shift_path("/a/b/c", "/"), ("", "/a/b/c", ""))
        self.assertEqual(shift_path("/a/b/c", ""), ("", "/a/b/c", ""))
示例#14
0
    def testBasics(self):
        """Test basic tool functions."""
        assert join_uri("/a/b", "c") == "/a/b/c"
        assert join_uri("/a/b/", "c") == "/a/b/c"
        assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
        assert join_uri("a/b", "c", "d") == "a/b/c/d"
        assert join_uri("/", "c") == "/c"
        assert join_uri("", "c") == "/c"

        assert not is_child_uri("/a/b", "/a/")
        assert not is_child_uri("/a/b", "/a/b")
        assert not is_child_uri("/a/b", "/a/b/")
        assert not is_child_uri("/a/b", "/a/bc")
        assert not is_child_uri("/a/b", "/a/bc/")
        assert is_child_uri("/a/b", "/a/b/c")
        assert is_child_uri("/a/b", "/a/b/c")

        assert not is_equal_or_child_uri("/a/b", "/a/")
        assert is_equal_or_child_uri("/a/b", "/a/b")
        assert is_equal_or_child_uri("/a/b", "/a/b/")
        assert not is_equal_or_child_uri("/a/b", "/a/bc")
        assert not is_equal_or_child_uri("/a/b", "/a/bc/")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")

        assert lstripstr("/dav/a/b", "/dav") == "/a/b"
        assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b"
        assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b"

        assert pop_path("/a/b/c") == ("a", "/b/c")
        assert pop_path("/a/b/") == ("a", "/b/")
        assert pop_path("/a/") == ("a", "/")
        assert pop_path("/a") == ("a", "/")
        assert pop_path("/") == ("", "")
        assert pop_path("") == ("", "")

        self.assertEqual(shift_path("", "/a/b/c"), ("a", "/a", "/b/c"))
        self.assertEqual(shift_path("/a", "/b/c"), ("b", "/a/b", "/c"))
        self.assertEqual(shift_path("/a/b", "/c"), ("c", "/a/b/c", ""))
        self.assertEqual(shift_path("/a/b/c", "/"), ("", "/a/b/c", ""))
        self.assertEqual(shift_path("/a/b/c", ""), ("", "/a/b/c", ""))
示例#15
0
 def copy_move_single(self, dest_path, is_move):
     """See DAVResource.copy_move_single() """
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
     assert not util.is_equal_or_child_uri(self.path, dest_path)
     # Copy file (overwrite, if exists)
     shutil.copy2(self._file_path, fpDest)
     # (Live properties are copied by copy2 or copystat)
     # Copy dead properties
     propMan = self.provider.prop_manager
     if propMan:
         destRes = self.provider.get_resource_inst(dest_path, self.environ)
         if is_move:
             propMan.move_properties(
                 self.get_ref_url(),
                 destRes.get_ref_url(),
                 with_children=False,
                 environ=self.environ,
             )
         else:
             propMan.copy_properties(
                 self.get_ref_url(), destRes.get_ref_url(), self.environ
             )
示例#16
0
 def is_url_locked_by_token(self, url, locktoken):
     """Check, if url (or any of it's parents) is locked by locktoken."""
     lockUrl = self.get_lock(locktoken, "root")
     return lockUrl and util.is_equal_or_child_uri(lockUrl, url)
示例#17
0
 def is_url_locked_by_token(self, url, lock_token):
     """Check, if url (or any of it's parents) is locked by lock_token."""
     lockUrl = self.get_lock(lock_token, "root")
     return lockUrl and util.is_equal_or_child_uri(lockUrl, url)