@@ -2,34 +2,33 @@ const fs = require('fs');
2
2
const exec_shell = require ( './util/exec_script' ) ;
3
3
4
4
const main = async ( ) => {
5
- //take snapshot name from arg
6
- const arg_input = process . argv [ 2 ] ;
7
- if ( arg_input === undefined ) {
8
- console . log ( 'Please specify snapshot name' ) ;
9
- return ;
10
- }
5
+ try {
6
+ //take snapshot name from arg
7
+ const arg_input = process . argv [ 2 ] ;
8
+ if ( arg_input === undefined ) {
9
+ console . log ( 'Please specify snapshot name' ) ;
10
+ return ;
11
+ }
11
12
12
- //check if .rnode dir exist
13
- const homedir = require ( 'os' ) . homedir ( ) ;
14
- if ( ! fs . existsSync ( homedir + '/.rnode' ) ) {
15
- console . log ( `Cannot snapshot: ${ homedir } /.rnode does not exist` ) ;
16
- return ;
17
- }
13
+ //check if .rnode dir exist
14
+ const homedir = require ( 'os' ) . homedir ( ) ;
15
+ if ( ! fs . existsSync ( homedir + '/.rnode' ) ) {
16
+ console . log ( `Cannot snapshot: ${ homedir } /.rnode does not exist` ) ;
17
+ return ;
18
+ }
18
19
19
- //run stop node script
20
- require ( 'child_process' ) . fork ( 'stop-rnode.js' ) ;
20
+ //run stop node script
21
+ require ( 'child_process' ) . fork ( 'stop-rnode.js' ) ;
21
22
22
- //create snapshot dir
23
- await exec_shell ( `mkdir -p snapshot` ) ;
24
- const target = `${ __dirname } /snapshot/${ arg_input } .tgz` ;
23
+ //create snapshot dir
24
+ fs . mkdirSync ( 'snapshot' , { recursive : true } ) ;
25
+ const target = `${ __dirname } /snapshot/${ arg_input } .tgz` ;
25
26
26
- if ( fs . existsSync ( target ) ) {
27
- console . log ( 'snapshot already exist' ) ;
28
- return ;
27
+ await exec_shell ( `cd ~ && tar czf "${ target } " .rnode` ) ;
28
+ console . log ( `snapshot created: ${ target } ` ) ;
29
+ } catch ( error ) {
30
+ console . log ( error ) ;
29
31
}
30
-
31
- await exec_shell ( `cd ~ && tar czf "${ target } " .rnode` ) ;
32
- console . log ( `snapshot created: ${ target } ` ) ;
33
32
} ;
34
33
35
34
main ( ) ;
0 commit comments