Example #1
0
  def _copy(self, src, dst, recursive, use_src_basename):
    src_st = self.stats(src)
    if src_st.isDir and not recursive:
      return # omitting directory

    dst = s3.abspath(src, dst)
    dst_st = self._stats(dst)
    if src_st.isDir and dst_st and not dst_st.isDir:
      raise IOError(errno.EEXIST, "Cannot overwrite non-directory '%s' with directory '%s'" % (dst, src))

    src_bucket, src_key = s3.parse_uri(src)[:2]
    dst_bucket, dst_key = s3.parse_uri(dst)[:2]

    keep_src_basename = use_src_basename and dst_st and dst_st.isDir
    src_bucket = self._get_bucket(src_bucket)
    dst_bucket = self._get_bucket(dst_bucket)

    if keep_src_basename:
      cut = len(posixpath.dirname(src_key))  # cut of an parent directory name
      if cut:
        cut += 1
    else:
      cut = len(src_key)
      if not src_key.endswith('/'):
        cut += 1

    for key in src_bucket.list(prefix=src_key):
      if not key.name.startswith(src_key):
        raise RuntimeError(_("Invalid key to transform: %s") % key.name)
      dst_name = posixpath.normpath(s3.join(dst_key, key.name[cut:]))
      key.copy(dst_bucket, dst_name)
Example #2
0
  def _copy(self, src, dst, recursive, use_src_basename):
    src_st = self.stats(src)
    if src_st.isDir and not recursive:
      return # omitting directory

    dst = s3.abspath(src, dst)
    dst_st = self._stats(dst)
    if src_st.isDir and dst_st and not dst_st.isDir:
      raise S3FileSystemException("Cannot overwrite non-directory '%s' with directory '%s'" % (dst, src))

    src_bucket, src_key = s3.parse_uri(src)[:2]
    dst_bucket, dst_key = s3.parse_uri(dst)[:2]

    keep_src_basename = use_src_basename and dst_st and dst_st.isDir
    src_bucket = self._get_bucket(src_bucket)
    dst_bucket = self._get_bucket(dst_bucket)

    if keep_src_basename:
      cut = len(posixpath.dirname(src_key))  # cut of an parent directory name
      if cut:
        cut += 1
    else:
      cut = len(src_key)
      if not src_key.endswith('/'):
        cut += 1

    for key in src_bucket.list(prefix=src_key):
      if not key.name.startswith(src_key):
        raise S3FileSystemException(_("Invalid key to transform: %s") % key.name)
      dst_name = posixpath.normpath(s3.join(dst_key, key.name[cut:]))

      if self.isdir(normpath(self.join(S3A_ROOT, key.bucket.name, key.name))):
        dst_name = self._append_separator(dst_name)

      key.copy(dst_bucket, dst_name)
Example #3
0
  def _copy(self, src, dst, recursive, use_src_basename):
    src_st = self.stats(src)
    if src_st.isDir and not recursive:
      return # omitting directory

    dst = s3.abspath(src, dst)
    dst_st = self._stats(dst)
    if src_st.isDir and dst_st and not dst_st.isDir:
      raise S3FileSystemException("Cannot overwrite non-directory '%s' with directory '%s'" % (dst, src))

    src_bucket, src_key = s3.parse_uri(src)[:2]
    dst_bucket, dst_key = s3.parse_uri(dst)[:2]

    keep_src_basename = use_src_basename and dst_st and dst_st.isDir
    src_bucket = self._get_bucket(src_bucket)
    dst_bucket = self._get_bucket(dst_bucket)

    if keep_src_basename:
      cut = len(posixpath.dirname(src_key))  # cut of an parent directory name
      if cut:
        cut += 1
    else:
      cut = len(src_key)
      if not src_key.endswith('/'):
        cut += 1

    for key in src_bucket.list(prefix=src_key):
      if not key.name.startswith(src_key):
        raise S3FileSystemException(_("Invalid key to transform: %s") % key.name)
      dst_name = posixpath.normpath(s3.join(dst_key, key.name[cut:]))

      if self.isdir(normpath(self.join(S3A_ROOT, key.bucket.name, key.name))):
        dst_name = self._append_separator(dst_name)

      key.copy(dst_bucket, dst_name)
Example #4
0
File: s3fs.py Project: igloosec/hue
    def _copy(self, src, dst, recursive, use_src_basename):
        src_st = self.stats(src)
        if src_st.isDir and not recursive:
            return  # omitting directory

        dst = s3.abspath(src, dst)
        dst_st = self._stats(dst)
        if src_st.isDir and dst_st and not dst_st.isDir:
            raise IOError(
                errno.EEXIST,
                "Cannot overwrite non-directory '%s' with directory '%s'" %
                (dst, src))

        src_bucket, src_key = s3.parse_uri(src)[:2]
        dst_bucket, dst_key = s3.parse_uri(dst)[:2]

        keep_src_basename = use_src_basename and dst_st and dst_st.isDir
        src_bucket = self._get_bucket(src_bucket)
        dst_bucket = self._get_bucket(dst_bucket)

        if keep_src_basename:
            cut = len(
                posixpath.dirname(src_key))  # cut of an parent directory name
            if cut:
                cut += 1
        else:
            cut = len(src_key)
            if not src_key.endswith('/'):
                cut += 1

        for key in src_bucket.list(prefix=src_key):
            if not key.name.startswith(src_key):
                raise RuntimeError("Invalid key to transform: %s" % key.name)
            dst_name = posixpath.normpath(s3.join(dst_key, key.name[cut:]))
            key.copy(dst_bucket, dst_name)
Example #5
0
 def parent_path(path):
     parent_dir = S3FileSystem._append_separator(path)
     if not s3.is_root(parent_dir):
         bucket_name, key_name, basename = s3.parse_uri(path)
         if not basename:  # bucket is top-level so return root
             parent_dir = S3A_ROOT
         else:
             bucket_path = '%s%s' % (S3A_ROOT, bucket_name)
             key_path = '/'.join(key_name.split('/')[:-1])
             parent_dir = s3.abspath(bucket_path, key_path)
     return parent_dir
Example #6
0
 def parent_path(path):
   parent_dir = S3FileSystem._append_separator(path)
   if not s3.is_root(parent_dir):
     bucket_name, key_name, basename = s3.parse_uri(path)
     if not basename:  # bucket is top-level so return root
       parent_dir = S3_ROOT
     else:
       bucket_path = '%s%s' % (S3_ROOT, bucket_name)
       key_path = '/'.join(key_name.split('/')[:-1])
       parent_dir = s3.abspath(bucket_path, key_path)
   return parent_dir
Example #7
0
 def rename(self, old, new):
     new = s3.abspath(old, new)
     self.copy(old, new, recursive=True)
     self.rmtree(old, skipTrash=True)
Example #8
0
 def rename(self, old, new):
     new = s3.abspath(old, new)
     self.copy(old, new, recursive=True)
     if self.isdir(old):
         self.rename_star(old, new)
     self.rmtree(old, skipTrash=True)
Example #9
0
 def rename(self, old, new):
   new = s3.abspath(old, new)
   self.copy(old, new, recursive=True)
   self.rmtree(old, skipTrash=True)
Example #10
0
 def rename(self, old, new):
   new = s3.abspath(old, new)
   self.copy(old, new, recursive=True)
   if self.isdir(old):
     self.rename_star(old, new)
   self.rmtree(old, skipTrash=True)