@@ -773,6 +773,7 @@ def destroy(self, path):
773773 self .cache_entries = 0 # To stop memory thread
774774 logger .info ("waiting for check cache thread to shutdown..." )
775775 self .check_cache_thread .join (self .cache_check_interval + 1.0 )
776+ logger .info ('File system unmounted.' )
776777
777778 def listen_for_messages_over_http (self ):
778779 logger .info ("Listening on: '%s'" % self .http_listen_url )
@@ -1003,7 +1004,10 @@ def reset_parent_readdir(self, path):
10031004
10041005 def join_prefix (self , path ):
10051006 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
10071011 else :
10081012 return self .s3_prefix + path
10091013
@@ -1015,7 +1019,7 @@ def get_key(self, path, cache=True):
10151019 return key
10161020 logger .debug ("get_key from S3 #1 '%s'" % (path ))
10171021 key = self .s3_bucket .get_key (self .join_prefix (path ))
1018- if not key :
1022+ if not key and path != '/' :
10191023 full_path = path + '/'
10201024 logger .debug ("get_key from S3 #2 '%s' '%s'" % (path , full_path ))
10211025 key = self .s3_bucket .get_key (self .join_prefix (full_path ))
@@ -1035,9 +1039,9 @@ def get_metadata(self, path, metadata_name, key=None):
10351039 if path == '/' : # First time mount of a new file system
10361040 ###self.cache.delete(path)
10371041 ###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)
10401043 self .mkdir (path , 0755 )
1044+ logger .debug ("get_metadata -> '%s' '%s' '%s' First time mount" % (path , metadata_name , key ))
10411045 return self .cache .get (path , metadata_name )
10421046 else :
10431047 full_path = self .join_prefix (path + '/' )
@@ -1097,6 +1101,7 @@ def set_metadata(self, path, metadata_name=None, metadata_values=None, key=None)
10971101 if self .write_metadata and (key or (not data ) or (data and not data .has ('change' ))): # No change in progress, I should write now
10981102 if not key :
10991103 key = self .get_key (path )
1104+ logger .debug ("set_metadata '%s' '%s' '%s' '%s' Key" % (path , metadata_name , metadata_values , key ))
11001105 if key :
11011106 if metadata_name :
11021107 values = metadata_values
@@ -1111,8 +1116,11 @@ def set_metadata(self, path, metadata_name=None, metadata_values=None, key=None)
11111116 if (not data ) or (data and (not data .has ('change' ))):
11121117 logger .debug ("writing metadata '%s' '%s'" % (path , key ))
11131118 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 ???
11161124 self .publish (['md' , metadata_name , path ])
11171125
11181126 def getattr (self , path , fh = None ):
@@ -1156,8 +1164,11 @@ def readdir(self, path, fh=None):
11561164
11571165 if not dirs :
11581166 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 ] != '/' :
11601170 full_path += '/'
1171+ logger .debug ("readdir '%s' '%s' S3 list '%s'" % (path , fh , full_path ))
11611172 key_list = self .s3_bucket .list (full_path , '/' )
11621173 dirs = ['.' , '..' ]
11631174 for k in key_list :
@@ -1195,12 +1206,17 @@ def mkdir(self, path, mode):
11951206 k = Key (self .s3_bucket )
11961207 self .set_metadata (path , 'attr' , attr , k )
11971208 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 ))
11991215 k .set_contents_from_string ('' , headers = {'Content-Type' : 'application/x-directory' })
12001216 self .cache .set (path , 'key' , k )
12011217 data .delete ('change' )
12021218 self .cache .set (path , 'readdir' , ['.' , '..' ]) # the directory is empty
1203- if path != '' :
1219+ if path != '/ ' :
12041220 self .add_to_parent_readdir (path )
12051221 self .publish (['mkdir' , path ])
12061222 return 0
0 commit comments