@@ -114,13 +114,7 @@ impl TxHashSet {
114
114
root_dir : String ,
115
115
commit_index : Arc < ChainStore > ,
116
116
header : Option < & BlockHeader > ,
117
- sandbox_dir : Option < String > ,
118
117
) -> Result < TxHashSet , Error > {
119
- let txhashset_rootdir = if let Some ( sandbox) = sandbox_dir {
120
- sandbox. clone ( )
121
- } else {
122
- root_dir. clone ( )
123
- } ;
124
118
Ok ( TxHashSet {
125
119
header_pmmr_h : PMMRHandle :: new (
126
120
& root_dir,
@@ -137,21 +131,21 @@ impl TxHashSet {
137
131
None ,
138
132
) ?,
139
133
output_pmmr_h : PMMRHandle :: new (
140
- & txhashset_rootdir ,
134
+ & root_dir ,
141
135
TXHASHSET_SUBDIR ,
142
136
OUTPUT_SUBDIR ,
143
137
true ,
144
138
header,
145
139
) ?,
146
140
rproof_pmmr_h : PMMRHandle :: new (
147
- & txhashset_rootdir ,
141
+ & root_dir ,
148
142
TXHASHSET_SUBDIR ,
149
143
RANGE_PROOF_SUBDIR ,
150
144
true ,
151
145
header,
152
146
) ?,
153
147
kernel_pmmr_h : PMMRHandle :: new (
154
- & txhashset_rootdir ,
148
+ & root_dir ,
155
149
TXHASHSET_SUBDIR ,
156
150
KERNEL_SUBDIR ,
157
151
false ,
@@ -1468,35 +1462,49 @@ pub fn zip_write(
1468
1462
check_and_remove_files ( & txhashset_path, header)
1469
1463
}
1470
1464
1471
- /// Rename a folder to another
1472
- pub fn txhashset_replace ( from : PathBuf , to : PathBuf ) -> Result < ( ) , Error > {
1473
- debug ! ( "txhashset_replace : move from {:?} to {:?}" , from, to) ;
1465
+ /// Overwrite 2 hashset folders ('txhashset' & 'header') in "to" folder with "from" folder
1466
+ pub fn hashset_replace ( from : PathBuf , to : PathBuf ) -> Result < ( ) , Error > {
1467
+ debug ! ( "hashset_replace : move from {:?} to {:?}" , from, to) ;
1474
1468
1475
1469
// clean the 'to' folder firstly
1476
- clean_txhashset_folder ( & to) ;
1470
+ clean_hashset_folder ( & to) ;
1477
1471
1478
1472
// rename the 'from' folder as the 'to' folder
1479
- let txhashset_from_path = from. clone ( ) . join ( TXHASHSET_SUBDIR ) ;
1480
- let txhashset_to_path = to. clone ( ) . join ( TXHASHSET_SUBDIR ) ;
1481
- if let Err ( e) = fs:: rename ( txhashset_from_path, txhashset_to_path) {
1482
- error ! ( "txhashset_replace fail. err: {}" , e) ;
1483
- Err ( ErrorKind :: TxHashSetErr ( format ! ( "txhashset replacing fail" ) ) . into ( ) )
1484
- } else {
1485
- Ok ( ( ) )
1473
+ if let Err ( e) = fs:: rename ( from. clone ( ) . join ( TXHASHSET_SUBDIR ) , to. clone ( ) . join ( TXHASHSET_SUBDIR ) ) {
1474
+ error ! ( "hashset_replace fail on {}. err: {}" , TXHASHSET_SUBDIR , e) ;
1475
+ return Err ( ErrorKind :: TxHashSetErr ( format ! ( "txhashset replacing fail" ) ) . into ( ) ) ;
1486
1476
}
1477
+
1478
+ // rename the 'from' folder as the 'to' folder
1479
+ if let Err ( e) = fs:: rename ( from. clone ( ) . join ( HEADERHASHSET_SUBDIR ) , to. clone ( ) . join ( HEADERHASHSET_SUBDIR ) ) {
1480
+ error ! ( "hashset_replace fail on {}. err: {}" , HEADERHASHSET_SUBDIR , e) ;
1481
+ return Err ( ErrorKind :: TxHashSetErr ( format ! ( "txhashset replacing fail" ) ) . into ( ) ) ;
1482
+ }
1483
+
1484
+ return Ok ( ( ) ) ;
1487
1485
}
1488
1486
1489
- /// Clean the txhashset folder
1490
- pub fn clean_txhashset_folder ( root_dir : & PathBuf ) {
1487
+ /// Clean the hashset folder (txhashset and header hashset)
1488
+ pub fn clean_hashset_folder ( root_dir : & PathBuf ) {
1491
1489
let txhashset_path = root_dir. clone ( ) . join ( TXHASHSET_SUBDIR ) ;
1492
1490
if txhashset_path. exists ( ) {
1493
1491
if let Err ( e) = fs:: remove_dir_all ( txhashset_path. clone ( ) ) {
1494
1492
warn ! (
1495
- "clean_txhashset_folder : fail on {:?}. err: {}" ,
1493
+ "clean_hashset_folder : fail on {:?}. err: {}" ,
1496
1494
txhashset_path, e
1497
1495
) ;
1498
1496
}
1499
1497
}
1498
+
1499
+ let header_hashset_path = root_dir. clone ( ) . join ( HEADERHASHSET_SUBDIR ) ;
1500
+ if header_hashset_path. exists ( ) {
1501
+ if let Err ( e) = fs:: remove_dir_all ( header_hashset_path. clone ( ) ) {
1502
+ warn ! (
1503
+ "clean_hashset_folder: fail on {:?}. err: {}" ,
1504
+ header_hashset_path, e
1505
+ ) ;
1506
+ }
1507
+ }
1500
1508
}
1501
1509
1502
1510
fn expected_file ( path : & Path ) -> bool {
0 commit comments