@@ -773,6 +773,7 @@ def destroy(self, path):
773
773
self .cache_entries = 0 # To stop memory thread
774
774
logger .info ("waiting for check cache thread to shutdown..." )
775
775
self .check_cache_thread .join (self .cache_check_interval + 1.0 )
776
+ logger .info ('File system unmounted.' )
776
777
777
778
def listen_for_messages_over_http (self ):
778
779
logger .info ("Listening on: '%s'" % self .http_listen_url )
@@ -1003,7 +1004,10 @@ def reset_parent_readdir(self, path):
1003
1004
1004
1005
def join_prefix (self , path ):
1005
1006
if self .s3_prefix == '' :
1006
- return path [1 :] # Remove beginning "/"
1007
+ if path != '/' :
1008
+ return path [1 :] # Remove beginning '/'
1009
+ else :
1010
+ return '.' # To handle '/' with empty s3_prefix
1007
1011
else :
1008
1012
return self .s3_prefix + path
1009
1013
@@ -1015,7 +1019,7 @@ def get_key(self, path, cache=True):
1015
1019
return key
1016
1020
logger .debug ("get_key from S3 #1 '%s'" % (path ))
1017
1021
key = self .s3_bucket .get_key (self .join_prefix (path ))
1018
- if not key :
1022
+ if not key and path != '/' :
1019
1023
full_path = path + '/'
1020
1024
logger .debug ("get_key from S3 #2 '%s' '%s'" % (path , full_path ))
1021
1025
key = self .s3_bucket .get_key (self .join_prefix (full_path ))
@@ -1035,9 +1039,9 @@ def get_metadata(self, path, metadata_name, key=None):
1035
1039
if path == '/' : # First time mount of a new file system
1036
1040
###self.cache.delete(path)
1037
1041
###self.mkdir('', 0755)
1038
- #self.cache.rename('', path)
1039
- logger .debug ("get_metadata -> '%s' '%s' '%s' First time mount" % (path , metadata_name , key ))
1042
+ ###self.cache.rename('', path)
1040
1043
self .mkdir (path , 0755 )
1044
+ logger .debug ("get_metadata -> '%s' '%s' '%s' First time mount" % (path , metadata_name , key ))
1041
1045
return self .cache .get (path , metadata_name )
1042
1046
else :
1043
1047
full_path = self .join_prefix (path + '/' )
@@ -1097,6 +1101,7 @@ def set_metadata(self, path, metadata_name=None, metadata_values=None, key=None)
1097
1101
if self .write_metadata and (key or (not data ) or (data and not data .has ('change' ))): # No change in progress, I should write now
1098
1102
if not key :
1099
1103
key = self .get_key (path )
1104
+ logger .debug ("set_metadata '%s' '%s' '%s' '%s' Key" % (path , metadata_name , metadata_values , key ))
1100
1105
if key :
1101
1106
if metadata_name :
1102
1107
values = metadata_values
@@ -1111,8 +1116,11 @@ def set_metadata(self, path, metadata_name=None, metadata_values=None, key=None)
1111
1116
if (not data ) or (data and (not data .has ('change' ))):
1112
1117
logger .debug ("writing metadata '%s' '%s'" % (path , key ))
1113
1118
md = key .metadata
1114
- md ['Content-Type' ] = key .content_type # Otherwise we loose the Content-Type with Copy
1115
- key .copy (key .bucket .name , key .name , md , preserve_acl = True ) # Do I need to preserve ACL?
1119
+ 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 ???
1116
1124
self .publish (['md' , metadata_name , path ])
1117
1125
1118
1126
def getattr (self , path , fh = None ):
@@ -1156,8 +1164,11 @@ def readdir(self, path, fh=None):
1156
1164
1157
1165
if not dirs :
1158
1166
full_path = self .join_prefix (path )
1159
- if full_path != '' and full_path [- 1 ] != '/' :
1167
+ if full_path == '.' :
1168
+ full_path = ''
1169
+ elif full_path != '' and full_path [- 1 ] != '/' :
1160
1170
full_path += '/'
1171
+ logger .debug ("readdir '%s' '%s' S3 list '%s'" % (path , fh , full_path ))
1161
1172
key_list = self .s3_bucket .list (full_path , '/' )
1162
1173
dirs = ['.' , '..' ]
1163
1174
for k in key_list :
@@ -1195,12 +1206,17 @@ def mkdir(self, path, mode):
1195
1206
k = Key (self .s3_bucket )
1196
1207
self .set_metadata (path , 'attr' , attr , k )
1197
1208
self .set_metadata (path , 'xattr' , {}, k )
1198
- k .key = self .join_prefix (path + '/' )
1209
+ if path != '/' :
1210
+ full_path = path + '/'
1211
+ else :
1212
+ 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 ))
1199
1215
k .set_contents_from_string ('' , headers = {'Content-Type' : 'application/x-directory' })
1200
1216
self .cache .set (path , 'key' , k )
1201
1217
data .delete ('change' )
1202
1218
self .cache .set (path , 'readdir' , ['.' , '..' ]) # the directory is empty
1203
- if path != '' :
1219
+ if path != '/ ' :
1204
1220
self .add_to_parent_readdir (path )
1205
1221
self .publish (['mkdir' , path ])
1206
1222
return 0
0 commit comments