Skip to content

Commit bbd9dc6

Browse files
authored
fix: unblock Deno.realPathSync (#493)
1 parent 3d93fb1 commit bbd9dc6

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

crates/base/src/deno_runtime.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,10 @@ where
653653
let build_file_system_fn =
654654
|base_fs: Arc<dyn deno_fs::FileSystem>| -> Result<Arc<dyn deno_fs::FileSystem>, AnyError> {
655655
let tmp_fs = TmpFs::try_from(maybe_tmp_fs_config.unwrap_or_default())?;
656-
let fs = PrefixFs::new("/tmp", tmp_fs, Some(base_fs))
657-
.tmp_dir("/tmp");
656+
let tmp_fs_actual_path = tmp_fs.actual_path().to_path_buf();
657+
let fs = PrefixFs::new("/tmp", tmp_fs.clone(), Some(base_fs))
658+
.tmp_dir("/tmp")
659+
.add_fs(tmp_fs_actual_path, tmp_fs);
658660

659661
Ok(if let Some(s3_fs) = maybe_s3_fs_config.map(S3Fs::new).transpose()? {
660662
maybe_s3_fs = Some(s3_fs.clone());
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const meowFile = await Deno.create('/tmp/meow');
2+
const meow = new TextEncoder().encode('meowmeow');
3+
await meowFile.write(meow);
4+
5+
const meowRealPath = Deno.realPathSync('/tmp/meow');
6+
const meowFileContent = await Deno.readTextFile(meowRealPath);
7+
const isValid = meowFileContent == 'meowmeow';
8+
9+
export default {
10+
fetch() {
11+
return new Response(null, {
12+
status: isValid ? 200 : 500,
13+
});
14+
},
15+
};

crates/base/test_cases/user-worker-san-check/.blocklisted

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ openSync
3131
readDirSync
3232
readLink
3333
readLinkSync
34-
realPathSync
3534
removeSync
3635
rename
3736
renameSync

crates/base/tests/integration_tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,23 @@ async fn test_tmp_fs_usage() {
28262826
TerminationToken::new()
28272827
);
28282828
}
2829+
2830+
{
2831+
integration_test!(
2832+
"./test_cases/main",
2833+
NON_SECURE_PORT,
2834+
"use-tmp-fs-3",
2835+
None,
2836+
None,
2837+
None,
2838+
None,
2839+
(|resp| async {
2840+
let resp = resp.unwrap();
2841+
assert_eq!(resp.status().as_u16(), 200);
2842+
}),
2843+
TerminationToken::new()
2844+
);
2845+
}
28292846
}
28302847

28312848
#[tokio::test]

crates/fs/impl/tmp_fs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ pub struct TmpFs {
227227
quota: Arc<Quota>,
228228
}
229229

230+
impl TmpFs {
231+
pub fn actual_path(&self) -> &Path {
232+
self.root.path()
233+
}
234+
}
235+
230236
#[async_trait::async_trait(?Send)]
231237
impl deno_fs::FileSystem for TmpFs {
232238
fn cwd(&self) -> FsResult<PathBuf> {

ext/core/js/bootstrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
641641
'open': true,
642642
'stat': true,
643643
'realPath': true,
644+
'realPathSync': true,
644645
'create': true,
645646
'remove': true,
646647
'writeFile': true,

0 commit comments

Comments
 (0)