Skip to content

canonicalize_path_maybe_not_exists returns NotFound when relative path is given #19

@magurotuna

Description

@magurotuna

Issue

canonicalize_path_maybe_not_exists returns NotFound error when it's given a relative path and RealSys impl. It does NOT when InMemorySys is in use.

Example

RealSys

use deno_path_util::fs::canonicalize_path_maybe_not_exists;
use sys_traits::impls::RealSys;
use std::path::Path;

fn main() {
    let sys = RealSys;
    let result = canonicalize_path_maybe_not_exists(&sys, Path::new("hello.txt"));
    dbg!(result);
}

Output:

[src/bin/deno_path_util_canonicalize_path_maybe_not_exists.rs:8:5] result = Err(
    Os {
        code: 2,
        kind: NotFound,
        message: "No such file or directory",
    },
)

InMemorySys

use deno_path_util::fs::canonicalize_path_maybe_not_exists;
use sys_traits::impls::InMemorySys;
use sys_traits::EnvSetCurrentDir;
use sys_traits::FsCreateDirAll;
use std::path::Path;

fn main() {
    let sys = InMemorySys::default();
    sys.fs_create_dir_all("/").unwrap();
    sys.env_set_current_dir("/").unwrap();
    let result = canonicalize_path_maybe_not_exists(&sys, Path::new("hello.txt"));
    dbg!(result);
}

Output:

[src/bin/deno_path_util_canonicalize_path_maybe_not_exists.rs:12:5] result = Ok(
    "/hello.txt",
)

Additional Context

This is the root cause of denoland/deno#30923

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions