Skip to content

Commit dc5c58c

Browse files
committed
modified PipeFile to only take a File and be cloneable through an Arc
Signed-off-by: danbugs <[email protected]>
1 parent 8b3db3f commit dc5c58c

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

crates/engine/src/io.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use cap_std::fs::File as CapFile;
22
use std::{
33
collections::HashSet,
44
fmt::Debug,
5-
fs::{File, OpenOptions},
5+
fs::File,
66
io::{LineWriter, Write},
7-
path::PathBuf,
87
sync::{Arc, RwLock, RwLockReadGuard},
98
};
109
use wasi_common::{
@@ -59,32 +58,24 @@ pub trait OutputBuffers {
5958
}
6059

6160
/// Wrapper around File with a convenient PathBuf for cloning
62-
pub struct PipeFile(pub File, pub PathBuf);
61+
pub struct PipeFile(pub Arc<RwLock<Option<File>>>);
6362

6463
impl PipeFile {
6564
/// Constructs an instance from a file, and the PathBuf to that file.
66-
pub fn new(file: File, path: PathBuf) -> Self {
67-
Self(file, path)
65+
pub fn new(file: File) -> Self {
66+
Self(Arc::new(RwLock::new(Some(file))))
6867
}
6968
}
7069

7170
impl std::fmt::Debug for PipeFile {
7271
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73-
f.debug_struct("PipeFile")
74-
.field("File", &self.0)
75-
.field("PathBuf", &self.1)
76-
.finish()
72+
f.debug_struct("PipeFile").field("File", &self.0).finish()
7773
}
7874
}
7975

8076
impl Clone for PipeFile {
8177
fn clone(&self) -> Self {
82-
let f = OpenOptions::new()
83-
.read(true)
84-
.write(true)
85-
.open(&self.1)
86-
.unwrap();
87-
Self(f, self.1.clone())
78+
Self(Arc::clone(&self.0))
8879
}
8980
}
9081

crates/http/src/spin.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ impl HttpExecutor for SpinHttpExecutor {
3636
engine.config.module_io_redirects.clone()
3737
{
3838
ModuleIoRedirects::new_from_files(
39-
clp.stdin_pipe.map(|inp| inp.0),
40-
clp.stdout_pipe.map(|oup| oup.0),
41-
clp.stderr_pipe.map(|erp| erp.0),
39+
clp.stdin_pipe
40+
.map(|inp| (*inp.0.write().unwrap()).take().unwrap()),
41+
clp.stdout_pipe
42+
.map(|oup| (*oup.0.write().unwrap()).take().unwrap()),
43+
clp.stderr_pipe
44+
.map(|erp| (*erp.0.write().unwrap()).take().unwrap()),
4245
)
4346
} else {
4447
ModuleIoRedirects::new(follow)

crates/redis/src/spin.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ impl RedisExecutor for SpinRedisExecutor {
2727
engine.config.module_io_redirects.clone()
2828
{
2929
ModuleIoRedirects::new_from_files(
30-
clp.stdin_pipe.map(|inp| inp.0),
31-
clp.stdout_pipe.map(|oup| oup.0),
32-
clp.stderr_pipe.map(|erp| erp.0),
30+
clp.stdin_pipe
31+
.map(|inp| (*inp.0.write().unwrap()).take().unwrap()),
32+
clp.stdout_pipe
33+
.map(|oup| (*oup.0.write().unwrap()).take().unwrap()),
34+
clp.stderr_pipe
35+
.map(|erp| (*erp.0.write().unwrap()).take().unwrap()),
3336
)
3437
} else {
3538
ModuleIoRedirects::new(follow)

0 commit comments

Comments
 (0)