summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2009-06-07 07:44:41 +0000
committerrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2009-06-07 07:44:41 +0000
commitd871bc710b6a6295062fc9388b30c192d48196bc (patch)
tree9af3874c6754f366458675f34529d65dce0d9c4e
parent41fc61154b0e7977ffbe3a45115b564c38aa87e3 (diff)
downloadpyfilesystem-d871bc710b6a6295062fc9388b30c192d48196bc.tar.gz
fix bugs in S3FS when no prefix is specified
git-svn-id: http://pyfilesystem.googlecode.com/svn/branches/rfk-ideas@158 67cdc799-7952-0410-af00-57a81ceafa0f
-rw-r--r--fs/s3fs.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/fs/s3fs.py b/fs/s3fs.py
index a1cc233..949915f 100644
--- a/fs/s3fs.py
+++ b/fs/s3fs.py
@@ -118,7 +118,7 @@ class S3FS(FS):
path = relpath(path)
path = self._separator.join(iteratepath(path))
s3path = self._prefix + path
- if s3path[-1] == self._separator:
+ if s3path and s3path[-1] == self._separator:
s3path = s3path[:-1]
return s3path
@@ -234,7 +234,7 @@ class S3FS(FS):
"""Check whether a path exists and is a directory."""
s3path = self._s3path(path) + self._separator
# Root is always a directory
- if s3path == self._prefix:
+ if s3path == "/" or s3path == self._prefix:
return True
# Use a list request so that we return true if there are any files
# in that directory. This avoids requiring a special file for the
@@ -317,7 +317,9 @@ class S3FS(FS):
if allow_recreate:
return
raise DestinationExistsError(path, msg="Can not create a directory that already exists (try allow_recreate=True): %(path)s")
- s3pathP = self._s3path(dirname(path)) + self._separator
+ s3pathP = self._s3path(dirname(path))
+ if s3pathP:
+ s3pathP = s3pathP + self._separator
# Check various preconditions using list of parent dir
ks = self._s3bukt.list(prefix=s3pathP,delimiter=self._separator)
if s3pathP == self._prefix:
@@ -363,7 +365,9 @@ class S3FS(FS):
def removedir(self,path,recursive=False,force=False):
"""Remove the directory at the given path."""
- s3path = self._s3path(path) + self._separator
+ s3path = self._s3path(path)
+ if s3path != self._prefix:
+ s3path = s3path + self._separator
if force:
# If we will be forcibly removing any directory contents, we
# might as well get the un-delimited list straight away.
@@ -399,11 +403,17 @@ class S3FS(FS):
def getinfo(self,path):
s3path = self._s3path(path)
+ if path in ("","/"):
+ return {}
k = self._s3bukt.get_key(s3path)
+ if k is None:
+ raise ResourceNotFoundError(path)
info = {}
- info['size'] = int(k.size)
+ if hasattr(k,"size"):
+ info['size'] = int(k.size)
fmt = "%a, %d %b %Y %H:%M:%S %Z"
- info['modified_time'] = datetime.datetime.strptime(k.last_modified,fmt)
+ if hasattr(k,"last_modified"):
+ info['modified_time'] = datetime.datetime.strptime(k.last_modified,fmt)
return info
def desc(self,path):