Skip to content

Commit da49f16

Browse files
committed
Bugfix for root permission with empty S3 prefix and no metadata
1 parent b360a6c commit da49f16

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

yas3fs.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,10 +1117,7 @@ def set_metadata(self, path, metadata_name=None, metadata_values=None, key=None)
11171117
logger.debug("writing metadata '%s' '%s'" % (path, key))
11181118
md = key.metadata
11191119
md['Content-Type'] = key.content_type # Otherwise we loose the Content-Type with S3 Copy
1120-
if key.size > 0:
1121-
key.copy(key.bucket.name, key.name, md, preserve_acl=False) # Do I need to preserve ACL?
1122-
else:
1123-
key.set_contents_from_string(''); # Better for empry objects ???
1120+
key.copy(key.bucket.name, key.name, md, preserve_acl=False) # Do I need to preserve ACL?
11241121
self.publish(['md', metadata_name, path])
11251122

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

11651162
if not dirs:
1163+
logger.debug("readdir '%s' '%s' no cache" % (path, fh))
11661164
full_path = self.join_prefix(path)
11671165
if full_path == '.':
11681166
full_path = ''
@@ -1174,11 +1172,14 @@ def readdir(self, path, fh=None):
11741172
for k in key_list:
11751173
d = k.name.encode('ascii')[len(full_path):]
11761174
if len(d) > 0:
1175+
if d == '.':
1176+
continue # already there ### Do I need this ???
11771177
if d[-1] == '/':
11781178
d = d[:-1]
11791179
dirs.append(d)
11801180
self.cache.set(path, 'readdir', dirs)
11811181

1182+
logger.debug("readdir '%s' '%s' '%s'" % (path, fh, dirs))
11821183
return dirs
11831184

11841185
def mkdir(self, path, mode):
@@ -1210,13 +1211,14 @@ def mkdir(self, path, mode):
12101211
full_path = path + '/'
12111212
else:
12121213
full_path = path # To manage '/' with an empty s3_prefix
1213-
k.key = self.join_prefix(full_path)
1214-
logger.debug("mkdir '%s' '%s' '%s' S3 " % (path, mode, k))
1215-
k.set_contents_from_string('', headers={'Content-Type': 'application/x-directory'})
1214+
if path != '/' or self.write_metadata:
1215+
k.key = self.join_prefix(full_path)
1216+
logger.debug("mkdir '%s' '%s' '%s' S3 " % (path, mode, k))
1217+
k.set_contents_from_string('', headers={'Content-Type': 'application/x-directory'})
12161218
self.cache.set(path, 'key', k)
12171219
data.delete('change')
1218-
self.cache.set(path, 'readdir', ['.', '..']) # the directory is empty
12191220
if path != '/':
1221+
self.cache.set(path, 'readdir', ['.', '..']) # the directory is empty
12201222
self.add_to_parent_readdir(path)
12211223
self.publish(['mkdir', path])
12221224
return 0

0 commit comments

Comments
 (0)