Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: fix os.join_path('/', 'file.txt') and os.join_path_single('/', 'file.txt') (fix #20231) #21429

Closed
wants to merge 7 commits into from

Conversation

spytheman
Copy link
Member

@spytheman spytheman commented May 5, 2024

Fix #20231 .

@spytheman spytheman changed the title os: fix os.join_path(/, file.txt) and os.join_path_single(/, file.txt) (fix #20231) os: fix os.join_path('/', 'file.txt') and os.join_path_single('/', 'file.txt') (fix #20231) May 5, 2024
@hholst80
Copy link
Contributor

hholst80 commented May 5, 2024

@spytheman what are you doing? are you stealing my PR? Let's not waste double efforts into solving the SAME ISSUE on multiple fronts there are 850+ issues to work on why not work together?

image

…and os.join_path_single, fix a/./b.txt -> a/b.txt without allocations
@spytheman
Copy link
Member Author

@spytheman what are you doing? are you stealing my PR? Let's not waste double efforts into solving the SAME ISSUE on multiple fronts there are 850+ issues to work on why not work together?

I am fixing it in a different way, that will require way less edits and review changes.

I am sorry, but os and join_path especially, is not the place for learning about V, and I am not in the mood of breaking bootstrapping and then fixing it slowly today.

@spytheman
Copy link
Member Author

Once it passes the CI, I can push to your PR, and then you will get the credit, when it is merged. I do not care about that at all. I simply do not want problems with the bootstrap and I have enough experience to know that changes in that particular place are tricky.

@spytheman
Copy link
Member Author

@hholst80, the CI passed for this PR, and imho it will be a bit less breaking, while ensuring the future stability of the behavior of os.join_path and os.join_path_single (which are now more unified in their output, and better tested).

Do you want me to push the changes here to your PR, so that I can merge them there?

os.setenv('USERPROFILE', '/tmp/home/folder', true)
os.setenv('USERPROFILE', r'\tmp\home\folder', true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I did this I am fairly sure the word "regression" would come up. ;-)

Anyways, I took this verbatim into my PR. The extended suite of tests and refactoring is probably a good idea anyways, if we now are going forward with the path normalization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USERPROFILE is a variable that is only defined on windows, and our home_dir only uses it on windows.
On windows, it will contain \, not / .
The difference between the regression in your PR, and the change here, is that here, the change in the test, makes the test closer to the environment, that it tested.
In your PR, the change was done just to make the CI pass with the changes in the PR.

assert os.join_path('/', 'test') == '/test'
assert os.join_path('foo/bar', './file.txt') == 'foo/bar/file.txt'
assert os.join_path('/opt/v', './x') == '/opt/v/x'
assert os.join_path('./a', './b') == './a/b'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not a/b here? I see no reason to keep the initial ./ prefix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It will be simpler without it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will have to be done in a separate focused PR, since it will break asserts like this one cmd/tools/vcomplete_test.v:229:

   > assert line == sorted_expected[i]
     Left value: sub0/
    Right value: ./sub0/

, and is not directly related to the join_path('/', 'x') problem in the issue.

Copy link
Member Author

@spytheman spytheman May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert os.join_path('foo\\bar', '.\\file.txt') == r'foo\bar\file.txt'
assert os.join_path('/opt/v', './x') == r'\opt\v\x'
} $else {
assert os.join_path('./b', '') == './b'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be just b imho

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

@spytheman
Copy link
Member Author

Obsoleted by #21494 .

@spytheman spytheman closed this May 13, 2024
@spytheman spytheman deleted the fix_os_issue_20231 branch May 13, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v fails to run and generate binaries from / folder
2 participants