6
6
*/
7
7
8
8
import { rm } from 'node:fs/promises' ;
9
- import { dirname , join , resolve } from 'node:path' ;
9
+ import { dirname , join , resolve , sep } from 'node:path' ;
10
10
import * as fs from 'node:fs' ;
11
11
12
12
import { MultiStageOutput } from '@oclif/multi-stage-output' ;
@@ -21,6 +21,7 @@ import {
21
21
MetadataApiRetrieveStatus ,
22
22
RegistryAccess ,
23
23
RequestStatus ,
24
+ ComponentStatus ,
24
25
} from '@salesforce/source-deploy-retrieve' ;
25
26
import { SfCommand , toHelpSection , Flags , Ux } from '@salesforce/sf-plugins-core' ;
26
27
import { getString } from '@salesforce/ts-types' ;
@@ -354,14 +355,18 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
354
355
) ;
355
356
return directories ;
356
357
}
357
- // If we retrieved only a package.xml, just return.
358
- if ( this . retrieveResult . getFileResponses ( ) . length < 2 ) {
358
+
359
+ // skip file move if all retrieves failed to avoid ENOENT err (no such file or directory).
360
+ if (
361
+ this . retrieveResult . getFileResponses ( ) . length ===
362
+ this . retrieveResult . getFileResponses ( ) . filter ( ( c ) => c . state === ComponentStatus . Failed ) . length
363
+ ) {
359
364
return ;
360
365
}
361
366
362
367
// getFileResponses fails once the files have been moved, calculate where they're moved to, and then move them
363
368
this . retrieveResult . getFileResponses ( ) . forEach ( ( fileResponse ) => {
364
- fileResponse . filePath = fileResponse . filePath ?. replace ( join ( 'main' , 'default' ) , '' ) ;
369
+ fileResponse . filePath = fileResponse . filePath ?. replace ( join ( 'main' , 'default' , sep ) , '' ) ;
365
370
} ) ;
366
371
// move contents of 'main/default' to 'retrievetargetdir'
367
372
await promisesQueue ( [ join ( resolvedTargetDir , 'main' , 'default' ) ] , mv , 5 , true ) ;
0 commit comments