1
1
import * as fse from 'fs-extra' ;
2
- import * as pathLib from 'path' ;
3
2
import util = require( 'util' ) ;
4
3
import sha256 = require( 'crypto-js/sha256' ) ;
5
4
import nodeStream = require( 'stream' ) ;
@@ -9,10 +8,14 @@ import { exec, execFile } from "child_process";
9
8
const execAsync = ( util as any ) . promisify ( exec ) ;
10
9
const execFileAsync = ( util as any ) . promisify ( execFile ) ;
11
10
11
+ function getSystemExecutable ( program : string ) {
12
+ return fse . pathExistsSync ( `/bin/${ program } ` ) ? `/bin/${ program } ` : `/usr/bin/${ program } `
13
+ }
14
+
12
15
export async function emptyDir ( dirName : string ) : Promise < void > {
13
16
for ( let i = 0 ; i < 10 ; i ++ ) {
14
17
try {
15
- await execAsync ( "/bin/ find . -mindepth 1 -delete" , { cwd : dirName } ) ;
18
+ await execAsync ( ` ${ getSystemExecutable ( " find" ) } . -mindepth 1 -delete` , { cwd : dirName } ) ;
16
19
return ;
17
20
} catch ( e ) {
18
21
if ( i === 9 ) throw e ;
@@ -23,11 +26,11 @@ export async function emptyDir(dirName: string): Promise<void> {
23
26
}
24
27
25
28
export async function remove ( filename : string ) : Promise < void > {
26
- await execFileAsync ( "/bin/ rm", [ "-rf" , "--" , filename ] ) ;
29
+ await execFileAsync ( getSystemExecutable ( " rm") , [ "-rf" , "--" , filename ] ) ;
27
30
}
28
31
29
32
export 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 } ) ;
31
34
return Number ( result . stdout ) || 0 ;
32
35
}
33
36
0 commit comments