mirror of
https://github.com/NixOS/nix
synced 2025-07-03 22:51:47 +02:00
For example, instead of doing #include "nix/store-config.hh" #include "nix/derived-path.hh" Now do #include "nix/store/config.hh" #include "nix/store/derived-path.hh" This was originally planned in the issue, and also recent requested by Eelco. Most of the change is purely mechanical. There is just one small additional issue. See how, in the example above, we took this opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`. Well, there was already a `nix/util/config.{cc,hh}`. Even though there is not a public configuration header for libutil (which also would be called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any such confusion, we renamed that to `nix/util/configuration.{cc,hh}`. Finally, note that the libflake headers already did this, so we didn't need to do anything to them. We wouldn't want to mistakenly get `nix/flake/flake/flake.hh`! Progress on #7876
40 lines
1.4 KiB
C++
40 lines
1.4 KiB
C++
#include <algorithm>
|
|
#include <codecvt>
|
|
#include <iostream>
|
|
#include <locale>
|
|
|
|
#include "nix/util/file-path.hh"
|
|
#include "nix/util/file-path-impl.hh"
|
|
#include "nix/util/util.hh"
|
|
|
|
namespace nix {
|
|
|
|
std::optional<std::filesystem::path> maybePath(PathView path)
|
|
{
|
|
if (path.length() >= 3 && (('A' <= path[0] && path[0] <= 'Z') || ('a' <= path[0] && path[0] <= 'z')) && path[1] == ':' && WindowsPathTrait<char>::isPathSep(path[2])) {
|
|
std::filesystem::path::string_type sw = string_to_os_string(
|
|
std::string { "\\\\?\\" } + path);
|
|
std::replace(sw.begin(), sw.end(), '/', '\\');
|
|
return sw;
|
|
}
|
|
if (path.length() >= 7 && path[0] == '\\' && path[1] == '\\' && (path[2] == '.' || path[2] == '?') && path[3] == '\\' &&
|
|
('A' <= path[4] && path[4] <= 'Z') && path[5] == ':' && WindowsPathTrait<char>::isPathSep(path[6])) {
|
|
std::filesystem::path::string_type sw = string_to_os_string(path);
|
|
std::replace(sw.begin(), sw.end(), '/', '\\');
|
|
return sw;
|
|
}
|
|
return std::optional<std::filesystem::path::string_type>();
|
|
}
|
|
|
|
std::filesystem::path pathNG(PathView path)
|
|
{
|
|
std::optional<std::filesystem::path::string_type> sw = maybePath(path);
|
|
if (!sw) {
|
|
// FIXME why are we not using the regular error handling?
|
|
std::cerr << "invalid path for WinAPI call ["<<path<<"]"<<std::endl;
|
|
_exit(111);
|
|
}
|
|
return *sw;
|
|
}
|
|
|
|
}
|