Skip to content

Relative paths with ../ or absolute paths to a directory on the same level as the CWD are not resolved properly #14

@saphieron

Description

@saphieron

Hello everyone,

first off my setup:
codeviz based off commit a7aed10
Python 3.12.3
WSL2/Ubuntu 24.04 Linux INV-12047 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

When I try to run codeviz and pass it either a relative path that contains a "../" to a a directory on the same level as the current working directory (CWD) or is an absolute path to said same directory, codeviz states that the path does not exist.
Running codeviz in verbose mode shows, that the path is resolved to an absolute path, but for some reason the leading "/" is missing.

A minimal example:
Project Structure

$ tree .
├── base
│   ├── Makefile
│   └── src
│       └── main.c
├── first
│   ├── inc
│   │   └── firstFile.h
│   └── src
│       └── firstFile.c
└── second
    └── src
        └── secondFile.c

I can then recreate the error with

$ cd ./base
$ codeviz --verbose -r ./src ../first/inc/ ../second/src/ -o graph.svg
Found files:
        first/inc/firstFile.h
        second/src/secondFile.c
        src/main.c
Traceback (most recent call last):
  File "/home/myuser/bin/codeviz", line 363, in <module>
    retcode = main()
              ^^^^^^
  File "/home/myuser/bin/codeviz", line 346, in main
    nodes = get_nodes(files, highlight_files, force_include=args.must_include)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/myuser/bin/codeviz", line 117, in get_nodes
    n = Node(f)
        ^^^^^^^
  File "/home/myuser/bin/codeviz", line 65, in __init__
    self.file = File(filepath)
                ^^^^^^^^^^^^^^
  File "/home/myuser/bin/codeviz", line 47, in __init__
    self.included_headers = self._get_included_headers()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/myuser/bin/codeviz", line 52, in _get_included_headers
    with open(self.path, 'rt') as f:
         ^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'first/inc/firstFile.h'
make: *** [Makefile:3: createDepsGraph] Error 1

So, codeviz finds the different source files, lists them, but has stripped the relative move upwards with "../". Then it fails as there is no first/ or second/ directory under base/.

Using an absolute path makes this even more obvious that something seems to be removed from the beginning:

$ cd ./base
$ codeviz --verbose -r ./src /home/myuser/workspace/ccpp_proj/tester_project/first/inc/ ../second/src/ -o graph.svg
Found files:
        home/myuser/workspace/ccpp_proj/tester_project/first/inc/firstFile.h
        second/src/secondFile.c
        src/main.c
Traceback (most recent call last):
  File "/home/myuser/bin/codeviz", line 363, in <module>
    retcode = main()
              ^^^^^^
  File "/home/myuser/bin/codeviz", line 346, in main
    nodes = get_nodes(files, highlight_files, force_include=args.must_include)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/myuser/bin/codeviz", line 117, in get_nodes
    n = Node(f)
        ^^^^^^^
  File "/home/myuser/bin/codeviz", line 65, in __init__
    self.file = File(filepath)
                ^^^^^^^^^^^^^^
  File "/home/myuser/bin/codeviz", line 47, in __init__
    self.included_headers = self._get_included_headers()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/myuser/bin/codeviz", line 52, in _get_included_headers
    with open(self.path, 'rt') as f:
         ^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'home/myuser/workspace/ccpp_proj/tester_project/first/inc/firstFile.h'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions