-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
linux-files.service.ts
53 lines (44 loc) 路 1.31 KB
/
linux-files.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { exec, spawn } from 'child_process';
import { FileService } from './files.service';
import { Observable } from 'rxjs';
import { StreamService } from './stream.service';
export class LinuxFilesService extends FileService {
constructor(private streamService: StreamService) {
super();
}
getFolderSize(path: string): Observable<{}> {
const du = spawn('du', ['-sm', path, '--max-depth', '0']);
const cut = spawn('cut', ['-f', '1']);
du.stdout.pipe(cut.stdin);
return this.streamService.getStream(cut);
}
listDir(path: string): Observable<{}> {
const child = spawn('find', [
path,
'-name',
'node_modules',
'-type',
'd',
'-prune',
]);
return this.streamService.getStream(child);
}
/* deleteDir(path: string): Observable<{}> {
const child = spawn('rm', ['-rf', path]);
return this.streamService.getStream(child);
} */
deleteDir(path: string): Promise<{}> {
return new Promise((resolve, reject) => {
const command = `rm -rf "${path}"`;
exec(command, (error, stdout, stderr) => {
if (error) return reject(error);
if (stderr) return reject(stderr);
resolve(stdout);
});
});
}
}
/*
const lf = new LinuxFilesService(new StreamService());
lf.deleteDir('/home/nya/Programming/node_modules');
*/