Skip to content

Commit

Permalink
Bugfix for root permission with empty S3 prefix and no metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
danilop committed Nov 15, 2013
1 parent b360a6c commit da49f16
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions yas3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,10 +1117,7 @@ def set_metadata(self, path, metadata_name=None, metadata_values=None, key=None)
logger.debug("writing metadata '%s' '%s'" % (path, key))
md = key.metadata
md['Content-Type'] = key.content_type # Otherwise we loose the Content-Type with S3 Copy
if key.size > 0:
key.copy(key.bucket.name, key.name, md, preserve_acl=False) # Do I need to preserve ACL?
else:
key.set_contents_from_string(''); # Better for empry objects ???
key.copy(key.bucket.name, key.name, md, preserve_acl=False) # Do I need to preserve ACL?
self.publish(['md', metadata_name, path])

def getattr(self, path, fh=None):
Expand Down Expand Up @@ -1163,6 +1160,7 @@ def readdir(self, path, fh=None):
dirs = self.cache.get(path, 'readdir')

if not dirs:
logger.debug("readdir '%s' '%s' no cache" % (path, fh))
full_path = self.join_prefix(path)
if full_path == '.':
full_path = ''
Expand All @@ -1174,11 +1172,14 @@ def readdir(self, path, fh=None):
for k in key_list:
d = k.name.encode('ascii')[len(full_path):]
if len(d) > 0:
if d == '.':
continue # already there ### Do I need this ???
if d[-1] == '/':
d = d[:-1]
dirs.append(d)
self.cache.set(path, 'readdir', dirs)

logger.debug("readdir '%s' '%s' '%s'" % (path, fh, dirs))
return dirs

def mkdir(self, path, mode):
Expand Down Expand Up @@ -1210,13 +1211,14 @@ def mkdir(self, path, mode):
full_path = path + '/'
else:
full_path = path # To manage '/' with an empty s3_prefix
k.key = self.join_prefix(full_path)
logger.debug("mkdir '%s' '%s' '%s' S3 " % (path, mode, k))
k.set_contents_from_string('', headers={'Content-Type': 'application/x-directory'})
if path != '/' or self.write_metadata:
k.key = self.join_prefix(full_path)
logger.debug("mkdir '%s' '%s' '%s' S3 " % (path, mode, k))
k.set_contents_from_string('', headers={'Content-Type': 'application/x-directory'})
self.cache.set(path, 'key', k)
data.delete('change')
self.cache.set(path, 'readdir', ['.', '..']) # the directory is empty
if path != '/':
self.cache.set(path, 'readdir', ['.', '..']) # the directory is empty
self.add_to_parent_readdir(path)
self.publish(['mkdir', path])
return 0
Expand Down

0 comments on commit da49f16

Please sign in to comment.