diff --git a/mirrord/layer/src/file/ops.rs b/mirrord/layer/src/file/ops.rs index 748c0fa308b..60ea225ec90 100644 --- a/mirrord/layer/src/file/ops.rs +++ b/mirrord/layer/src/file/ops.rs @@ -339,9 +339,13 @@ pub(crate) fn read_link(path: Detour) -> Detour { #[mirrord_layer_macro::instrument(level = Level::TRACE, ret)] pub(crate) fn mkdir(pathname: Detour, mode: u32) -> Detour { - let path = remap_path!(pathname?); + let pathname = pathname?; - check_relative_paths!(path); + // TODO: (validate this) I think mirrord doesn't have a way to get the current working directory + // (yet?) so relative paths should be ignored. (Copied from open/openat hook) + check_relative_paths!(pathname); + + let path = remap_path!(pathname); ensure_not_ignored!(path, false); @@ -364,7 +368,7 @@ pub(crate) fn mkdirat( pathname: Detour, mode: u32, ) -> Detour { - let pathname = pathname?; + let pathname: PathBuf = pathname?; if pathname.is_absolute() || dirfd == AT_FDCWD { let path = remap_path!(pathname); @@ -376,7 +380,7 @@ pub(crate) fn mkdirat( let mkdir: MakeDirAtRequest = MakeDirAtRequest { dirfd: remote_fd, - pathname, + pathname: pathname.clone(), mode, }; diff --git a/tests/go-e2e-dir/main.go b/tests/go-e2e-dir/main.go index 4fbb223da42..b608f01b53b 100644 --- a/tests/go-e2e-dir/main.go +++ b/tests/go-e2e-dir/main.go @@ -30,12 +30,6 @@ func main() { os.Exit(-1) } - err = os.Mkdir("test_relative_mkdir", 0755) - if err != nil { - fmt.Printf("Mkdir (relative path) error: %s\n", err) - os.Exit(-1) - } - // let close requests be sent for test time.Sleep(1 * time.Second) os.Exit(0) diff --git a/tests/python-e2e/ops.py b/tests/python-e2e/ops.py index d2794d95ad5..c30d9e0801d 100644 --- a/tests/python-e2e/ops.py +++ b/tests/python-e2e/ops.py @@ -50,6 +50,24 @@ def test_openat(self): os.close(file) os.close(dir) + def test_mkdir(self): + """ + Creates a new directory in "/tmp" and verifies if the directory exists. + """ + os.mkdir("/tmp/test") + self.assertTrue(os.path.isdir("/tmp/test")) + + def test_mkdirat(self): + """ + Creates a new directory in "/tmp" using mkdirat given the directory file descriptor for "/tmp" and verifies if the directory exists. + """ + dir = os.open( + "/tmp", os.O_RDONLY | os.O_NONBLOCK | os.O_CLOEXEC | os.O_DIRECTORY + ) + os.mkdir("test", dir_fd=dir) + self.assertTrue(os.path.isdir("/tmp/test")) + os.close(dir) + def _create_new_tmp_file(self): """ Creates a new file in /tmp and returns the path and name of the file.