-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Slightly more std::filesystem
for nix eval
#11650
Slightly more std::filesystem
for nix eval
#11650
Conversation
namespace nix::fs { using namespace std::filesystem; } | ||
|
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.
nitpick(non-blocking): Could maybe even move this inside of the class declaration.
namespace nix::fs { using namespace std::filesystem; } | |
using fs = std::filesystem; | |
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.
Actually it can't be that, I'll say why below
@@ -11,11 +11,13 @@ | |||
|
|||
using namespace nix; |
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.
nitpick(non-blocking): Would prefer to see this wrap the whole file.
@@ -11,11 +11,13 @@ | |||
|
|||
using namespace nix; | |||
|
|||
namespace nix::fs { using namespace std::filesystem; } |
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.
I hadn't noticed this before, but there are a few of these nix::fs
namespace declarations in src/nix now. I don't really understand what that's for? Just use std::filesystem
so people don't have to wonder what nix::fs
is.
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's because of
nix/src/libutil/file-system.hh
Lines 129 to 144 in 26c3fc1
namespace fs { | |
/** | |
* ``` | |
* symlink_exists(p) = std::filesystem::exists(std::filesystem::symlink_status(p)) | |
* ``` | |
* Missing convenience analogous to | |
* ``` | |
* std::filesystem::exists(p) = std::filesystem::exists(std::filesystem::status(p)) | |
* ``` | |
*/ | |
inline bool symlink_exists(const std::filesystem::path & path) { | |
return std::filesystem::exists(std::filesystem::symlink_status(path)); | |
} | |
} // namespace fs |
I hope that with more std::filesystem
, most of file-system.hh
goes away. However, there are a few things that aren't in there they we need, like this symlink_exists
.
I put it in an fs
namespace with the idea that if C++ files (not headers!) use fs::
as a shorthand for std::filesystem::
, then it will nicely gell with the existing apis.
namespace nix::fs { using namespace std::filesystem; }
I do because if I do
using fs = std::filesystem;
then that fs
will shadow, rather than expand, the namespace fs
I put in file-system.hh
.
I tried a few combinations, and the thing you commented on is the only one that will work (other than declaring symlink_exists
in std::filesystem
directly, which would be ill-advised.)
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.
clangd reports for an fs::current_path
identifier:
function current_path
provided by→ path
// In namespace std::filesystem
path current_path()
This pattern also seems useful for polyfilling functions from new C++ versions.
53fa147
to
b5c8865
Compare
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.
Refactor LGTM. Details can be improved if need be.
Am I missing something or is this borked with release builds without asserts? // TODO abstract mkdir perms for Windows
createDir(path.string(), 0777); // Directory should not already exist
assert(fs::create_directory(path.string())); Without asserts the call to [[maybe_unused]] bool created = fs::create_directory(path.string());
assert(created); |
@xokdvium Sorry I missed your message above! |
Context
Progress on #9205
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.