11import * as fse from 'fs-extra' ;
2- import * as pathLib from 'path' ;
32import util = require( 'util' ) ;
43import sha256 = require( 'crypto-js/sha256' ) ;
54import nodeStream = require( 'stream' ) ;
@@ -9,10 +8,14 @@ import { exec, execFile } from "child_process";
98const execAsync = ( util as any ) . promisify ( exec ) ;
109const execFileAsync = ( util as any ) . promisify ( execFile ) ;
1110
11+ function getSystemExecutable ( program : string ) {
12+ return fse . pathExistsSync ( `/bin/${ program } ` ) ? `/bin/${ program } ` : `/usr/bin/${ program } `
13+ }
14+
1215export async function emptyDir ( dirName : string ) : Promise < void > {
1316 for ( let i = 0 ; i < 10 ; i ++ ) {
1417 try {
15- await execAsync ( "/bin/ find . -mindepth 1 -delete" , { cwd : dirName } ) ;
18+ await execAsync ( ` ${ getSystemExecutable ( " find" ) } . -mindepth 1 -delete` , { cwd : dirName } ) ;
1619 return ;
1720 } catch ( e ) {
1821 if ( i === 9 ) throw e ;
@@ -23,11 +26,11 @@ export async function emptyDir(dirName: string): Promise<void> {
2326}
2427
2528export async function remove ( filename : string ) : Promise < void > {
26- await execFileAsync ( "/bin/ rm", [ "-rf" , "--" , filename ] ) ;
29+ await execFileAsync ( getSystemExecutable ( " rm") , [ "-rf" , "--" , filename ] ) ;
2730}
2831
2932export async function getFolderSize ( dirName : string ) : Promise < number > {
30- const result = await execAsync ( "/usr/bin/du -sb . | /usr/bin/ cut -f1" , { cwd : dirName } ) ;
33+ const result = await execAsync ( ` ${ getSystemExecutable ( "du" ) } -sb . | ${ getSystemExecutable ( " cut" ) } -f1` , { cwd : dirName } ) ;
3134 return Number ( result . stdout ) || 0 ;
3235}
3336
0 commit comments