-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfix_node_lib.py
More file actions
32 lines (27 loc) · 1.15 KB
/
Copy pathfix_node_lib.py
File metadata and controls
32 lines (27 loc) · 1.15 KB
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
import re
with open("bindings/node/src/lib.rs", "r") as f:
content = f.read()
config_new = """ if let Some(v) = config.default_ttl_secs {
if v < 0 { return Err(napi::Error::from_reason("default_ttl_secs cannot be negative")); }
cfg.default_ttl_secs = Some(v as u64);
}
if let Some(v) = config.memtable_size_mb {
if v <= 0 { return Err(napi::Error::from_reason("memtable_size_mb must be > 0")); }
cfg.memtable_size_mb = v as usize;
}
if let Some(v) = config.block_cache_capacity_mb {
if v < 0 { return Err(napi::Error::from_reason("block_cache_capacity_mb cannot be negative")); }
cfg.block_cache_capacity_mb = v as usize;
}
if let Some(v) = config.bloom_bits_per_key {
if v <= 0 { return Err(napi::Error::from_reason("bloom_bits_per_key must be > 0")); }
cfg.bloom_bits_per_key = v as usize;
}"""
content = re.sub(
r' if let Some\(v\) = config\.default_ttl_secs \{.*?\n \}',
config_new,
content,
flags=re.DOTALL
)
with open("bindings/node/src/lib.rs", "w") as f:
f.write(content)