-
Notifications
You must be signed in to change notification settings - Fork 88
fix #381 #382
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
base: master
Are you sure you want to change the base?
fix #381 #382
Conversation
simplecpp.cpp
Outdated
|
||
// This is a workaround to properly check if a file exists, | ||
// since std::ifstream::good() incorrectly returns true for directories | ||
std::fstream fs(simplePath, std::ios::app); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is an interesting handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution still has flaws; when the file does not exist, an empty file will be created. Therefore, I replaced it with
std::fstream fs(simplePath, std::ios::in|std::ios::out);
Here is a simple test result (linux, mac, and windows):
https://github.com/foryoung365/CppFstreamTest/actions/runs/11549258974
Here are some references:
https://en.cppreference.com/w/cpp/io/basic_filebuf/open
Thanks. Please give me a few days since I might be out sick. |
how do we test this? you can easily check if a file exists or not in a unit test but if you need to test various edge cases I guess a pytest working in a tempdir is better. |
File existence check using fstream with ios::app is implemented as a workaround because: