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)
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)
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)
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
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
def rename(self, old, new): new = s3.abspath(old, new) self.copy(old, new, recursive=True) self.rmtree(old, skipTrash=True)
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)