c3lang / c3c

Compiler for the C3 language
https://c3-lang.org
GNU Lesser General Public License v3.0
2.85k stars 175 forks source link

Path's dont say they are directories while they are #1589

Closed StandUp2001 closed 2 hours ago

StandUp2001 commented 4 hours ago

I have a test case that won't show directories as directories with path::is_dir(path) is called (I would preffere to have made it like path.is_dir() -> bool, but sidetrack)

Test case

import std::io::os;
import std::io::path;
import std::io;

fn void main() {
    Path cwd = path::new("..")!!;
    PathList list = path::temp_ls(cwd, false, false, "")!!;
    foreach (Path path: list) {
        if (path::is_dir(path)) {
            io::printfn("You are in a directory: %s", path.str_view());
            io::printfn("%s/", path.str_view());
        } else {
            io::printfn("%s", path.str_view());
        }
    }
}

What it shows: image

What I would expect: image (With "You are in a directory %s")

lerno commented 3 hours ago

This is actually correct. You are looking at the files in the parent directory. So in this case the actual path to c3c is "../c3c", but you test if "./c3c" is a dir – which it isn't since it doesn't even exist. If you prepend ".." to the path before testing "path::is_dir" then it will work.

lerno commented 3 hours ago

I think this should fix your issue.

StandUp2001 commented 2 hours ago

Aha. To be fair that makes a lot of sense. And yes now it works with the "../{{folder}}" Thx for the answer

lerno commented 2 hours ago

It's an easy enough mistake to make. I didn't see it at first either.