Skip to content

Commit 9efa7bc

Browse files
author
Michael-F-Bryan
committed
Added tests for #3678
1 parent e28c569 commit 9efa7bc

File tree

2 files changed

+72
-20
lines changed

2 files changed

+72
-20
lines changed

lib/vfs/src/mem_fs/filesystem.rs

+36-14
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,25 @@ impl Default for FileSystemInner {
937937
}
938938
}
939939

940+
#[allow(dead_code)] // The `No` variant.
941+
pub(super) enum DirectoryMustBeEmpty {
942+
Yes,
943+
No,
944+
}
945+
946+
impl DirectoryMustBeEmpty {
947+
pub(super) fn yes(&self) -> bool {
948+
matches!(self, Self::Yes)
949+
}
950+
951+
pub(super) fn no(&self) -> bool {
952+
!self.yes()
953+
}
954+
}
955+
940956
#[cfg(test)]
941957
mod test_filesystem {
942-
use crate::{mem_fs::*, DirEntry, FileSystem as FS, FileType, FsError};
958+
use crate::{mem_fs::*, DirEntry, FileSystem as FS, FileSystemExt, FileType, FsError};
943959

944960
macro_rules! path {
945961
($path:expr) => {
@@ -1686,20 +1702,26 @@ mod test_filesystem {
16861702
"canonicalizing a crazily stupid path name",
16871703
);
16881704
}
1689-
}
1690-
1691-
#[allow(dead_code)] // The `No` variant.
1692-
pub(super) enum DirectoryMustBeEmpty {
1693-
Yes,
1694-
No,
1695-
}
16961705

1697-
impl DirectoryMustBeEmpty {
1698-
pub(super) fn yes(&self) -> bool {
1699-
matches!(self, Self::Yes)
1700-
}
1706+
#[test]
1707+
#[ignore = "Not yet supported. See https://github.com/wasmerio/wasmer/issues/3678"]
1708+
fn mount_to_overlapping_directories() {
1709+
let top_level = FileSystem::default();
1710+
top_level.touch("/file.txt").unwrap();
1711+
let nested = FileSystem::default();
1712+
nested.touch("/another-file.txt").unwrap();
1713+
let top_level: Arc<dyn crate::FileSystem + Send + Sync> = Arc::new(top_level);
1714+
let nested: Arc<dyn crate::FileSystem + Send + Sync> = Arc::new(nested);
17011715

1702-
pub(super) fn no(&self) -> bool {
1703-
!self.yes()
1716+
let fs = FileSystem::default();
1717+
fs.mount("/top-level".into(), &top_level, "/".into())
1718+
.unwrap();
1719+
fs.mount("/top-level/nested".into(), &nested, "/".into())
1720+
.unwrap();
1721+
1722+
assert!(fs.is_dir("/top-level"));
1723+
assert!(fs.is_file("/top-level/file.txt"));
1724+
assert!(fs.is_dir("/top-level/nested"));
1725+
assert!(fs.is_file("/top-level/nested/another-file.txt"));
17041726
}
17051727
}

lib/vfs/src/union_fs.rs

+36-6
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,14 @@ impl FileOpener for UnionFileSystem {
460460

461461
#[cfg(test)]
462462
mod tests {
463+
use std::{path::Path, sync::Arc};
464+
463465
use tokio::io::AsyncWriteExt;
464466

465-
use crate::host_fs::FileSystem;
466-
use crate::mem_fs;
467-
use crate::FileSystem as FileSystemTrait;
468-
use crate::FsError;
469-
use crate::UnionFileSystem;
470-
use std::path::Path;
467+
use crate::{
468+
host_fs::FileSystem, mem_fs, FileSystem as FileSystemTrait, FileSystemExt, FsError,
469+
UnionFileSystem,
470+
};
471471

472472
fn gen_filesystem() -> UnionFileSystem {
473473
let mut union = UnionFileSystem::new();
@@ -1073,4 +1073,34 @@ mod tests {
10731073
let _ = fs_extra::remove_items(&["./test_canonicalize"]);
10741074
}
10751075
*/
1076+
1077+
#[test]
1078+
#[ignore = "Not yet supported. See https://github.com/wasmerio/wasmer/issues/3678"]
1079+
fn mount_to_overlapping_directories() {
1080+
let top_level = mem_fs::FileSystem::default();
1081+
top_level.touch("/file.txt").unwrap();
1082+
let nested = mem_fs::FileSystem::default();
1083+
nested.touch("/another-file.txt").unwrap();
1084+
1085+
let mut fs = UnionFileSystem::default();
1086+
fs.mount(
1087+
"top-level",
1088+
"/",
1089+
false,
1090+
Box::new(top_level),
1091+
Some("/top-level"),
1092+
);
1093+
fs.mount(
1094+
"nested",
1095+
"/",
1096+
false,
1097+
Box::new(nested),
1098+
Some("/top-level/nested"),
1099+
);
1100+
1101+
assert!(fs.is_dir("/top-level"));
1102+
assert!(fs.is_file("/top-level/file.txt"));
1103+
assert!(fs.is_dir("/top-level/nested"));
1104+
assert!(fs.is_file("/top-level/nested/another-file.txt"));
1105+
}
10761106
}

0 commit comments

Comments
 (0)