@@ -7,50 +7,50 @@ require('dotenv').config();
77const killServicesCommand = "kill $(ps -A | grep -e java -e bitcoind | awk '{print $1}')" ;
88
99async function clearLogFiles ( directory ) {
10- try {
11- const files = await fs . promises . readdir ( directory , { withFileTypes : true } ) ;
12-
13- for ( const file of files ) {
14- const filePath = path . join ( directory , file . name ) ;
15-
16- if ( file . isDirectory ( ) ) {
17- await clearLogFiles ( filePath ) ;
18- } else if ( path . extname ( file . name ) === ".log" ) {
19- await fs . promises . truncate ( filePath , 0 ) ;
20- console . log ( `Cleared content of file: ${ filePath } ` ) ;
21- }
10+ try {
11+ const files = await fs . promises . readdir ( directory , { withFileTypes : true } ) ;
12+
13+ for ( const file of files ) {
14+ const filePath = path . join ( directory , file . name ) ;
15+
16+ if ( file . isDirectory ( ) ) {
17+ await clearLogFiles ( filePath ) ;
18+ } else if ( path . extname ( file . name ) === '.log' ) {
19+ await fs . promises . truncate ( filePath , 0 ) ;
20+ console . log ( `Cleared content of file: ${ filePath } ` ) ;
21+ }
22+ }
23+ } catch ( err ) {
24+ console . error ( `Error processing directory ${ directory } : ${ err . message } ` ) ;
2225 }
23- } catch ( err ) {
24- console . error ( `Error processing directory ${ directory } : ${ err . message } ` ) ;
25- }
2626}
2727
2828function clearBitcoinDataDirectory ( ) {
29- return new Promise ( ( resolve , reject ) => {
30- const directory = process . env . BITCOIN_DATA_DIR ;
31-
32- if ( ! directory ) {
33- return reject ( new Error ( "BITCOIN_DATA_DIR is not set." ) ) ;
34- }
35-
36- fs . readdir ( directory , ( err , files ) => {
37- if ( err ) {
38- return reject ( new Error ( `Error reading directory ${ directory } : ${ err . message } ` ) ) ;
39- }
40-
41- const deletePromises = files . map ( file => {
42- const filePath = path . join ( directory , file ) ;
43- return fs . promises . rm ( filePath , { recursive : true , force : true } ) ;
44- } ) ;
45-
46- Promise . all ( deletePromises )
47- . then ( ( ) => {
48- console . log ( `Successfully cleared contents of: ${ directory } ` ) ;
49- resolve ( ) ;
50- } )
51- . catch ( reject ) ;
29+ return new Promise ( ( resolve , reject ) => {
30+ const directory = process . env . BITCOIN_DATA_DIR ;
31+
32+ if ( ! directory ) {
33+ return reject ( new Error ( 'BITCOIN_DATA_DIR is not set.' ) ) ;
34+ }
35+
36+ fs . readdir ( directory , ( err , files ) => {
37+ if ( err ) {
38+ return reject ( new Error ( `Error reading directory ${ directory } : ${ err . message } ` ) ) ;
39+ }
40+
41+ const deletePromises = files . map ( ( file ) => {
42+ const filePath = path . join ( directory , file ) ;
43+ return fs . promises . rm ( filePath , { recursive : true , force : true } ) ;
44+ } ) ;
45+
46+ Promise . all ( deletePromises )
47+ . then ( ( ) => {
48+ console . log ( `Successfully cleared contents of: ${ directory } ` ) ;
49+ resolve ( ) ;
50+ } )
51+ . catch ( reject ) ;
52+ } ) ;
5253 } ) ;
53- } ) ;
5454}
5555const cleanEnvironment = async ( ) => {
5656 console . info ( 'Cleaning environment...' ) ;
0 commit comments