Skip to content

Commit

Permalink
mkdir refactor and python mkdir/mkdirat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
facundopoblete committed Dec 15, 2024
1 parent b9e94e2 commit 9514788
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
12 changes: 8 additions & 4 deletions mirrord/layer/src/file/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,13 @@ pub(crate) fn read_link(path: Detour<PathBuf>) -> Detour<ReadLinkFileResponse> {

#[mirrord_layer_macro::instrument(level = Level::TRACE, ret)]
pub(crate) fn mkdir(pathname: Detour<PathBuf>, mode: u32) -> Detour<MakeDirResponse> {
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);

Expand All @@ -364,7 +368,7 @@ pub(crate) fn mkdirat(
pathname: Detour<PathBuf>,
mode: u32,
) -> Detour<MakeDirResponse> {
let pathname = pathname?;
let pathname: PathBuf = pathname?;

if pathname.is_absolute() || dirfd == AT_FDCWD {
let path = remap_path!(pathname);
Expand All @@ -376,7 +380,7 @@ pub(crate) fn mkdirat(

let mkdir: MakeDirAtRequest = MakeDirAtRequest {
dirfd: remote_fd,
pathname,
pathname: pathname.clone(),
mode,
};

Expand Down
6 changes: 0 additions & 6 deletions tests/go-e2e-dir/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tests/python-e2e/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9514788

Please sign in to comment.