Skip to content

Commit 1256596

Browse files
committed
fix: unblock Deno.realPathSync (#493)
1 parent 7377dc2 commit 1256596

File tree

6 files changed

+43
-2
lines changed

6 files changed

+43
-2
lines changed

crates/base/src/runtime/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,10 @@ where
639639
AnyError,
640640
> {
641641
let tmp_fs = TmpFs::try_from(maybe_tmp_fs_config.unwrap_or_default())?;
642-
let fs = PrefixFs::new("/tmp", tmp_fs, Some(base_fs)).tmp_dir("/tmp");
642+
let tmp_fs_actual_path = tmp_fs.actual_path().to_path_buf();
643+
let fs = PrefixFs::new("/tmp", tmp_fs.clone(), Some(base_fs))
644+
.tmp_dir("/tmp")
645+
.add_fs(tmp_fs_actual_path, tmp_fs);
643646

644647
Ok(
645648
if let Some(s3_fs) = maybe_s3_fs_config.map(S3Fs::new).transpose()? {
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
@@ -2766,6 +2766,23 @@ async fn test_tmp_fs_usage() {
27662766
TerminationToken::new()
27672767
);
27682768
}
2769+
2770+
{
2771+
integration_test!(
2772+
"./test_cases/main",
2773+
NON_SECURE_PORT,
2774+
"use-tmp-fs-3",
2775+
None,
2776+
None,
2777+
None,
2778+
None,
2779+
(|resp| async {
2780+
let resp = resp.unwrap();
2781+
assert_eq!(resp.status().as_u16(), 200);
2782+
}),
2783+
TerminationToken::new()
2784+
);
2785+
}
27692786
}
27702787

27712788
#[tokio::test]

crates/fs/impl/tmp_fs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ pub struct TmpFs {
238238
quota: Arc<Quota>,
239239
}
240240

241+
impl TmpFs {
242+
pub fn actual_path(&self) -> &Path {
243+
self.root.path()
244+
}
245+
}
246+
241247
#[async_trait::async_trait(?Send)]
242248
impl deno_fs::FileSystem for TmpFs {
243249
fn cwd(&self) -> FsResult<PathBuf> {

ext/runtime/js/bootstrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
658658
"open": true,
659659
"stat": true,
660660
"realPath": true,
661+
"realPathSync": true,
661662
"create": true,
662663
"remove": true,
663664
"writeFile": true,

0 commit comments

Comments
 (0)