-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlib.rs
58 lines (43 loc) · 1.57 KB
/
lib.rs
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
54
55
56
57
58
use ic_cdk_macros::{query, update};
thread_local! {
static STABLE_MEMORY: std::cell::RefCell<icfs::StableMemory>
= std::cell::RefCell::new(icfs::StableMemory::default());
static VOL: std::cell::RefCell<ext4::SuperBlock<icfs::StableMemory>> = {
let vol: Result<ext4::SuperBlock<icfs::StableMemory>> = STABLE_MEMORY.with(|stable_memory| {
let stable_memory = *stable_memory.borrow();
#[cfg(target_arch = "wasm32")]
let memory_pages = core::arch::wasm32::memory_size(0)
.try_into()
.map_err(|error| std::io::Error::new(std::io::ErrorKind::Other, error))?;
#[cfg(not(target_arch = "wasm32"))]
let memory_pages = 19;
icfs::StableMemory::grow(memory_pages)?;
let mut options = ext4::Options::default();
options.checksums = ext4::Checksums::Enabled;
let vol = ext4::SuperBlock::new_with_options(stable_memory, &options).expect("ext4 volume");
Ok(vol)
});
std::cell::RefCell::new(vol.unwrap())
}
}
#[query]
fn ls() -> Vec<String> {
_ls().unwrap()
}
fn _ls() -> std::io::Result<Vec<String>> {
Ok(vec!("FIXME".to_string()))
}
#[query]
fn read_file(filename: String) -> String {
_read_file(filename).unwrap()
}
fn _read_file(filename: String) -> std::io::Result<String> {
Ok("FIXME".to_string())
}
#[update]
fn write_file(filename: String, contents: String) {
_write_file(filename, contents).unwrap();
}
fn _write_file(filename: String, contents: String) -> std::io::Result<()> {
Ok(())
}