@wasm-oj/server 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +6 -0
- package/THIRD_PARTY_NOTICES.md +302 -0
- package/crates/runtime-core/Cargo.lock +5099 -0
- package/crates/runtime-core/Cargo.toml +66 -0
- package/crates/runtime-core/README.md +47 -0
- package/crates/runtime-core/src/bin/wasm-oj-compiler.rs +418 -0
- package/crates/runtime-core/src/bin/wasm-oj-runner.rs +294 -0
- package/crates/runtime-core/src/capabilities.rs +118 -0
- package/crates/runtime-core/src/compiler.rs +658 -0
- package/crates/runtime-core/src/contract.rs +5 -0
- package/crates/runtime-core/src/deterministic.rs +1051 -0
- package/crates/runtime-core/src/error.rs +58 -0
- package/crates/runtime-core/src/filesystem.rs +547 -0
- package/crates/runtime-core/src/filesystem_quota.rs +167 -0
- package/crates/runtime-core/src/go_compiler_session.rs +297 -0
- package/crates/runtime-core/src/interactive.rs +1019 -0
- package/crates/runtime-core/src/judge_package.rs +1539 -0
- package/crates/runtime-core/src/lib.rs +98 -0
- package/crates/runtime-core/src/memory.rs +84 -0
- package/crates/runtime-core/src/meter.rs +549 -0
- package/crates/runtime-core/src/module_imports.rs +149 -0
- package/crates/runtime-core/src/module_policy.rs +714 -0
- package/crates/runtime-core/src/output.rs +204 -0
- package/crates/runtime-core/src/run/mod.rs +208 -0
- package/crates/runtime-core/src/run/native.rs +260 -0
- package/crates/runtime-core/src/run/web.rs +229 -0
- package/crates/runtime-core/src/run/web_runtime.rs +109 -0
- package/crates/runtime-core/src/types.rs +268 -0
- package/crates/runtime-core/src/web.rs +83 -0
- package/dist/chunks/go-toolchain-Dbt-lp2L.js +426 -0
- package/dist/chunks/java-toolchain-DajoRCHu.js +44 -0
- package/dist/chunks/python-toolchain-Dx834o2A.js +4 -0
- package/dist/chunks/rust-toolchain-CJ3sMxPE.js +252 -0
- package/dist/chunks/toolchains-C6KuA1yM.js +224 -0
- package/dist/go-stage.mjs +193 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.js +4393 -0
- package/dist/java-stage.mjs +111 -0
- package/dist/python-stage.mjs +90 -0
- package/dist/rustc-stage.mjs +301 -0
- package/dist/server-build-stage.mjs +2564 -0
- package/dist/server-runner-stage.mjs +155 -0
- package/licenses/fflate-MIT.txt +21 -0
- package/licenses/runtime-core-dependencies.html +6253 -0
- package/licenses/runtime-core-dependencies.json +3041 -0
- package/licenses/wasmer-sdk-MIT.txt +21 -0
- package/licenses/wasmer-sdk-dependencies.html +6901 -0
- package/licenses/wasmer-sdk-dependencies.json +3013 -0
- package/package.json +70 -0
- package/rust-toolchain.toml +5 -0
- package/testdata/wojjdg02-v2-text.hex +1 -0
- package/vendor/shared-buffer/Cargo.toml +22 -0
- package/vendor/shared-buffer/LICENSE_APACHE.md +176 -0
- package/vendor/shared-buffer/LICENSE_MIT.md +25 -0
- package/vendor/shared-buffer/README.md +34 -0
- package/vendor/shared-buffer/src/lib.rs +58 -0
- package/vendor/shared-buffer/src/mmap.rs +250 -0
- package/vendor/shared-buffer/src/owned.rs +389 -0
- package/vendor/virtual-fs/Cargo.toml +181 -0
- package/vendor/virtual-fs/LICENSE +25 -0
- package/vendor/virtual-fs/src/arc_box_file.rs +142 -0
- package/vendor/virtual-fs/src/arc_file.rs +182 -0
- package/vendor/virtual-fs/src/arc_fs.rs +68 -0
- package/vendor/virtual-fs/src/buffer_file.rs +103 -0
- package/vendor/virtual-fs/src/builder.rs +232 -0
- package/vendor/virtual-fs/src/combine_file.rs +101 -0
- package/vendor/virtual-fs/src/cow_file.rs +345 -0
- package/vendor/virtual-fs/src/dual_write_file.rs +113 -0
- package/vendor/virtual-fs/src/empty_fs.rs +81 -0
- package/vendor/virtual-fs/src/filesystems.rs +108 -0
- package/vendor/virtual-fs/src/host_fs.rs +1390 -0
- package/vendor/virtual-fs/src/lib.rs +782 -0
- package/vendor/virtual-fs/src/limiter.rs +252 -0
- package/vendor/virtual-fs/src/mem_fs/file.rs +1799 -0
- package/vendor/virtual-fs/src/mem_fs/file_opener.rs +941 -0
- package/vendor/virtual-fs/src/mem_fs/filesystem.rs +2134 -0
- package/vendor/virtual-fs/src/mem_fs/mod.rs +245 -0
- package/vendor/virtual-fs/src/mem_fs/offloaded_file.rs +474 -0
- package/vendor/virtual-fs/src/mem_fs/stdio.rs +318 -0
- package/vendor/virtual-fs/src/mount_fs.rs +2225 -0
- package/vendor/virtual-fs/src/null_file.rs +87 -0
- package/vendor/virtual-fs/src/ops.rs +364 -0
- package/vendor/virtual-fs/src/overlay_fs.rs +2216 -0
- package/vendor/virtual-fs/src/passthru_fs.rs +119 -0
- package/vendor/virtual-fs/src/pipe.rs +603 -0
- package/vendor/virtual-fs/src/random_file.rs +88 -0
- package/vendor/virtual-fs/src/special_file.rs +108 -0
- package/vendor/virtual-fs/src/static_file.rs +133 -0
- package/vendor/virtual-fs/src/static_fs.rs +460 -0
- package/vendor/virtual-fs/src/tmp_fs.rs +95 -0
- package/vendor/virtual-fs/src/trace_fs.rs +258 -0
- package/vendor/virtual-fs/src/webc_volume_fs.rs +829 -0
- package/vendor/virtual-fs/src/zero_file.rs +90 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
//! Used for sharing references to the same file across multiple file systems,
|
|
2
|
+
//! effectively this is a symbolic link without all the complex path redirection
|
|
3
|
+
|
|
4
|
+
use std::{
|
|
5
|
+
io::{self, *},
|
|
6
|
+
pin::Pin,
|
|
7
|
+
sync::{Arc, Mutex},
|
|
8
|
+
task::{Context, Poll},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};
|
|
12
|
+
|
|
13
|
+
use crate::VirtualFile;
|
|
14
|
+
|
|
15
|
+
#[derive(Debug, Clone)]
|
|
16
|
+
pub struct ArcBoxFile {
|
|
17
|
+
inner: Arc<Mutex<Box<dyn VirtualFile + Send + Sync + 'static>>>,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
impl ArcBoxFile {
|
|
21
|
+
pub fn new(inner: Box<dyn VirtualFile + Send + Sync + 'static>) -> Self {
|
|
22
|
+
Self {
|
|
23
|
+
inner: Arc::new(Mutex::new(inner)),
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
impl AsyncSeek for ArcBoxFile {
|
|
29
|
+
fn start_seek(self: Pin<&mut Self>, position: SeekFrom) -> io::Result<()> {
|
|
30
|
+
let mut guard = self.inner.lock().unwrap();
|
|
31
|
+
let file = Pin::new(guard.as_mut());
|
|
32
|
+
file.start_seek(position)
|
|
33
|
+
}
|
|
34
|
+
fn poll_complete(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
|
|
35
|
+
let mut guard = self.inner.lock().unwrap();
|
|
36
|
+
let file = Pin::new(guard.as_mut());
|
|
37
|
+
file.poll_complete(cx)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl AsyncWrite for ArcBoxFile {
|
|
42
|
+
fn poll_write(
|
|
43
|
+
self: Pin<&mut Self>,
|
|
44
|
+
cx: &mut Context<'_>,
|
|
45
|
+
buf: &[u8],
|
|
46
|
+
) -> Poll<io::Result<usize>> {
|
|
47
|
+
let mut guard = self.inner.lock().unwrap();
|
|
48
|
+
let file = Pin::new(guard.as_mut());
|
|
49
|
+
file.poll_write(cx, buf)
|
|
50
|
+
}
|
|
51
|
+
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
52
|
+
let mut guard = self.inner.lock().unwrap();
|
|
53
|
+
let file = Pin::new(guard.as_mut());
|
|
54
|
+
file.poll_flush(cx)
|
|
55
|
+
}
|
|
56
|
+
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
57
|
+
let mut guard = self.inner.lock().unwrap();
|
|
58
|
+
let file = Pin::new(guard.as_mut());
|
|
59
|
+
file.poll_shutdown(cx)
|
|
60
|
+
}
|
|
61
|
+
fn poll_write_vectored(
|
|
62
|
+
self: Pin<&mut Self>,
|
|
63
|
+
cx: &mut Context<'_>,
|
|
64
|
+
bufs: &[IoSlice<'_>],
|
|
65
|
+
) -> Poll<io::Result<usize>> {
|
|
66
|
+
let mut guard = self.inner.lock().unwrap();
|
|
67
|
+
let file = Pin::new(guard.as_mut());
|
|
68
|
+
file.poll_write_vectored(cx, bufs)
|
|
69
|
+
}
|
|
70
|
+
fn is_write_vectored(&self) -> bool {
|
|
71
|
+
let mut guard = self.inner.lock().unwrap();
|
|
72
|
+
let file = Pin::new(guard.as_mut());
|
|
73
|
+
file.is_write_vectored()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
impl AsyncRead for ArcBoxFile {
|
|
78
|
+
fn poll_read(
|
|
79
|
+
self: Pin<&mut Self>,
|
|
80
|
+
cx: &mut Context<'_>,
|
|
81
|
+
buf: &mut tokio::io::ReadBuf<'_>,
|
|
82
|
+
) -> Poll<io::Result<()>> {
|
|
83
|
+
let mut guard = self.inner.lock().unwrap();
|
|
84
|
+
let file = Pin::new(guard.as_mut());
|
|
85
|
+
file.poll_read(cx, buf)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
impl VirtualFile for ArcBoxFile {
|
|
90
|
+
fn last_accessed(&self) -> u64 {
|
|
91
|
+
let inner = self.inner.lock().unwrap();
|
|
92
|
+
inner.last_accessed()
|
|
93
|
+
}
|
|
94
|
+
fn last_modified(&self) -> u64 {
|
|
95
|
+
let inner = self.inner.lock().unwrap();
|
|
96
|
+
inner.last_modified()
|
|
97
|
+
}
|
|
98
|
+
fn created_time(&self) -> u64 {
|
|
99
|
+
let inner = self.inner.lock().unwrap();
|
|
100
|
+
inner.created_time()
|
|
101
|
+
}
|
|
102
|
+
fn set_times(&mut self, atime: Option<u64>, mtime: Option<u64>) -> crate::Result<()> {
|
|
103
|
+
let mut inner = self.inner.lock().unwrap();
|
|
104
|
+
inner.set_times(atime, mtime)
|
|
105
|
+
}
|
|
106
|
+
fn size(&self) -> u64 {
|
|
107
|
+
let inner = self.inner.lock().unwrap();
|
|
108
|
+
inner.size()
|
|
109
|
+
}
|
|
110
|
+
fn set_len(&mut self, new_size: u64) -> crate::Result<()> {
|
|
111
|
+
let mut inner = self.inner.lock().unwrap();
|
|
112
|
+
inner.set_len(new_size)
|
|
113
|
+
}
|
|
114
|
+
fn unlink(&mut self) -> crate::Result<()> {
|
|
115
|
+
let mut inner = self.inner.lock().unwrap();
|
|
116
|
+
inner.unlink()
|
|
117
|
+
}
|
|
118
|
+
fn is_open(&self) -> bool {
|
|
119
|
+
let inner = self.inner.lock().unwrap();
|
|
120
|
+
inner.is_open()
|
|
121
|
+
}
|
|
122
|
+
fn get_special_fd(&self) -> Option<u32> {
|
|
123
|
+
let inner = self.inner.lock().unwrap();
|
|
124
|
+
inner.get_special_fd()
|
|
125
|
+
}
|
|
126
|
+
fn poll_read_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
127
|
+
let mut inner = self.inner.lock().unwrap();
|
|
128
|
+
let inner = Pin::new(inner.as_mut());
|
|
129
|
+
inner.poll_read_ready(cx)
|
|
130
|
+
}
|
|
131
|
+
fn poll_write_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
132
|
+
let mut inner = self.inner.lock().unwrap();
|
|
133
|
+
let inner = Pin::new(inner.as_mut());
|
|
134
|
+
inner.poll_write_ready(cx)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
impl From<Box<dyn VirtualFile + Send + Sync + 'static>> for ArcBoxFile {
|
|
139
|
+
fn from(val: Box<dyn VirtualFile + Send + Sync + 'static>) -> Self {
|
|
140
|
+
ArcBoxFile::new(val)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
//! Used for sharing references to the same file across multiple file systems,
|
|
2
|
+
//! effectively this is a symbolic link without all the complex path redirection
|
|
3
|
+
|
|
4
|
+
use crate::{CloneableVirtualFile, VirtualFile};
|
|
5
|
+
use std::pin::Pin;
|
|
6
|
+
use std::task::{Context, Poll};
|
|
7
|
+
use std::{
|
|
8
|
+
io::{self, *},
|
|
9
|
+
sync::{Arc, Mutex},
|
|
10
|
+
};
|
|
11
|
+
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};
|
|
12
|
+
|
|
13
|
+
#[derive(Debug)]
|
|
14
|
+
pub struct ArcFile<T>
|
|
15
|
+
where
|
|
16
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
17
|
+
{
|
|
18
|
+
inner: Arc<Mutex<Box<T>>>,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
impl<T> ArcFile<T>
|
|
22
|
+
where
|
|
23
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
24
|
+
{
|
|
25
|
+
pub fn new(inner: Box<T>) -> Self {
|
|
26
|
+
Self {
|
|
27
|
+
inner: Arc::new(Mutex::new(inner)),
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl<T> AsyncSeek for ArcFile<T>
|
|
33
|
+
where
|
|
34
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
35
|
+
{
|
|
36
|
+
fn start_seek(self: Pin<&mut Self>, position: SeekFrom) -> io::Result<()> {
|
|
37
|
+
let mut guard = self.inner.lock().unwrap();
|
|
38
|
+
let file = Pin::new(guard.as_mut());
|
|
39
|
+
file.start_seek(position)
|
|
40
|
+
}
|
|
41
|
+
fn poll_complete(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
|
|
42
|
+
let mut guard = self.inner.lock().unwrap();
|
|
43
|
+
let file = Pin::new(guard.as_mut());
|
|
44
|
+
file.poll_complete(cx)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
impl<T> AsyncWrite for ArcFile<T>
|
|
49
|
+
where
|
|
50
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
51
|
+
{
|
|
52
|
+
fn poll_write(
|
|
53
|
+
self: Pin<&mut Self>,
|
|
54
|
+
cx: &mut Context<'_>,
|
|
55
|
+
buf: &[u8],
|
|
56
|
+
) -> Poll<io::Result<usize>> {
|
|
57
|
+
let mut guard = self.inner.lock().unwrap();
|
|
58
|
+
let file = Pin::new(guard.as_mut());
|
|
59
|
+
file.poll_write(cx, buf)
|
|
60
|
+
}
|
|
61
|
+
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
62
|
+
let mut guard = self.inner.lock().unwrap();
|
|
63
|
+
let file = Pin::new(guard.as_mut());
|
|
64
|
+
file.poll_flush(cx)
|
|
65
|
+
}
|
|
66
|
+
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
67
|
+
let mut guard = self.inner.lock().unwrap();
|
|
68
|
+
let file = Pin::new(guard.as_mut());
|
|
69
|
+
file.poll_shutdown(cx)
|
|
70
|
+
}
|
|
71
|
+
fn poll_write_vectored(
|
|
72
|
+
self: Pin<&mut Self>,
|
|
73
|
+
cx: &mut Context<'_>,
|
|
74
|
+
bufs: &[IoSlice<'_>],
|
|
75
|
+
) -> Poll<io::Result<usize>> {
|
|
76
|
+
let mut guard = self.inner.lock().unwrap();
|
|
77
|
+
let file = Pin::new(guard.as_mut());
|
|
78
|
+
file.poll_write_vectored(cx, bufs)
|
|
79
|
+
}
|
|
80
|
+
fn is_write_vectored(&self) -> bool {
|
|
81
|
+
let mut guard = self.inner.lock().unwrap();
|
|
82
|
+
let file = Pin::new(guard.as_mut());
|
|
83
|
+
file.is_write_vectored()
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
impl<T> AsyncRead for ArcFile<T>
|
|
88
|
+
where
|
|
89
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
90
|
+
{
|
|
91
|
+
fn poll_read(
|
|
92
|
+
self: Pin<&mut Self>,
|
|
93
|
+
cx: &mut Context<'_>,
|
|
94
|
+
buf: &mut tokio::io::ReadBuf<'_>,
|
|
95
|
+
) -> Poll<io::Result<()>> {
|
|
96
|
+
let mut guard = self.inner.lock().unwrap();
|
|
97
|
+
let file = Pin::new(guard.as_mut());
|
|
98
|
+
file.poll_read(cx, buf)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
impl<T> VirtualFile for ArcFile<T>
|
|
103
|
+
where
|
|
104
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
105
|
+
{
|
|
106
|
+
fn last_accessed(&self) -> u64 {
|
|
107
|
+
let inner = self.inner.lock().unwrap();
|
|
108
|
+
inner.last_accessed()
|
|
109
|
+
}
|
|
110
|
+
fn last_modified(&self) -> u64 {
|
|
111
|
+
let inner = self.inner.lock().unwrap();
|
|
112
|
+
inner.last_modified()
|
|
113
|
+
}
|
|
114
|
+
fn created_time(&self) -> u64 {
|
|
115
|
+
let inner = self.inner.lock().unwrap();
|
|
116
|
+
inner.created_time()
|
|
117
|
+
}
|
|
118
|
+
fn set_times(&mut self, atime: Option<u64>, mtime: Option<u64>) -> crate::Result<()> {
|
|
119
|
+
let mut inner = self.inner.lock().unwrap();
|
|
120
|
+
inner.set_times(atime, mtime)
|
|
121
|
+
}
|
|
122
|
+
fn size(&self) -> u64 {
|
|
123
|
+
let inner = self.inner.lock().unwrap();
|
|
124
|
+
inner.size()
|
|
125
|
+
}
|
|
126
|
+
fn set_len(&mut self, new_size: u64) -> crate::Result<()> {
|
|
127
|
+
let mut inner = self.inner.lock().unwrap();
|
|
128
|
+
inner.set_len(new_size)
|
|
129
|
+
}
|
|
130
|
+
fn unlink(&mut self) -> crate::Result<()> {
|
|
131
|
+
let mut inner = self.inner.lock().unwrap();
|
|
132
|
+
inner.unlink()
|
|
133
|
+
}
|
|
134
|
+
fn is_open(&self) -> bool {
|
|
135
|
+
let inner = self.inner.lock().unwrap();
|
|
136
|
+
inner.is_open()
|
|
137
|
+
}
|
|
138
|
+
fn get_special_fd(&self) -> Option<u32> {
|
|
139
|
+
let inner = self.inner.lock().unwrap();
|
|
140
|
+
inner.get_special_fd()
|
|
141
|
+
}
|
|
142
|
+
fn poll_read_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
143
|
+
let mut inner = self.inner.lock().unwrap();
|
|
144
|
+
let inner = Pin::new(inner.as_mut());
|
|
145
|
+
inner.poll_read_ready(cx)
|
|
146
|
+
}
|
|
147
|
+
fn poll_write_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
148
|
+
let mut inner = self.inner.lock().unwrap();
|
|
149
|
+
let inner = Pin::new(inner.as_mut());
|
|
150
|
+
inner.poll_write_ready(cx)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
impl<T> Clone for ArcFile<T>
|
|
155
|
+
where
|
|
156
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
157
|
+
{
|
|
158
|
+
fn clone(&self) -> Self {
|
|
159
|
+
ArcFile {
|
|
160
|
+
inner: self.inner.clone(),
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
impl<T> CloneableVirtualFile for ArcFile<T>
|
|
166
|
+
where
|
|
167
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
168
|
+
T: Clone,
|
|
169
|
+
{
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
impl<T> Default for ArcFile<T>
|
|
173
|
+
where
|
|
174
|
+
T: VirtualFile + Send + Sync + 'static,
|
|
175
|
+
T: Default,
|
|
176
|
+
{
|
|
177
|
+
fn default() -> Self {
|
|
178
|
+
Self {
|
|
179
|
+
inner: Arc::new(Mutex::new(Box::default())),
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//! Wraps a cloneable Arc of a file system - in practice this is useful so you
|
|
2
|
+
//! can pass cloneable file systems with a `Box<dyn FileSystem>` to other
|
|
3
|
+
//! interfaces
|
|
4
|
+
|
|
5
|
+
use std::{path::Path, sync::Arc};
|
|
6
|
+
|
|
7
|
+
use crate::*;
|
|
8
|
+
|
|
9
|
+
#[derive(Debug)]
|
|
10
|
+
pub struct ArcFileSystem {
|
|
11
|
+
fs: Arc<dyn FileSystem + Send + Sync + 'static>,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
impl ArcFileSystem {
|
|
15
|
+
pub fn new(inner: Arc<dyn FileSystem + Send + Sync + 'static>) -> Self {
|
|
16
|
+
Self { fs: inner }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pub fn inner(&self) -> &Arc<dyn FileSystem + Send + Sync + 'static> {
|
|
20
|
+
&self.fs
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
impl FileSystem for ArcFileSystem {
|
|
25
|
+
fn readlink(&self, path: &Path) -> Result<PathBuf> {
|
|
26
|
+
self.fs.readlink(path)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fn read_dir(&self, path: &Path) -> Result<ReadDir> {
|
|
30
|
+
self.fs.read_dir(path)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fn create_dir(&self, path: &Path) -> Result<()> {
|
|
34
|
+
self.fs.create_dir(path)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fn create_symlink(&self, source: &Path, target: &Path) -> Result<()> {
|
|
38
|
+
self.fs.create_symlink(source, target)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn hard_link(&self, source: &Path, target: &Path) -> Result<()> {
|
|
42
|
+
self.fs.hard_link(source, target)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fn remove_dir(&self, path: &Path) -> Result<()> {
|
|
46
|
+
self.fs.remove_dir(path)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fn rename<'a>(&'a self, from: &'a Path, to: &'a Path) -> BoxFuture<'a, Result<()>> {
|
|
50
|
+
Box::pin(async { self.fs.rename(from, to).await })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fn metadata(&self, path: &Path) -> Result<Metadata> {
|
|
54
|
+
self.fs.metadata(path)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fn symlink_metadata(&self, path: &Path) -> Result<Metadata> {
|
|
58
|
+
self.fs.symlink_metadata(path)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fn remove_file(&self, path: &Path) -> Result<()> {
|
|
62
|
+
self.fs.remove_file(path)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fn new_open_options(&self) -> OpenOptions<'_> {
|
|
66
|
+
self.fs.new_open_options()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//! Used for /dev/zero - infinitely returns zero
|
|
2
|
+
//! which is useful for commands like `dd if=/dev/zero of=bigfile.img size=1G`
|
|
3
|
+
|
|
4
|
+
use std::io::{self, *};
|
|
5
|
+
use std::pin::Pin;
|
|
6
|
+
use std::task::{Context, Poll};
|
|
7
|
+
|
|
8
|
+
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};
|
|
9
|
+
|
|
10
|
+
use crate::VirtualFile;
|
|
11
|
+
|
|
12
|
+
#[derive(Debug, Default)]
|
|
13
|
+
pub struct BufferFile {
|
|
14
|
+
pub(crate) data: Cursor<Vec<u8>>,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
impl AsyncSeek for BufferFile {
|
|
18
|
+
fn start_seek(mut self: Pin<&mut Self>, position: io::SeekFrom) -> io::Result<()> {
|
|
19
|
+
let data = Pin::new(&mut self.data);
|
|
20
|
+
data.start_seek(position)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fn poll_complete(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
|
|
24
|
+
let data = Pin::new(&mut self.data);
|
|
25
|
+
data.poll_complete(cx)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
impl AsyncWrite for BufferFile {
|
|
30
|
+
fn poll_write(
|
|
31
|
+
mut self: Pin<&mut Self>,
|
|
32
|
+
cx: &mut Context<'_>,
|
|
33
|
+
buf: &[u8],
|
|
34
|
+
) -> Poll<io::Result<usize>> {
|
|
35
|
+
let data = Pin::new(&mut self.data);
|
|
36
|
+
data.poll_write(cx, buf)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fn poll_write_vectored(
|
|
40
|
+
mut self: Pin<&mut Self>,
|
|
41
|
+
cx: &mut Context<'_>,
|
|
42
|
+
bufs: &[io::IoSlice<'_>],
|
|
43
|
+
) -> Poll<io::Result<usize>> {
|
|
44
|
+
let data = Pin::new(&mut self.data);
|
|
45
|
+
data.poll_write_vectored(cx, bufs)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
49
|
+
let data = Pin::new(&mut self.data);
|
|
50
|
+
data.poll_flush(cx)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
54
|
+
let data = Pin::new(&mut self.data);
|
|
55
|
+
data.poll_shutdown(cx)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
impl AsyncRead for BufferFile {
|
|
60
|
+
fn poll_read(
|
|
61
|
+
mut self: Pin<&mut Self>,
|
|
62
|
+
cx: &mut Context<'_>,
|
|
63
|
+
buf: &mut tokio::io::ReadBuf<'_>,
|
|
64
|
+
) -> Poll<io::Result<()>> {
|
|
65
|
+
let data = Pin::new(&mut self.data);
|
|
66
|
+
data.poll_read(cx, buf)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
impl VirtualFile for BufferFile {
|
|
71
|
+
fn last_accessed(&self) -> u64 {
|
|
72
|
+
1_000_000_000 // 1 second after epoch, since zero times are bad!
|
|
73
|
+
}
|
|
74
|
+
fn last_modified(&self) -> u64 {
|
|
75
|
+
1_000_000_000
|
|
76
|
+
}
|
|
77
|
+
fn created_time(&self) -> u64 {
|
|
78
|
+
1_000_000_000
|
|
79
|
+
}
|
|
80
|
+
fn size(&self) -> u64 {
|
|
81
|
+
self.data.get_ref().len() as u64
|
|
82
|
+
}
|
|
83
|
+
fn set_len(&mut self, new_size: u64) -> crate::Result<()> {
|
|
84
|
+
self.data.get_mut().resize(new_size as usize, 0);
|
|
85
|
+
Ok(())
|
|
86
|
+
}
|
|
87
|
+
fn unlink(&mut self) -> crate::Result<()> {
|
|
88
|
+
Ok(())
|
|
89
|
+
}
|
|
90
|
+
fn poll_read_ready(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
91
|
+
let cur = self.data.stream_position().unwrap_or_default();
|
|
92
|
+
let len = self.data.seek(SeekFrom::End(0)).unwrap_or_default();
|
|
93
|
+
if cur < len {
|
|
94
|
+
Poll::Ready(Ok((len - cur) as usize))
|
|
95
|
+
} else {
|
|
96
|
+
Poll::Ready(Ok(0))
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
fn poll_write_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
101
|
+
Poll::Ready(Ok(8192))
|
|
102
|
+
}
|
|
103
|
+
}
|