@@ -249,35 +249,38 @@ def _transfer_bg_thread(
249249 """
250250 self .logger .info (f"Writing image to storage in the background: { src_path } " )
251251 try :
252+ filename = Path (src_path ).name if isinstance (src_path , (str , os .PathLike )) else src_path .name
253+
252254 # if the source is a local file, we can hash it and compare to the known hash
253255 if src_operator_scheme == "fs" :
254256 file_hash = self ._sha256_file (src_operator , src_path )
255- if to_storage .hash ( src_path . name ) == file_hash :
256- self .logger .info (f"Image { src_path } already exists in storage with matching hash, skipping" )
257+ if to_storage .exists ( filename ) and to_storage . hash ( filename ) == file_hash :
258+ self .logger .info (f"Image { filename } already exists in storage with matching hash, skipping" )
257259 return
260+
258261 # if the source is a remote file, we can't hash it, so we need to check the hash from the metadata
259- elif known_hash and to_storage .exists (src_path . name ):
260- self .logger .info (f"Image { src_path } already exists in storage, checking hash" )
261- if to_storage .hash (src_path . name ) == known_hash :
262- self .logger .info (f"Image { src_path } already exists in storage with matching hash, skipping" )
262+ elif known_hash and to_storage .exists (filename ):
263+ self .logger .info (f"Image { filename } already exists in storage, checking hash" )
264+ if to_storage .hash (filename ) == known_hash :
265+ self .logger .info (f"Image { filename } already exists in storage with matching hash, skipping" )
263266 return
264267
265268 # last attempt to check if the image in storage matches the known metadata
266269 metadata , metadata_json = self ._create_metadata_and_json (src_operator , src_path )
267- metadata_file = src_path . name + ".metadata"
270+ metadata_file = filename + ".metadata"
268271 self .logger .info (f"Metadata: { metadata_json } " )
269- if to_storage .exists (metadata_file ) and to_storage .exists (src_path . name ):
272+ if to_storage .exists (metadata_file ) and to_storage .exists (filename ):
270273 self .logger .info (f"Checking metadata for file in exporter storage { metadata_file } " )
271274 data = to_storage .read_bytes (metadata_file ).decode (errors = "ignore" )
272- if to_storage .stat (src_path . name ).content_length == metadata .content_length and data == metadata_json :
273- self .logger .info (f"Image { src_path } already exists in storage with matching metadata, skipping" )
275+ if to_storage .stat (filename ).content_length == metadata .content_length and data == metadata_json :
276+ self .logger .info (f"Image { filename } already exists in storage with matching metadata, skipping" )
274277 return
275278
276279 # ok, we need to write the image to storage
277- to_storage .write_from_path (src_path . name , src_path , src_operator )
280+ to_storage .write_from_path (filename , src_path , src_operator )
278281 # but also write the metadata to be able to check for matching images later
279282 to_storage .write_bytes (metadata_file , metadata_json .encode (errors = "ignore" ))
280- self .logger .info (f"Image written to storage: { src_path } " )
283+ self .logger .info (f"Image written to storage: { filename } " )
281284
282285 except Exception as e :
283286 self .logger .error (f"Error writing image to storage: { e } " )
0 commit comments