@@ -198,13 +198,15 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
198198 } else throw new Error ( `getPackageActualVersion: ${ response . reason . user } : ${ response . reason . tech } ` )
199199 }
200200 async ensurePackageFulfilled ( ) : Promise < void > {
201- await this . fileHandler . clearPackageRemoval ( this . filePath )
201+ if ( ( this . workOptions . removeDelay ?? - 1 ) >= 0 ) {
202+ // Only handle this if there is a removeDelay set, otherwise we can skip it to save time:
203+ await this . fileHandler . clearPackageRemoval ( this . filePath )
204+ }
202205 }
203206 async removePackage ( reason : string ) : Promise < void > {
204207 await this . fileHandler . handleRemovePackage ( this . filePath , this . packageName , reason )
205208 }
206209 async getPackageReadStream ( ) : Promise < PackageReadStream > {
207- // important that this is a 'read', so that it doesn't go into a deadlock with putPackageStream() in case of an upload/download to the same accessorPackageContainer
208210 const ftp = await this . prepareFTPClient ( )
209211
210212 const response = await ftp . download ( this . fullPath )
@@ -267,7 +269,10 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
267269 operationName : string ,
268270 source : string | GenericAccessorHandle < any >
269271 ) : Promise < PackageOperation > {
270- await this . fileHandler . clearPackageRemoval ( this . filePath )
272+ if ( ( this . workOptions . removeDelay ?? - 1 ) >= 0 ) {
273+ // Only handle this if there is a removeDelay set, otherwise we can skip it to save time:
274+ await this . fileHandler . clearPackageRemoval ( this . filePath )
275+ }
271276 return this . logWorkOperation ( operationName , source , this . packageName )
272277 }
273278 async finalizePackage ( operation : PackageOperation ) : Promise < void > {
@@ -482,18 +487,20 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
482487 [ accessorType : string ] : CachedClients | undefined
483488 }
484489
485- const cacheKey = JSON . stringify ( [
486- this . accessorId ,
487- ftpOptions . serverType ,
488- ftpOptions . host ,
489- ftpOptions . port ,
490- this . accessor . basePath ?? '/' ,
491- ] )
490+ const cacheKey = JSON . stringify ( [ this . accessorId , options , this . accessor . basePath ?? '/' ] )
492491
493492 let cachedClients = accessorCache [ cacheKey ]
494493 if ( cachedClients ) {
495494 // Check that options matches:
496495 if ( ! isEqual ( cachedClients . options , options ) ) {
496+ // It the options don't match, something is wrong with the cacheKey
497+
498+ this . worker . logger . error (
499+ `Something is wrong with the FTP client cacheKey. The options do not match the cacheKey. Deleting cached clients for this key. cacheKey: ${ cacheKey } , options: ${ JSON . stringify (
500+ options
501+ ) } , cachedOptions: ${ JSON . stringify ( cachedClients . options ) } `
502+ )
503+
497504 for ( const c of cachedClients . clients ) {
498505 await c . client . destroy ( )
499506 }
@@ -532,9 +539,10 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
532539 }
533540
534541 if ( ! cachedClient ) {
542+ this . worker . logger . info ( `Creating new FTP client for purpose="${ purpose } ", ${ JSON . stringify ( options ) } ` )
535543 // Set up a new FTP client:
536544 cachedClient = {
537- client : createFTPClient ( ftpOptions . serverType , this . worker . logger , options ) ,
545+ client : createFTPClient ( options . serverType , this . worker . logger , options ) ,
538546 purpose : purpose ,
539547 }
540548 cachedClients . clients . push ( cachedClient )
@@ -580,6 +588,11 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
580588 return ftp . downloadContent ( fullPath )
581589 }
582590 async readFileIfExists ( fullPath : string ) : Promise < Buffer | undefined > {
591+ // On FTP, it is a much lighter operation to check if the file exists that reading it,
592+ // so we'll do that first:
593+ const exists = await this . fileExists ( fullPath )
594+ if ( ! exists ) return undefined
595+
583596 try {
584597 return await this . readFile ( fullPath )
585598 } catch ( e ) {
0 commit comments