1+ import * as fs from 'fs' ;
12import * as sleep from 'sleep-promise' ;
23
4+ import logger = require( '../../common/logger' ) ;
35import * as processWrapper from '../../common/process' ;
46import * as config from '../../common/config' ;
57import * as credentials from './credentials' ;
@@ -43,10 +45,10 @@ export async function pull(
4345 args . push ( { body : prefixRespository ( image , SkopeoRepositoryType . ImageRegistry ) , sanitise : false } ) ;
4446 args . push ( { body : prefixRespository ( destination , SkopeoRepositoryType . DockerArchive ) , sanitise : false } ) ;
4547
46- await pullWithRetry ( args ) ;
48+ await pullWithRetry ( args , destination ) ;
4749}
4850
49- async function pullWithRetry ( args : Array < processWrapper . IProcessArgument > ) : Promise < void > {
51+ async function pullWithRetry ( args : Array < processWrapper . IProcessArgument > , destination : string ) : Promise < void > {
5052 const MAX_ATTEMPTS = 10 ;
5153 const RETRY_INTERVAL_SEC = 0.2 ;
5254
@@ -55,6 +57,13 @@ async function pullWithRetry(args: Array<processWrapper.IProcessArgument>): Prom
5557 await processWrapper . exec ( 'skopeo' , ...args ) ;
5658 return ;
5759 } catch ( err ) {
60+ try {
61+ if ( fs . existsSync ( destination ) ) {
62+ fs . unlinkSync ( destination ) ;
63+ }
64+ } catch ( deleteErr ) {
65+ logger . warn ( { error : deleteErr , destination} , 'could not clean up the Skopeo-copy archive' ) ;
66+ }
5867 if ( attempt + 1 > MAX_ATTEMPTS ) {
5968 throw err ;
6069 }
0 commit comments