Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ded675e56 |
No files matched your search
@@ -9,3 +9,9 @@ endif
|
|||||||
if 'address' in get_option('b_sanitize')
|
if 'address' in get_option('b_sanitize')
|
||||||
deps_other += declare_dependency(sources : 'asan-options.cc')
|
deps_other += declare_dependency(sources : 'asan-options.cc')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if 'undefined' in get_option('b_sanitize')
|
||||||
|
add_project_arguments('-DNIX_UBSAN_ENABLED=1', language : 'cpp')
|
||||||
|
else
|
||||||
|
add_project_arguments('-DNIX_UBSAN_ENABLED=0', language : 'cpp')
|
||||||
|
endif
|
||||||
+1
-1
@@ -710,7 +710,7 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
|
|||||||
try {
|
try {
|
||||||
cwd = std::filesystem::current_path();
|
cwd = std::filesystem::current_path();
|
||||||
} catch (std::filesystem::filesystem_error & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
throw SystemError(e.code(), "cannot determine current working directory");
|
throw SysError("cannot determine current working directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto flakeRef = parseFlakeRef(fetchSettings, flakeRefS, cwd.string(), true);
|
auto flakeRef = parseFlakeRef(fetchSettings, flakeRefS, cwd.string(), true);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
namespace nix::eval_cache {
|
namespace nix::eval_cache {
|
||||||
|
|
||||||
CachedEvalError::CachedEvalError(ref<AttrCursor> cursor, Symbol attr)
|
CachedEvalError::CachedEvalError(ref<AttrCursor> cursor, Symbol attr)
|
||||||
: EvalError(cursor->root->state, "cached failure of attribute '%s'", cursor->getAttrPathStr(attr))
|
: CloneableError(cursor->root->state, "cached failure of attribute '%s'", cursor->getAttrPathStr(attr))
|
||||||
, cursor(cursor)
|
, cursor(cursor)
|
||||||
, attr(attr)
|
, attr(attr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace nix::eval_cache {
|
|||||||
struct AttrDb;
|
struct AttrDb;
|
||||||
class AttrCursor;
|
class AttrCursor;
|
||||||
|
|
||||||
struct CachedEvalError : EvalError
|
struct CachedEvalError : CloneableError<CachedEvalError, EvalError>
|
||||||
{
|
{
|
||||||
const ref<AttrCursor> cursor;
|
const ref<AttrCursor> cursor;
|
||||||
const Symbol attr;
|
const Symbol attr;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class EvalErrorBuilder;
|
|||||||
*
|
*
|
||||||
* Most subclasses should inherit from `EvalError` instead of this class.
|
* Most subclasses should inherit from `EvalError` instead of this class.
|
||||||
*/
|
*/
|
||||||
class EvalBaseError : public Error
|
class EvalBaseError : public CloneableError<EvalBaseError, Error>
|
||||||
{
|
{
|
||||||
template<class T>
|
template<class T>
|
||||||
friend class EvalErrorBuilder;
|
friend class EvalErrorBuilder;
|
||||||
@@ -26,14 +26,14 @@ public:
|
|||||||
EvalState & state;
|
EvalState & state;
|
||||||
|
|
||||||
EvalBaseError(EvalState & state, ErrorInfo && errorInfo)
|
EvalBaseError(EvalState & state, ErrorInfo && errorInfo)
|
||||||
: Error(errorInfo)
|
: CloneableError(errorInfo)
|
||||||
, state(state)
|
, state(state)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
explicit EvalBaseError(EvalState & state, const std::string & formatString, const Args &... formatArgs)
|
explicit EvalBaseError(EvalState & state, const std::string & formatString, const Args &... formatArgs)
|
||||||
: Error(formatString, formatArgs...)
|
: CloneableError(formatString, formatArgs...)
|
||||||
, state(state)
|
, state(state)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -60,23 +60,23 @@ MakeError(InfiniteRecursionError, EvalError);
|
|||||||
* Inherits from EvalBaseError (not EvalError) because resource exhaustion
|
* Inherits from EvalBaseError (not EvalError) because resource exhaustion
|
||||||
* should not be cached.
|
* should not be cached.
|
||||||
*/
|
*/
|
||||||
struct StackOverflowError : public EvalBaseError
|
struct StackOverflowError : public CloneableError<StackOverflowError, EvalBaseError>
|
||||||
{
|
{
|
||||||
StackOverflowError(EvalState & state)
|
StackOverflowError(EvalState & state)
|
||||||
: EvalBaseError(state, "stack overflow; max-call-depth exceeded")
|
: CloneableError(state, "stack overflow; max-call-depth exceeded")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MakeError(IFDError, EvalBaseError);
|
MakeError(IFDError, EvalBaseError);
|
||||||
|
|
||||||
struct InvalidPathError : public EvalError
|
struct InvalidPathError : public CloneableError<InvalidPathError, EvalError>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Path path;
|
Path path;
|
||||||
|
|
||||||
InvalidPathError(EvalState & state, const Path & path)
|
InvalidPathError(EvalState & state, const Path & path)
|
||||||
: EvalError(state, "path '%s' is not valid", path)
|
: CloneableError(state, "path '%s' is not valid", path)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class BadNixStringContextElem : public Error
|
class BadNixStringContextElem final : public CloneableError<BadNixStringContextElem, Error>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string_view raw;
|
std::string_view raw;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
BadNixStringContextElem(std::string_view raw_, const Args &... args)
|
BadNixStringContextElem(std::string_view raw_, const Args &... args)
|
||||||
: Error("")
|
: CloneableError("")
|
||||||
{
|
{
|
||||||
raw = raw_;
|
raw = raw_;
|
||||||
auto hf = HintFmt(args...);
|
auto hf = HintFmt(args...);
|
||||||
|
|||||||
@@ -1312,11 +1312,12 @@ static void prim_warn(EvalState & state, const PosIdx pos, Value ** args, Value
|
|||||||
state.forceString(*args[0], pos, "while evaluating the first argument; the message passed to builtins.warn");
|
state.forceString(*args[0], pos, "while evaluating the first argument; the message passed to builtins.warn");
|
||||||
|
|
||||||
{
|
{
|
||||||
BaseError msg(std::string{msgStr});
|
ErrorInfo info{
|
||||||
msg.atPos(state.positions[pos]);
|
.level = lvlWarn,
|
||||||
auto info = msg.info();
|
.msg = HintFmt(std::string(msgStr)),
|
||||||
info.level = lvlWarn;
|
.pos = state.positions[pos],
|
||||||
info.isFromExpr = true;
|
.isFromExpr = true,
|
||||||
|
};
|
||||||
logWarning(info);
|
logWarning(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,11 +74,11 @@ namespace nix {
|
|||||||
|
|
||||||
struct GitSourceAccessor;
|
struct GitSourceAccessor;
|
||||||
|
|
||||||
struct GitError : public Error
|
struct GitError final : public CloneableError<GitError, Error>
|
||||||
{
|
{
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
GitError(const git_error & error, Ts &&... args)
|
GitError(const git_error & error, Ts &&... args)
|
||||||
: Error("")
|
: CloneableError("")
|
||||||
{
|
{
|
||||||
auto hf = HintFmt(std::forward<Ts>(args)...);
|
auto hf = HintFmt(std::forward<Ts>(args)...);
|
||||||
err.msg = HintFmt("%1%: %2% (libgit2 error code = %3%)", Uncolored(hf.str()), error.message, error.klass);
|
err.msg = HintFmt("%1%: %2% (libgit2 error code = %3%)", Uncolored(hf.str()), error.message, error.klass);
|
||||||
@@ -247,8 +247,7 @@ static void initRepoAtomically(std::filesystem::path & path, GitRepo::Options op
|
|||||||
|| e.code() == std::errc::directory_not_empty) {
|
|| e.code() == std::errc::directory_not_empty) {
|
||||||
return;
|
return;
|
||||||
} else
|
} else
|
||||||
throw SystemError(
|
throw SysError("moving temporary git repository from %s to %s", PathFmt(tmpDir), PathFmt(path));
|
||||||
e.code(), "moving temporary git repository from %s to %s", PathFmt(tmpDir), PathFmt(path));
|
|
||||||
}
|
}
|
||||||
// we successfully moved the repository, so the temporary directory no longer exists.
|
// we successfully moved the repository, so the temporary directory no longer exists.
|
||||||
delTmpDir.cancel();
|
delTmpDir.cancel();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
AwsAuthError::AwsAuthError(int errorCode)
|
AwsAuthError::AwsAuthError(int errorCode)
|
||||||
: Error("AWS authentication error: '%s' (%d)", aws_error_str(errorCode), errorCode)
|
: CloneableError("AWS authentication error: '%s' (%d)", aws_error_str(errorCode), errorCode)
|
||||||
, errorCode(errorCode)
|
, errorCode(errorCode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "nix/store/build/goal.hh"
|
#include "nix/store/build/goal.hh"
|
||||||
#include "nix/store/build/worker.hh"
|
#include "nix/store/build/worker.hh"
|
||||||
#include "nix/store/globals.hh"
|
#include "nix/store/worker-settings.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
TimedOut::TimedOut(time_t maxDuration)
|
TimedOut::TimedOut(time_t maxDuration)
|
||||||
: BuildError(BuildResult::Failure::TimedOut, "timed out after %1% seconds", maxDuration)
|
: CloneableError(BuildResult::Failure::TimedOut, "timed out after %1% seconds", maxDuration)
|
||||||
, maxDuration(maxDuration)
|
, maxDuration(maxDuration)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ static void builtinUnpackChannel(const BuiltinBuilderContext & ctx)
|
|||||||
auto target = out / channelName;
|
auto target = out / channelName;
|
||||||
try {
|
try {
|
||||||
std::filesystem::rename(fileName, target);
|
std::filesystem::rename(fileName, target);
|
||||||
} catch (std::filesystem::filesystem_error & e) {
|
} catch (std::filesystem::filesystem_error &) {
|
||||||
throw SystemError(e.code(), "failed to rename %1% to %2%", fileName, target.string());
|
throw SysError("failed to rename %1% to %2%", fileName, target.string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,12 +60,12 @@ namespace {
|
|||||||
using curlSList = std::unique_ptr<::curl_slist, decltype([](::curl_slist * list) { ::curl_slist_free_all(list); })>;
|
using curlSList = std::unique_ptr<::curl_slist, decltype([](::curl_slist * list) { ::curl_slist_free_all(list); })>;
|
||||||
using curlMulti = std::unique_ptr<::CURLM, decltype([](::CURLM * multi) { ::curl_multi_cleanup(multi); })>;
|
using curlMulti = std::unique_ptr<::CURLM, decltype([](::CURLM * multi) { ::curl_multi_cleanup(multi); })>;
|
||||||
|
|
||||||
struct curlMultiError : Error
|
struct curlMultiError final : CloneableError<curlMultiError, Error>
|
||||||
{
|
{
|
||||||
::CURLMcode code;
|
::CURLMcode code;
|
||||||
|
|
||||||
curlMultiError(::CURLMcode code)
|
curlMultiError(::CURLMcode code)
|
||||||
: Error{"unexpected curl multi error: %s", ::curl_multi_strerror(code)}
|
: CloneableError{"unexpected curl multi error: %s", ::curl_multi_strerror(code)}
|
||||||
{
|
{
|
||||||
assert(code != CURLM_OK);
|
assert(code != CURLM_OK);
|
||||||
}
|
}
|
||||||
@@ -1212,7 +1212,7 @@ void FileTransfer::download(
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
FileTransferError::FileTransferError(
|
FileTransferError::FileTransferError(
|
||||||
FileTransfer::Error error, std::optional<std::string> response, const Args &... args)
|
FileTransfer::Error error, std::optional<std::string> response, const Args &... args)
|
||||||
: Error(args...)
|
: CloneableError(args...)
|
||||||
, error(error)
|
, error(error)
|
||||||
, response(response)
|
, response(response)
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -272,7 +272,7 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R
|
|||||||
|| e.code() == std::errc::not_a_directory)
|
|| e.code() == std::errc::not_a_directory)
|
||||||
printInfo("cannot read potential root '%1%'", path);
|
printInfo("cannot read potential root '%1%'", path);
|
||||||
else
|
else
|
||||||
throw SystemError(e.code(), "finding GC roots in '%1%'", path);
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (SystemError & e) {
|
catch (SystemError & e) {
|
||||||
|
|||||||
@@ -34,12 +34,13 @@ struct AwsCredentials
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class AwsAuthError : public Error
|
class AwsAuthError final : public CloneableError<AwsAuthError, Error>
|
||||||
{
|
{
|
||||||
std::optional<int> errorCode;
|
std::optional<int> errorCode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Error::Error;
|
using CloneableError::CloneableError;
|
||||||
|
|
||||||
AwsAuthError(int errorCode);
|
AwsAuthError(int errorCode);
|
||||||
|
|
||||||
std::optional<int> getErrorCode() const
|
std::optional<int> getErrorCode() const
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ enum struct BuildResultFailureStatus : uint8_t {
|
|||||||
* This is both an exception type (inherits from Error) and serves as
|
* This is both an exception type (inherits from Error) and serves as
|
||||||
* the failure variant in BuildResult::inner.
|
* the failure variant in BuildResult::inner.
|
||||||
*/
|
*/
|
||||||
struct BuildError : public Error
|
struct BuildError : public CloneableError<BuildError, Error>
|
||||||
{
|
{
|
||||||
using Status = BuildResultFailureStatus;
|
using Status = BuildResultFailureStatus;
|
||||||
using enum Status;
|
using enum Status;
|
||||||
@@ -80,7 +80,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
BuildError(Status status, const Args &... args)
|
BuildError(Status status, const Args &... args)
|
||||||
: Error(args...)
|
: CloneableError(args...)
|
||||||
, status{status}
|
, status{status}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ public:
|
|||||||
* Also used for deserialization.
|
* Also used for deserialization.
|
||||||
*/
|
*/
|
||||||
BuildError(Args args)
|
BuildError(Args args)
|
||||||
: Error(std::move(args.msg))
|
: CloneableError(std::move(args.msg))
|
||||||
, status{args.status}
|
, status{args.status}
|
||||||
, isNonDeterministic{args.isNonDeterministic}
|
, isNonDeterministic{args.isNonDeterministic}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public:
|
|||||||
* Default constructor for deserialization.
|
* Default constructor for deserialization.
|
||||||
*/
|
*/
|
||||||
BuildError()
|
BuildError()
|
||||||
: Error("")
|
: CloneableError("")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ namespace nix {
|
|||||||
* Denotes a build failure that stemmed from the builder exiting with a
|
* Denotes a build failure that stemmed from the builder exiting with a
|
||||||
* failing exist status.
|
* failing exist status.
|
||||||
*/
|
*/
|
||||||
struct BuilderFailureError : BuildError
|
struct BuilderFailureError final : CloneableError<BuilderFailureError, BuildError>
|
||||||
{
|
{
|
||||||
int builderStatus;
|
int builderStatus;
|
||||||
|
|
||||||
std::string extraMsgAfter;
|
std::string extraMsgAfter;
|
||||||
|
|
||||||
BuilderFailureError(BuildResult::Failure::Status status, int builderStatus, std::string extraMsgAfter)
|
BuilderFailureError(BuildResult::Failure::Status status, int builderStatus, std::string extraMsgAfter)
|
||||||
: BuildError{
|
: CloneableError{
|
||||||
status,
|
status,
|
||||||
/* No message for now, because the caller will make for
|
/* No message for now, because the caller will make for
|
||||||
us, with extra context */
|
us, with extra context */
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
struct TimedOut : BuildError
|
struct TimedOut final : CloneableError<TimedOut, BuildError>
|
||||||
{
|
{
|
||||||
time_t maxDuration;
|
time_t maxDuration;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ struct Package
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class BuildEnvFileConflictError : public Error
|
class BuildEnvFileConflictError final : public CloneableError<BuildEnvFileConflictError, Error>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const Path fileA;
|
const Path fileA;
|
||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
int priority;
|
int priority;
|
||||||
|
|
||||||
BuildEnvFileConflictError(const Path fileA, const Path fileB, int priority)
|
BuildEnvFileConflictError(const Path fileA, const Path fileB, int priority)
|
||||||
: Error(
|
: CloneableError(
|
||||||
"Unable to build profile. There is a conflict for the following files:\n"
|
"Unable to build profile. There is a conflict for the following files:\n"
|
||||||
"\n"
|
"\n"
|
||||||
" %1%\n"
|
" %1%\n"
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ ref<FileTransfer> getFileTransfer();
|
|||||||
*/
|
*/
|
||||||
ref<FileTransfer> makeFileTransfer(const FileTransferSettings & settings = fileTransferSettings);
|
ref<FileTransfer> makeFileTransfer(const FileTransferSettings & settings = fileTransferSettings);
|
||||||
|
|
||||||
class FileTransferError : public Error
|
class FileTransferError final : public CloneableError<FileTransferError, Error>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileTransfer::Error error;
|
FileTransfer::Error error;
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ struct RealisedPath
|
|||||||
auto operator<=>(const RealisedPath &) const = default;
|
auto operator<=>(const RealisedPath &) const = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MissingRealisation : public Error
|
class MissingRealisation final : public CloneableError<MissingRealisation, Error>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MissingRealisation(DrvOutput & outputId)
|
MissingRealisation(DrvOutput & outputId)
|
||||||
@@ -155,7 +155,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
MissingRealisation(std::string_view drv, OutputName outputName)
|
MissingRealisation(std::string_view drv, OutputName outputName)
|
||||||
: Error(
|
: CloneableError(
|
||||||
"cannot operate on output '%s' of the "
|
"cannot operate on output '%s' of the "
|
||||||
"unbuilt derivation '%s'",
|
"unbuilt derivation '%s'",
|
||||||
outputName,
|
outputName,
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ struct SQLiteTxn
|
|||||||
~SQLiteTxn();
|
~SQLiteTxn();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SQLiteError : Error
|
struct SQLiteError : CloneableError<SQLiteError, Error>
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ static void readProcLink(const std::filesystem::path & file, UncheckedRoots & ro
|
|||||||
if (e.code() == std::errc::no_such_file_or_directory || e.code() == std::errc::permission_denied
|
if (e.code() == std::errc::no_such_file_or_directory || e.code() == std::errc::permission_denied
|
||||||
|| e.code() == std::errc::no_such_process)
|
|| e.code() == std::errc::no_such_process)
|
||||||
return;
|
return;
|
||||||
throw SystemError(e.code(), "reading symlink '%s'", PathFmt(file));
|
throw;
|
||||||
}
|
}
|
||||||
if (buf.is_absolute())
|
if (buf.is_absolute())
|
||||||
roots[buf.string()].emplace(file.string());
|
roots[buf.string()].emplace(file.string());
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ static std::vector<std::string> expandBuilderLines(const std::string & builders)
|
|||||||
std::string text;
|
std::string text;
|
||||||
try {
|
try {
|
||||||
text = readFile(path);
|
text = readFile(path);
|
||||||
} catch (const SystemError & e) {
|
} catch (const SysError & e) {
|
||||||
if (!e.is(std::errc::no_such_file_or_directory))
|
if (e.errNo != ENOENT)
|
||||||
throw;
|
throw;
|
||||||
debug("cannot find machines file '%s'", path);
|
debug("cannot find machines file '%s'", path);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -202,13 +202,14 @@ void LocalStore::optimisePath_(
|
|||||||
full. When that happens, it's fine to ignore it: we
|
full. When that happens, it's fine to ignore it: we
|
||||||
just effectively disable deduplication of this
|
just effectively disable deduplication of this
|
||||||
file.
|
file.
|
||||||
|
TODO: Get rid of errno, use error code.
|
||||||
*/
|
*/
|
||||||
printInfo("cannot link %s to '%s': %s", PathFmt(linkPath), path, e.code().message());
|
printInfo("cannot link %s to '%s': %s", PathFmt(linkPath), path, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
throw SystemError(e.code(), "creating hard link from %1% to %2%", PathFmt(linkPath), path);
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +250,7 @@ void LocalStore::optimisePath_(
|
|||||||
printInfo("%1% has maximum number of links", PathFmt(linkPath));
|
printInfo("%1% has maximum number of links", PathFmt(linkPath));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw SystemError(e.code(), "creating hard link from %1% to %2%", PathFmt(linkPath), PathFmt(tempLink));
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Atomically replace the old file with the new hard link. */
|
/* Atomically replace the old file with the new hard link. */
|
||||||
@@ -270,7 +271,7 @@ void LocalStore::optimisePath_(
|
|||||||
debug("%s has reached maximum number of links", PathFmt(linkPath));
|
debug("%s has reached maximum number of links", PathFmt(linkPath));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw SystemError(e.code(), "renaming %1% to %2%", PathFmt(tempLink), path);
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.filesLinked++;
|
stats.filesLinked++;
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ static void removeFile(const std::filesystem::path & path)
|
|||||||
try {
|
try {
|
||||||
std::filesystem::remove(path);
|
std::filesystem::remove(path);
|
||||||
} catch (std::filesystem::filesystem_error & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
throw SystemError(e.code(), "removing file %1%", PathFmt(path));
|
throw SysError("removing file %1%", PathFmt(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,6 +324,8 @@ std::filesystem::path getDefaultProfile(ProfileDirsOptions settings)
|
|||||||
return absPath(readLink(profileLink), &linkDir);
|
return absPath(readLink(profileLink), &linkDir);
|
||||||
} catch (Error &) {
|
} catch (Error &) {
|
||||||
return profileLink;
|
return profileLink;
|
||||||
|
} catch (std::filesystem::filesystem_error &) {
|
||||||
|
return profileLink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace nix {
|
|||||||
|
|
||||||
SQLiteError::SQLiteError(
|
SQLiteError::SQLiteError(
|
||||||
const char * path, const char * errMsg, int errNo, int extendedErrNo, int offset, HintFmt && hf)
|
const char * path, const char * errMsg, int errNo, int extendedErrNo, int offset, HintFmt && hf)
|
||||||
: Error("")
|
: CloneableError("")
|
||||||
, path(path)
|
, path(path)
|
||||||
, errMsg(errMsg)
|
, errMsg(errMsg)
|
||||||
, errNo(errNo)
|
, errNo(errNo)
|
||||||
|
|||||||
+2
-2
@@ -18,11 +18,11 @@ static std::string parsePublicHostKey(std::string_view host, std::string_view ss
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvalidSSHAuthority : public Error
|
class InvalidSSHAuthority final : public CloneableError<InvalidSSHAuthority, Error>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InvalidSSHAuthority(const ParsedURL::Authority & authority, std::string_view reason)
|
InvalidSSHAuthority(const ParsedURL::Authority & authority, std::string_view reason)
|
||||||
: Error("invalid SSH authority: '%s': %s", authority.to_string(), reason)
|
: CloneableError("invalid SSH authority: '%s': %s", authority.to_string(), reason)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,10 +55,10 @@
|
|||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
struct NotDeterministic : BuildError
|
struct NotDeterministic final : CloneableError<NotDeterministic, BuildError>
|
||||||
{
|
{
|
||||||
NotDeterministic(auto &&... args)
|
NotDeterministic(auto &&... args)
|
||||||
: BuildError(BuildResult::Failure::NotDeterministic, args...)
|
: CloneableError(BuildResult::Failure::NotDeterministic, args...)
|
||||||
{
|
{
|
||||||
isNonDeterministic = true;
|
isNonDeterministic = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,24 +56,26 @@ bool lockFile(Descriptor desc, LockType lockType, bool wait)
|
|||||||
switch (lockType) {
|
switch (lockType) {
|
||||||
case ltNone: {
|
case ltNone: {
|
||||||
OVERLAPPED ov = {0};
|
OVERLAPPED ov = {0};
|
||||||
if (!UnlockFileEx(desc, 0, 2, 0, &ov))
|
if (!UnlockFileEx(desc, 0, 2, 0, &ov)) {
|
||||||
throw WinError("Failed to unlock file desc %s", desc);
|
WinError winError("Failed to unlock file desc %s", desc);
|
||||||
|
throw winError;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ltRead: {
|
case ltRead: {
|
||||||
OVERLAPPED ov = {0};
|
OVERLAPPED ov = {0};
|
||||||
if (!LockFileEx(desc, wait ? 0 : LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &ov)) {
|
if (!LockFileEx(desc, wait ? 0 : LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &ov)) {
|
||||||
auto lastError = GetLastError();
|
WinError winError("Failed to lock file desc %s", desc);
|
||||||
if (lastError == ERROR_LOCK_VIOLATION)
|
if (winError.lastError == ERROR_LOCK_VIOLATION)
|
||||||
return false;
|
return false;
|
||||||
throw WinError(lastError, "Failed to lock file desc %s", desc);
|
throw winError;
|
||||||
}
|
}
|
||||||
|
|
||||||
ov.Offset = 1;
|
ov.Offset = 1;
|
||||||
if (!UnlockFileEx(desc, 0, 1, 0, &ov)) {
|
if (!UnlockFileEx(desc, 0, 1, 0, &ov)) {
|
||||||
auto lastError = GetLastError();
|
WinError winError("Failed to unlock file desc %s", desc);
|
||||||
if (lastError != ERROR_NOT_LOCKED)
|
if (winError.lastError != ERROR_NOT_LOCKED)
|
||||||
throw WinError(lastError, "Failed to unlock file desc %s", desc);
|
throw winError;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -81,17 +83,17 @@ bool lockFile(Descriptor desc, LockType lockType, bool wait)
|
|||||||
OVERLAPPED ov = {0};
|
OVERLAPPED ov = {0};
|
||||||
ov.Offset = 1;
|
ov.Offset = 1;
|
||||||
if (!LockFileEx(desc, LOCKFILE_EXCLUSIVE_LOCK | (wait ? 0 : LOCKFILE_FAIL_IMMEDIATELY), 0, 1, 0, &ov)) {
|
if (!LockFileEx(desc, LOCKFILE_EXCLUSIVE_LOCK | (wait ? 0 : LOCKFILE_FAIL_IMMEDIATELY), 0, 1, 0, &ov)) {
|
||||||
auto lastError = GetLastError();
|
WinError winError("Failed to lock file desc %s", desc);
|
||||||
if (lastError == ERROR_LOCK_VIOLATION)
|
if (winError.lastError == ERROR_LOCK_VIOLATION)
|
||||||
return false;
|
return false;
|
||||||
throw WinError(lastError, "Failed to lock file desc %s", desc);
|
throw winError;
|
||||||
}
|
}
|
||||||
|
|
||||||
ov.Offset = 0;
|
ov.Offset = 0;
|
||||||
if (!UnlockFileEx(desc, 0, 1, 0, &ov)) {
|
if (!UnlockFileEx(desc, 0, 1, 0, &ov)) {
|
||||||
auto lastError = GetLastError();
|
WinError winError("Failed to unlock file desc %s", desc);
|
||||||
if (lastError != ERROR_NOT_LOCKED)
|
if (winError.lastError != ERROR_NOT_LOCKED)
|
||||||
throw WinError(lastError, "Failed to unlock file desc %s", desc);
|
throw winError;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ TEST(chmodIfNeeded, works)
|
|||||||
|
|
||||||
TEST(chmodIfNeeded, nonexistent)
|
TEST(chmodIfNeeded, nonexistent)
|
||||||
{
|
{
|
||||||
ASSERT_THROW(chmodIfNeeded("/schnitzel/darmstadt/pommes", 0755), SystemError);
|
ASSERT_THROW(chmodIfNeeded("/schnitzel/darmstadt/pommes", 0755), SysError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@@ -340,7 +340,7 @@ TEST(DirectoryIterator, works)
|
|||||||
|
|
||||||
TEST(DirectoryIterator, nonexistent)
|
TEST(DirectoryIterator, nonexistent)
|
||||||
{
|
{
|
||||||
ASSERT_THROW(DirectoryIterator("/schnitzel/darmstadt/pommes"), SystemError);
|
ASSERT_THROW(DirectoryIterator("/schnitzel/darmstadt/pommes"), SysError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -47,16 +47,16 @@ TEST(fchmodatTryNoFollow, works)
|
|||||||
/* Check that symlinks are not followed and targets are not changed. */
|
/* Check that symlinks are not followed and targets are not changed. */
|
||||||
|
|
||||||
EXPECT_NO_THROW(
|
EXPECT_NO_THROW(
|
||||||
try { fchmodatTryNoFollow(dirFd.get(), CanonPath("filelink"), 0777); } catch (SystemError & e) {
|
try { fchmodatTryNoFollow(dirFd.get(), CanonPath("filelink"), 0777); } catch (SysError & e) {
|
||||||
if (!e.is(std::errc::operation_not_supported))
|
if (e.errNo != EOPNOTSUPP)
|
||||||
throw;
|
throw;
|
||||||
});
|
});
|
||||||
ASSERT_EQ(stat((tmpDir / "file").c_str(), &st), 0);
|
ASSERT_EQ(stat((tmpDir / "file").c_str(), &st), 0);
|
||||||
EXPECT_EQ(st.st_mode & 0777, 0644);
|
EXPECT_EQ(st.st_mode & 0777, 0644);
|
||||||
|
|
||||||
EXPECT_NO_THROW(
|
EXPECT_NO_THROW(
|
||||||
try { fchmodatTryNoFollow(dirFd.get(), CanonPath("dirlink"), 0777); } catch (SystemError & e) {
|
try { fchmodatTryNoFollow(dirFd.get(), CanonPath("dirlink"), 0777); } catch (SysError & e) {
|
||||||
if (!e.is(std::errc::operation_not_supported))
|
if (e.errNo != EOPNOTSUPP)
|
||||||
throw;
|
throw;
|
||||||
});
|
});
|
||||||
ASSERT_EQ(stat((tmpDir / "dir").c_str(), &st), 0);
|
ASSERT_EQ(stat((tmpDir / "dir").c_str(), &st), 0);
|
||||||
@@ -110,14 +110,14 @@ TEST(fchmodatTryNoFollow, fallbackWithoutProc)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
fchmodatTryNoFollow(dirFd.get(), CanonPath("file"), 0600);
|
fchmodatTryNoFollow(dirFd.get(), CanonPath("file"), 0600);
|
||||||
} catch (SystemError & e) {
|
} catch (SysError & e) {
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fchmodatTryNoFollow(dirFd.get(), CanonPath("link"), 0777);
|
fchmodatTryNoFollow(dirFd.get(), CanonPath("link"), 0777);
|
||||||
} catch (SystemError & e) {
|
} catch (SysError & e) {
|
||||||
if (e.is(std::errc::operation_not_supported))
|
if (e.errNo == EOPNOTSUPP)
|
||||||
_exit(0); /* Success. */
|
_exit(0); /* Success. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ std::set<ExperimentalFeature> parseFeatures(const StringSet & rawFeatures)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MissingExperimentalFeature::MissingExperimentalFeature(ExperimentalFeature feature, std::string reason)
|
MissingExperimentalFeature::MissingExperimentalFeature(ExperimentalFeature feature, std::string reason)
|
||||||
: Error(
|
: CloneableError(
|
||||||
"experimental Nix feature '%1%' is disabled%2%; add '--extra-experimental-features %1%' to enable it",
|
"experimental Nix feature '%1%' is disabled%2%; add '--extra-experimental-features %1%' to enable it",
|
||||||
showExperimentalFeature(feature),
|
showExperimentalFeature(feature),
|
||||||
Uncolored(optionalBracket(" (", reason, ")")))
|
Uncolored(optionalBracket(" (", reason, ")")))
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ DirectoryIterator::DirectoryIterator(const std::filesystem::path & p)
|
|||||||
// **Attempt to create the underlying directory_iterator**
|
// **Attempt to create the underlying directory_iterator**
|
||||||
it_ = std::filesystem::directory_iterator(p);
|
it_ = std::filesystem::directory_iterator(p);
|
||||||
} catch (const std::filesystem::filesystem_error & e) {
|
} catch (const std::filesystem::filesystem_error & e) {
|
||||||
// **Catch filesystem_error and throw SystemError**
|
// **Catch filesystem_error and throw SysError**
|
||||||
// Adapt the error message as needed for SystemError
|
// Adapt the error message as needed for SysError
|
||||||
throw SystemError(e.code(), "cannot read directory %s", PathFmt(p));
|
throw SysError("cannot read directory %s", PathFmt(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,11 +280,7 @@ bool pathAccessible(const std::filesystem::path & path)
|
|||||||
std::filesystem::path readLink(const std::filesystem::path & path)
|
std::filesystem::path readLink(const std::filesystem::path & path)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
try {
|
return std::filesystem::read_symlink(path);
|
||||||
return std::filesystem::read_symlink(path);
|
|
||||||
} catch (std::filesystem::filesystem_error & e) {
|
|
||||||
throw SystemError(e.code(), "reading symbolic link '%s'", PathFmt(path));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path readLink(const Path & path)
|
Path readLink(const Path & path)
|
||||||
@@ -467,7 +463,7 @@ void createDirs(const std::filesystem::path & path)
|
|||||||
try {
|
try {
|
||||||
std::filesystem::create_directories(path);
|
std::filesystem::create_directories(path);
|
||||||
} catch (std::filesystem::filesystem_error & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
throw SystemError(e.code(), "creating directory '%1%'", path.string());
|
throw SysError("creating directory '%1%'", path.string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,7 +664,7 @@ void replaceSymlink(const std::filesystem::path & target, const std::filesystem:
|
|||||||
} catch (std::filesystem::filesystem_error & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
if (e.code() == std::errc::file_exists)
|
if (e.code() == std::errc::file_exists)
|
||||||
continue;
|
continue;
|
||||||
throw SystemError(e.code(), "creating symlink %1% -> %2%", PathFmt(tmp), PathFmt(target));
|
throw SysError("creating symlink %1% -> %2%", PathFmt(tmp), PathFmt(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -676,7 +672,7 @@ void replaceSymlink(const std::filesystem::path & target, const std::filesystem:
|
|||||||
} catch (std::filesystem::filesystem_error & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
if (e.code() == std::errc::file_exists)
|
if (e.code() == std::errc::file_exists)
|
||||||
continue;
|
continue;
|
||||||
throw SystemError(e.code(), "renaming %1% to %2%", PathFmt(tmp), PathFmt(link));
|
throw SysError("renaming %1% to %2%", PathFmt(tmp), PathFmt(link));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -777,7 +773,7 @@ std::filesystem::path makeParentCanonical(const std::filesystem::path & rawPath)
|
|||||||
}
|
}
|
||||||
return std::filesystem::canonical(parent) / path.filename();
|
return std::filesystem::canonical(parent) / path.filename();
|
||||||
} catch (std::filesystem::filesystem_error & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
throw SystemError(e.code(), "canonicalising parent path of %1%", PathFmt(path));
|
throw SysError("canonicalising parent path of %1%", PathFmt(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include "nix/util/suggestions.hh"
|
#include "nix/util/suggestions.hh"
|
||||||
#include "nix/util/fmt.hh"
|
#include "nix/util/fmt.hh"
|
||||||
#include "nix/util/config.hh"
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <list>
|
#include <list>
|
||||||
@@ -127,20 +126,20 @@ public:
|
|||||||
BaseError & operator=(BaseError &&) = default;
|
BaseError & operator=(BaseError &&) = default;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
BaseError(unsigned int status, Args &&... args)
|
BaseError(unsigned int status, const Args &... args)
|
||||||
: err{.level = lvlError, .msg = HintFmt(std::forward<Args>(args)...), .pos = {}, .status = status}
|
: err{.level = lvlError, .msg = HintFmt(args...), .pos = {}, .status = status}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
explicit BaseError(const std::string & fs, Args &&... args)
|
explicit BaseError(const std::string & fs, const Args &... args)
|
||||||
: err{.level = lvlError, .msg = HintFmt(fs, std::forward<Args>(args)...), .pos = {}}
|
: err{.level = lvlError, .msg = HintFmt(fs, args...), .pos = {}}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
BaseError(const Suggestions & sug, Args &&... args)
|
BaseError(const Suggestions & sug, const Args &... args)
|
||||||
: err{.level = lvlError, .msg = HintFmt(std::forward<Args>(args)...), .pos = {}, .suggestions = sug}
|
: err{.level = lvlError, .msg = HintFmt(args...), .pos = {}, .suggestions = sug}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,9 +203,9 @@ public:
|
|||||||
* @param args... Format string arguments.
|
* @param args... Format string arguments.
|
||||||
*/
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void addTrace(std::shared_ptr<const Pos> && pos, std::string_view fs, Args &&... args)
|
void addTrace(std::shared_ptr<const Pos> && pos, std::string_view fs, const Args &... args)
|
||||||
{
|
{
|
||||||
addTrace(std::move(pos), HintFmt(std::string(fs), std::forward<Args>(args)...));
|
addTrace(std::move(pos), HintFmt(std::string(fs), args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,13 +226,31 @@ public:
|
|||||||
{
|
{
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[noreturn]] virtual void throwClone() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MakeError(newClass, superClass) \
|
template<typename Derived, typename Base>
|
||||||
class newClass : public superClass \
|
class CloneableError : public Base
|
||||||
{ \
|
{
|
||||||
public: \
|
public:
|
||||||
using superClass::superClass; \
|
using Base::Base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rethrow a copy of this exception. Useful when the exception can get
|
||||||
|
* modified when appending traces.
|
||||||
|
*/
|
||||||
|
[[noreturn]] void throwClone() const override
|
||||||
|
{
|
||||||
|
throw Derived(static_cast<const Derived &>(*this));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MakeError(newClass, superClass) \
|
||||||
|
class newClass : public CloneableError<newClass, superClass> \
|
||||||
|
{ \
|
||||||
|
public: \
|
||||||
|
using CloneableError<newClass, superClass>::CloneableError; \
|
||||||
}
|
}
|
||||||
|
|
||||||
MakeError(Error, BaseError);
|
MakeError(Error, BaseError);
|
||||||
@@ -245,115 +262,25 @@ MakeError(UnimplementedError, Error);
|
|||||||
* std::error_code. Use when you want to catch and check an error condition like
|
* std::error_code. Use when you want to catch and check an error condition like
|
||||||
* no_such_file_or_directory (ENOENT) without ifdefs.
|
* no_such_file_or_directory (ENOENT) without ifdefs.
|
||||||
*/
|
*/
|
||||||
class SystemError : public Error
|
class SystemError : public CloneableError<SystemError, Error>
|
||||||
{
|
{
|
||||||
std::error_code errorCode;
|
std::error_code errorCode;
|
||||||
std::string errorDetails;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Just here to allow the static methods to use the right constructor
|
|
||||||
* (the private one).
|
|
||||||
*/
|
|
||||||
struct Disambig
|
|
||||||
{};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private constructor with explicit error message string.
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
SystemError(Disambig, std::error_code errorCode, std::string_view errorDetails, Args &&... args)
|
|
||||||
: Error("")
|
|
||||||
, errorCode(errorCode)
|
|
||||||
, errorDetails(errorDetails)
|
|
||||||
{
|
|
||||||
auto hf = HintFmt(std::forward<Args>(args)...);
|
|
||||||
err.msg = HintFmt("%s: %s", Uncolored(hf.str()), errorDetails);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
template<typename... Args>
|
||||||
* Construct with an error code. The error code's message is automatically
|
SystemError(std::errc posixErrNo, Args &&... args)
|
||||||
* appended to the error message.
|
: CloneableError(std::forward<Args>(args)...)
|
||||||
*/
|
, errorCode(std::make_error_code(posixErrNo))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
SystemError(std::error_code errorCode, Args &&... args)
|
SystemError(std::error_code errorCode, Args &&... args)
|
||||||
: SystemError(Disambig{}, errorCode, errorCode.message(), std::forward<Args>(args)...)
|
: CloneableError(std::forward<Args>(args)...)
|
||||||
|
, errorCode(errorCode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a POSIX error using the explicitly-provided error number.
|
|
||||||
* `strerror` will be used to try to add additional information to the message.
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
static SystemError fromPosixExplicit(int errNo, Args &&... args)
|
|
||||||
{
|
|
||||||
return SystemError(
|
|
||||||
Disambig{},
|
|
||||||
std::make_error_code(static_cast<std::errc>(errNo)),
|
|
||||||
strerror(errNo),
|
|
||||||
std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a POSIX error using the ambient `errno`.
|
|
||||||
*
|
|
||||||
* Be sure to not perform another `errno`-modifying operation before
|
|
||||||
* calling this!
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
static SystemError fromPosix(Args &&... args)
|
|
||||||
{
|
|
||||||
return fromPosixExplicit(errno, std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
/**
|
|
||||||
* Construct a Windows error using the explicitly-provided error number.
|
|
||||||
* `FormatMessageA` will be used to try to add additional information
|
|
||||||
* to the message.
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
static SystemError fromWindowsExplicit(DWORD lastError, Args &&... args)
|
|
||||||
{
|
|
||||||
return SystemError(
|
|
||||||
Disambig{},
|
|
||||||
std::error_code(lastError, std::system_category()),
|
|
||||||
renderWindowsError(lastError),
|
|
||||||
std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a Windows error using `GetLastError()`.
|
|
||||||
*
|
|
||||||
* Be sure to not perform another last-error-modifying operation
|
|
||||||
* before calling this!
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
static SystemError fromWindows(Args &&... args)
|
|
||||||
{
|
|
||||||
return fromWindowsExplicit(GetLastError(), std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static std::string renderWindowsError(DWORD lastError);
|
|
||||||
|
|
||||||
public:
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct using the native error (errno on POSIX, GetLastError() on Windows).
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
static SystemError fromNative(Args &&... args)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
return fromWindows(std::forward<Args>(args)...);
|
|
||||||
#else
|
|
||||||
return fromPosix(std::forward<Args>(args)...);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::error_code ec() const &
|
const std::error_code ec() const &
|
||||||
{
|
{
|
||||||
return errorCode;
|
return errorCode;
|
||||||
@@ -366,58 +293,51 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper to avoid churn
|
* POSIX system error, created using `errno`, `strerror` friends.
|
||||||
|
*
|
||||||
|
* Throw this, but prefer not to catch this, and catch `SystemError`
|
||||||
|
* instead. This allows implementations to freely switch between this
|
||||||
|
* and `windows::WinError` without breaking catch blocks.
|
||||||
|
*
|
||||||
|
* However, it is permissible to catch this and rethrow so long as
|
||||||
|
* certain conditions are not met (e.g. to catch only if `errNo =
|
||||||
|
* EFooBar`). In that case, try to also catch the equivalent `windows::WinError`
|
||||||
|
* code.
|
||||||
|
*
|
||||||
|
* @todo Rename this to `PosixError` or similar. At this point Windows
|
||||||
|
* support is too WIP to justify the code churn, but if it is finished
|
||||||
|
* then a better identifier becomes moe worth it.
|
||||||
*/
|
*/
|
||||||
template<typename... Args>
|
class SysError final : public CloneableError<SysError, SystemError>
|
||||||
SystemError SysError(int errNo, Args &&... args)
|
|
||||||
{
|
{
|
||||||
return SystemError::fromPosixExplicit(errNo, std::forward<Args>(args)...);
|
public:
|
||||||
}
|
int errNo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper to avoid churn
|
* Construct using the explicitly-provided error number. `strerror`
|
||||||
*/
|
* will be used to try to add additional information to the message.
|
||||||
template<typename... Args>
|
*/
|
||||||
SystemError SysError(Args &&... args)
|
template<typename... Args>
|
||||||
{
|
SysError(int errNo, const Args &... args)
|
||||||
return SystemError::fromPosix(std::forward<Args>(args)...);
|
: CloneableError(static_cast<std::errc>(errNo), "")
|
||||||
}
|
, errNo(errNo)
|
||||||
|
{
|
||||||
|
auto hf = HintFmt(args...);
|
||||||
|
err.msg = HintFmt("%1%: %2%", Uncolored(hf.str()), strerror(errNo));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
/**
|
||||||
|
* Construct using the ambient `errno`.
|
||||||
namespace windows {
|
*
|
||||||
|
* Be sure to not perform another `errno`-modifying operation before
|
||||||
/**
|
* calling this constructor!
|
||||||
* Wrapper to avoid churn
|
*/
|
||||||
*/
|
template<typename... Args>
|
||||||
template<typename... Args>
|
SysError(const Args &... args)
|
||||||
SystemError WinError(DWORD lastError, Args &&... args)
|
: SysError(errno, args...)
|
||||||
{
|
{
|
||||||
return SystemError::fromWindowsExplicit(lastError, std::forward<Args>(args)...);
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper to avoid churn
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
SystemError WinError(Args &&... args)
|
|
||||||
{
|
|
||||||
return SystemError::fromWindows(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace windows
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience wrapper for when we use `errno`-based error handling
|
|
||||||
* on Unix, and `GetLastError()`-based error handling on Windows.
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
SystemError NativeSysError(Args &&... args)
|
|
||||||
{
|
|
||||||
return SystemError::fromNative(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw an exception for the purpose of checking that exception
|
* Throw an exception for the purpose of checking that exception
|
||||||
@@ -448,7 +368,7 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
|
|||||||
*/
|
*/
|
||||||
[[gnu::noinline, gnu::cold, noreturn]] void unreachable(std::source_location loc = std::source_location::current());
|
[[gnu::noinline, gnu::cold, noreturn]] void unreachable(std::source_location loc = std::source_location::current());
|
||||||
|
|
||||||
#if NIX_UBSAN_ENABLED
|
#if NIX_UBSAN_ENABLED == 1
|
||||||
/* When building with sanitizers, also enable expensive unreachable checks. In
|
/* When building with sanitizers, also enable expensive unreachable checks. In
|
||||||
optimised builds this explicitly invokes UB with std::unreachable for better
|
optimised builds this explicitly invokes UB with std::unreachable for better
|
||||||
optimisations. */
|
optimisations. */
|
||||||
@@ -457,4 +377,67 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
|
|||||||
# define nixUnreachableWhenHardened std::unreachable
|
# define nixUnreachableWhenHardened std::unreachable
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
namespace windows {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Windows Error type.
|
||||||
|
*
|
||||||
|
* Unless you need to catch a specific error number, don't catch this in
|
||||||
|
* portable code. Catch `SystemError` instead.
|
||||||
|
*/
|
||||||
|
class WinError : public CloneableError<WinError, SystemError>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DWORD lastError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct using the explicitly-provided error number.
|
||||||
|
* `FormatMessageA` will be used to try to add additional
|
||||||
|
* information to the message.
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
WinError(DWORD lastError, const Args &... args)
|
||||||
|
: CloneableError(std::error_code(lastError, std::system_category()), "")
|
||||||
|
, lastError(lastError)
|
||||||
|
{
|
||||||
|
auto hf = HintFmt(args...);
|
||||||
|
err.msg = HintFmt("%1%: %2%", Uncolored(hf.str()), renderError(lastError));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct using `GetLastError()` and the ambient "last error".
|
||||||
|
*
|
||||||
|
* Be sure to not perform another last-error-modifying operation
|
||||||
|
* before calling this constructor!
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
WinError(const Args &... args)
|
||||||
|
: WinError(GetLastError(), args...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::string renderError(DWORD lastError);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace windows
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience alias for when we use a `errno`-based error handling
|
||||||
|
* function on Unix, and `GetLastError()`-based error handling on on
|
||||||
|
* Windows.
|
||||||
|
*/
|
||||||
|
using NativeSysError =
|
||||||
|
#ifdef _WIN32
|
||||||
|
windows::WinError
|
||||||
|
#else
|
||||||
|
SysError
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
@@ -80,7 +80,7 @@ std::set<ExperimentalFeature> parseFeatures(const StringSet &);
|
|||||||
* An experimental feature was required for some (experimental)
|
* An experimental feature was required for some (experimental)
|
||||||
* operation, but was not enabled.
|
* operation, but was not enabled.
|
||||||
*/
|
*/
|
||||||
class MissingExperimentalFeature : public Error
|
class MissingExperimentalFeature final : public CloneableError<MissingExperimentalFeature, Error>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace linux {
|
|||||||
*
|
*
|
||||||
* @see https://man7.org/linux/man-pages/man2/openat2.2.html
|
* @see https://man7.org/linux/man-pages/man2/openat2.2.html
|
||||||
* @see https://man7.org/linux/man-pages/man2/open_how.2type.html
|
* @see https://man7.org/linux/man-pages/man2/open_how.2type.html
|
||||||
*
|
v*
|
||||||
* @param flags O_* flags
|
* @param flags O_* flags
|
||||||
* @param mode Mode for O_{CREAT,TMPFILE}
|
* @param mode Mode for O_{CREAT,TMPFILE}
|
||||||
* @param resolve RESOLVE_* flags
|
* @param resolve RESOLVE_* flags
|
||||||
@@ -97,7 +97,7 @@ namespace unix {
|
|||||||
* AT_SYMLINK_NOFOLLOW, since it's the best we can do without failing.
|
* AT_SYMLINK_NOFOLLOW, since it's the best we can do without failing.
|
||||||
*
|
*
|
||||||
* @pre path.isRoot() is false
|
* @pre path.isRoot() is false
|
||||||
* @throws SystemError if any operation fails
|
* @throws SysError if any operation fails
|
||||||
*/
|
*/
|
||||||
void fchmodatTryNoFollow(Descriptor dirFd, const CanonPath & path, mode_t mode);
|
void fchmodatTryNoFollow(Descriptor dirFd, const CanonPath & path, mode_t mode);
|
||||||
|
|
||||||
|
|||||||
@@ -189,19 +189,21 @@ Path readLink(const Path & path);
|
|||||||
*/
|
*/
|
||||||
std::filesystem::path readLink(const std::filesystem::path & path);
|
std::filesystem::path readLink(const std::filesystem::path & path);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
namespace windows {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the path associated with a file descriptor.
|
* Get the path associated with a file handle.
|
||||||
*
|
*
|
||||||
* @note One MUST only use this for error handling, because it creates
|
* @note One MUST only use this for error handling, because it creates
|
||||||
* TOCTOU issues. We don't mind if error messages point to out of date
|
* TOCTOU issues. We don't mind if error messages point to out of date
|
||||||
* paths (that is a rather trivial TOCTOU --- the error message is best
|
* paths (that is a rather trivial TOCTOU --- the error message is best
|
||||||
* effort) but for anything else we do.
|
* effort) but for anything else we do.
|
||||||
*
|
|
||||||
* @note this function will clobber `errno` (Unix) / "last error"
|
|
||||||
* (Windows), so care must be used to get those error codes, then call
|
|
||||||
* this, then build a `SystemError` with the saved error code.
|
|
||||||
*/
|
*/
|
||||||
std::filesystem::path descriptorToPath(Descriptor fd);
|
std::filesystem::path handleToPath(Descriptor handle);
|
||||||
|
|
||||||
|
} // namespace windows
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a `Descriptor` with read-only access to the given directory.
|
* Open a `Descriptor` with read-only access to the given directory.
|
||||||
|
|||||||
@@ -2,12 +2,7 @@
|
|||||||
|
|
||||||
include_dirs = [ include_directories('../..') ]
|
include_dirs = [ include_directories('../..') ]
|
||||||
|
|
||||||
config_pub_h = configure_file(
|
headers = files(
|
||||||
configuration : configdata_pub,
|
|
||||||
output : 'config.hh',
|
|
||||||
)
|
|
||||||
|
|
||||||
headers = [ config_pub_h ] + files(
|
|
||||||
'abstract-setting-to-json.hh',
|
'abstract-setting-to-json.hh',
|
||||||
'alignment.hh',
|
'alignment.hh',
|
||||||
'ansicolor.hh',
|
'ansicolor.hh',
|
||||||
|
|||||||
@@ -133,14 +133,14 @@ std::pair<int, std::string> runProgram(RunOptions && options);
|
|||||||
|
|
||||||
void runProgram2(const RunOptions & options);
|
void runProgram2(const RunOptions & options);
|
||||||
|
|
||||||
class ExecError : public Error
|
class ExecError final : public CloneableError<ExecError, Error>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
ExecError(int status, const Args &... args)
|
ExecError(int status, const Args &... args)
|
||||||
: Error(args...)
|
: CloneableError(args...)
|
||||||
, status(status)
|
, status(status)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,19 +231,19 @@ ref<SourceAccessor> makeEmptySourceAccessor();
|
|||||||
*/
|
*/
|
||||||
MakeError(RestrictedPathError, Error);
|
MakeError(RestrictedPathError, Error);
|
||||||
|
|
||||||
struct SymlinkNotAllowed : public Error
|
struct SymlinkNotAllowed final : public CloneableError<SymlinkNotAllowed, Error>
|
||||||
{
|
{
|
||||||
CanonPath path;
|
CanonPath path;
|
||||||
|
|
||||||
SymlinkNotAllowed(CanonPath path)
|
SymlinkNotAllowed(CanonPath path)
|
||||||
: Error("relative path '%s' points to a symlink, which is not allowed", path.rel())
|
: CloneableError("relative path '%s' points to a symlink, which is not allowed", path.rel())
|
||||||
, path(std::move(path))
|
, path(std::move(path))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
SymlinkNotAllowed(CanonPath path, const std::string & fs, Args &&... args)
|
SymlinkNotAllowed(CanonPath path, const std::string & fs, Args &&... args)
|
||||||
: Error(fs, std::forward<Args>(args)...)
|
: CloneableError(fs, std::forward<Args>(args)...)
|
||||||
, path(std::move(path))
|
, path(std::move(path))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ bool userNamespacesSupported()
|
|||||||
|
|
||||||
auto r = pid.wait();
|
auto r = pid.wait();
|
||||||
assert(!r);
|
assert(!r);
|
||||||
} catch (SystemError & e) {
|
} catch (SysError & e) {
|
||||||
debug("user namespaces do not work on this system: %s", e.msg());
|
debug("user namespaces do not work on this system: %s", e.msg());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ bool mountAndPidNamespacesSupported()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SystemError & e) {
|
} catch (SysError & e) {
|
||||||
debug("mount namespaces do not work on this system: %s", e.msg());
|
debug("mount namespaces do not work on this system: %s", e.msg());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-11
@@ -16,8 +16,7 @@ cxx = meson.get_compiler('cpp')
|
|||||||
|
|
||||||
subdir('nix-meson-build-support/deps-lists')
|
subdir('nix-meson-build-support/deps-lists')
|
||||||
|
|
||||||
configdata_pub = configuration_data()
|
configdata = configuration_data()
|
||||||
configdata_priv = configuration_data()
|
|
||||||
|
|
||||||
deps_private_maybe_subproject = []
|
deps_private_maybe_subproject = []
|
||||||
deps_public_maybe_subproject = []
|
deps_public_maybe_subproject = []
|
||||||
@@ -35,15 +34,9 @@ check_funcs = [
|
|||||||
foreach funcspec : check_funcs
|
foreach funcspec : check_funcs
|
||||||
define_name = 'HAVE_' + funcspec[0].underscorify().to_upper()
|
define_name = 'HAVE_' + funcspec[0].underscorify().to_upper()
|
||||||
define_value = cxx.has_function(funcspec[0]).to_int()
|
define_value = cxx.has_function(funcspec[0]).to_int()
|
||||||
configdata_priv.set(define_name, define_value, description : funcspec[1])
|
configdata.set(define_name, define_value, description : funcspec[1])
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
configdata_pub.set(
|
|
||||||
'NIX_UBSAN_ENABLED',
|
|
||||||
('undefined' in get_option('b_sanitize')).to_int(),
|
|
||||||
description : 'Whether nix has been built with UBSan enabled',
|
|
||||||
)
|
|
||||||
|
|
||||||
subdir('nix-meson-build-support/libatomic')
|
subdir('nix-meson-build-support/libatomic')
|
||||||
|
|
||||||
if host_machine.system() == 'windows'
|
if host_machine.system() == 'windows'
|
||||||
@@ -111,7 +104,7 @@ cpuid = dependency(
|
|||||||
version : '>= 0.7.0',
|
version : '>= 0.7.0',
|
||||||
required : cpuid_required,
|
required : cpuid_required,
|
||||||
)
|
)
|
||||||
configdata_priv.set('HAVE_LIBCPUID', cpuid.found().to_int())
|
configdata.set('HAVE_LIBCPUID', cpuid.found().to_int())
|
||||||
deps_private += cpuid
|
deps_private += cpuid
|
||||||
|
|
||||||
nlohmann_json = dependency('nlohmann_json', version : '>= 3.9')
|
nlohmann_json = dependency('nlohmann_json', version : '>= 3.9')
|
||||||
@@ -120,7 +113,7 @@ deps_public += nlohmann_json
|
|||||||
cxx = meson.get_compiler('cpp')
|
cxx = meson.get_compiler('cpp')
|
||||||
|
|
||||||
config_priv_h = configure_file(
|
config_priv_h = configure_file(
|
||||||
configuration : configdata_priv,
|
configuration : configdata,
|
||||||
output : 'util-config-private.hh',
|
output : 'util-config-private.hh',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ SourceAccessor::DirEntries PosixSourceAccessor::readDirectory(const CanonPath &
|
|||||||
if (e.code() == std::errc::permission_denied || e.code() == std::errc::operation_not_permitted)
|
if (e.code() == std::errc::permission_denied || e.code() == std::errc::operation_not_permitted)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
else
|
else
|
||||||
throw SystemError(e.code(), "getting status of '%s'", PathFmt(entry.path()));
|
throw;
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
res.emplace(entry.path().filename().string(), type);
|
res.emplace(entry.path().filename().string(), type);
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ bindConnectProcHelper(std::string_view operationName, auto && operation, Socket
|
|||||||
if (operation(fd, psaddr, sizeof(addr)) == -1)
|
if (operation(fd, psaddr, sizeof(addr)) == -1)
|
||||||
throw SysError("cannot %s to socket at '%s'", operationName, path);
|
throw SysError("cannot %s to socket at '%s'", operationName, path);
|
||||||
writeFull(pipe.writeSide.get(), "0\n");
|
writeFull(pipe.writeSide.get(), "0\n");
|
||||||
} catch (SystemError & e) {
|
} catch (SysError & e) {
|
||||||
writeFull(pipe.writeSide.get(), fmt("%d\n", e.ec().value()));
|
writeFull(pipe.writeSide.get(), fmt("%d\n", e.errNo));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
writeFull(pipe.writeSide.get(), "-1\n");
|
writeFull(pipe.writeSide.get(), "-1\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ void readFull(int fd, char * buf, size_t count)
|
|||||||
pollFD(fd, POLLIN);
|
pollFD(fd, POLLIN);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto savedErrno = errno;
|
throw SysError("reading from file");
|
||||||
throw SysError(savedErrno, "reading from file %s", PathFmt(descriptorToPath(fd)));
|
|
||||||
}
|
}
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
throw EndOfFile("unexpected end-of-file");
|
throw EndOfFile("unexpected end-of-file");
|
||||||
@@ -73,8 +72,7 @@ void writeFull(int fd, std::string_view s, bool allowInterrupts)
|
|||||||
pollFD(fd, POLLOUT);
|
pollFD(fd, POLLOUT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto savedErrno = errno;
|
throw SysError("writing to file");
|
||||||
throw SysError(savedErrno, "writing to file %s", PathFmt(descriptorToPath(fd)));
|
|
||||||
}
|
}
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
s.remove_prefix(res);
|
s.remove_prefix(res);
|
||||||
@@ -97,10 +95,8 @@ std::string readLine(int fd, bool eofOk, char terminator)
|
|||||||
pollFD(fd, POLLIN);
|
pollFD(fd, POLLIN);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
default: {
|
default:
|
||||||
auto savedErrno = errno;
|
throw SysError("reading a line");
|
||||||
throw SysError(savedErrno, "reading a line from %s", PathFmt(descriptorToPath(fd)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (rd == 0) {
|
} else if (rd == 0) {
|
||||||
if (eofOk)
|
if (eofOk)
|
||||||
@@ -188,7 +184,7 @@ void unix::closeExtraFDs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} catch (SystemError &) {
|
} catch (SysError &) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -71,10 +71,8 @@ void unix::fchmodatTryNoFollow(Descriptor dirFd, const CanonPath & path, mode_t
|
|||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
if (errno == ENOSYS)
|
if (errno == ENOSYS)
|
||||||
fchmodat2Unsupported.test_and_set();
|
fchmodat2Unsupported.test_and_set();
|
||||||
else {
|
else
|
||||||
auto savedErrno = errno;
|
throw SysError("fchmodat2 '%s' relative to parent directory", path.rel());
|
||||||
throw SysError(savedErrno, "fchmodat2 %s", PathFmt(descriptorToPath(dirFd) / path.rel()));
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -82,13 +80,10 @@ void unix::fchmodatTryNoFollow(Descriptor dirFd, const CanonPath & path, mode_t
|
|||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
AutoCloseFD pathFd = ::openat(dirFd, path.rel_c_str(), O_PATH | O_NOFOLLOW | O_CLOEXEC);
|
AutoCloseFD pathFd = ::openat(dirFd, path.rel_c_str(), O_PATH | O_NOFOLLOW | O_CLOEXEC);
|
||||||
if (!pathFd) {
|
if (!pathFd)
|
||||||
auto savedErrno = errno;
|
|
||||||
throw SysError(
|
throw SysError(
|
||||||
savedErrno,
|
"opening '%s' relative to parent directory to get an O_PATH file descriptor (fchmodat2 is unsupported)",
|
||||||
"opening %s to get an O_PATH file descriptor (fchmodat2 is unsupported)",
|
path.rel());
|
||||||
PathFmt(descriptorToPath(dirFd) / path.rel()));
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ::stat st;
|
struct ::stat st;
|
||||||
/* Possible since https://github.com/torvalds/linux/commit/55815f70147dcfa3ead5738fd56d3574e2e3c1c2 (3.6) */
|
/* Possible since https://github.com/torvalds/linux/commit/55815f70147dcfa3ead5738fd56d3574e2e3c1c2 (3.6) */
|
||||||
@@ -96,7 +91,7 @@ void unix::fchmodatTryNoFollow(Descriptor dirFd, const CanonPath & path, mode_t
|
|||||||
throw SysError("statting '%s' relative to parent directory via O_PATH file descriptor", path.rel());
|
throw SysError("statting '%s' relative to parent directory via O_PATH file descriptor", path.rel());
|
||||||
|
|
||||||
if (S_ISLNK(st.st_mode))
|
if (S_ISLNK(st.st_mode))
|
||||||
throw SysError(EOPNOTSUPP, "can't change mode of symlink %s", PathFmt(descriptorToPath(dirFd) / path.rel()));
|
throw SysError(EOPNOTSUPP, "can't change mode of symlink '%s' relative to parent directory", path.rel());
|
||||||
|
|
||||||
static std::atomic_flag dontHaveProc{};
|
static std::atomic_flag dontHaveProc{};
|
||||||
if (!dontHaveProc.test()) {
|
if (!dontHaveProc.test()) {
|
||||||
@@ -106,11 +101,8 @@ void unix::fchmodatTryNoFollow(Descriptor dirFd, const CanonPath & path, mode_t
|
|||||||
if (int res = ::chmod(selfProcFdPath.c_str(), mode); res == -1) {
|
if (int res = ::chmod(selfProcFdPath.c_str(), mode); res == -1) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
dontHaveProc.test_and_set();
|
dontHaveProc.test_and_set();
|
||||||
else {
|
else
|
||||||
auto savedErrno = errno;
|
throw SysError("chmod '%s' ('%s' relative to parent directory)", selfProcFdPath, path);
|
||||||
throw SysError(
|
|
||||||
savedErrno, "chmod %s (%s)", selfProcFdPath, PathFmt(descriptorToPath(dirFd) / path.rel()));
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -130,10 +122,8 @@ void unix::fchmodatTryNoFollow(Descriptor dirFd, const CanonPath & path, mode_t
|
|||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res == -1) {
|
if (res == -1)
|
||||||
auto savedErrno = errno;
|
throw SysError("fchmodat '%s' relative to parent directory", path.rel());
|
||||||
throw SysError(savedErrno, "fchmodat %s", PathFmt(descriptorToPath(dirFd) / path.rel()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Descriptor
|
static Descriptor
|
||||||
@@ -216,10 +206,9 @@ OsString readLinkAt(Descriptor dirFd, const CanonPath & path)
|
|||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
buf.resize(bufSize);
|
buf.resize(bufSize);
|
||||||
ssize_t rlSize = ::readlinkat(dirFd, path.rel_c_str(), buf.data(), bufSize);
|
ssize_t rlSize = ::readlinkat(dirFd, path.rel_c_str(), buf.data(), bufSize);
|
||||||
if (rlSize == -1) {
|
if (rlSize == -1)
|
||||||
auto savedErrno = errno;
|
throw SysError("reading symbolic link '%1%' relative to parent directory", path.rel());
|
||||||
throw SysError(savedErrno, "reading symbolic link %1%", PathFmt(descriptorToPath(dirFd) / path.rel()));
|
else if (rlSize < bufSize)
|
||||||
} else if (rlSize < bufSize)
|
|
||||||
return {buf.data(), static_cast<std::size_t>(rlSize)};
|
return {buf.data(), static_cast<std::size_t>(rlSize)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,31 +46,6 @@ Descriptor openNewFileForWrite(const std::filesystem::path & path, mode_t mode,
|
|||||||
return open(path.c_str(), flags, mode);
|
return open(path.c_str(), flags, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path descriptorToPath(Descriptor fd)
|
|
||||||
{
|
|
||||||
if (fd == STDIN_FILENO)
|
|
||||||
return "<stdin>";
|
|
||||||
if (fd == STDOUT_FILENO)
|
|
||||||
return "<stdout>";
|
|
||||||
if (fd == STDERR_FILENO)
|
|
||||||
return "<stderr>";
|
|
||||||
|
|
||||||
#if defined(__linux__)
|
|
||||||
try {
|
|
||||||
return readLink("/proc/self/fd/" + std::to_string(fd));
|
|
||||||
} catch (SystemError &) {
|
|
||||||
}
|
|
||||||
#elif HAVE_F_GETPATH
|
|
||||||
/* F_GETPATH requires PATH_MAX buffer per POSIX */
|
|
||||||
char buf[PATH_MAX];
|
|
||||||
if (fcntl(fd, F_GETPATH, buf) != -1)
|
|
||||||
return buf;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Fallback for unknown fd or unsupported platform */
|
|
||||||
return "<fd " + std::to_string(fd) + ">";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path defaultTempDir()
|
std::filesystem::path defaultTempDir()
|
||||||
{
|
{
|
||||||
return getEnvNonEmpty("TMPDIR").value_or("/tmp");
|
return getEnvNonEmpty("TMPDIR").value_or("/tmp");
|
||||||
@@ -186,9 +161,9 @@ static void _deletePath(
|
|||||||
if ((st.st_mode & PERM_MASK) != PERM_MASK)
|
if ((st.st_mode & PERM_MASK) != PERM_MASK)
|
||||||
try {
|
try {
|
||||||
unix::fchmodatTryNoFollow(parentfd, CanonPath(name), st.st_mode | PERM_MASK);
|
unix::fchmodatTryNoFollow(parentfd, CanonPath(name), st.st_mode | PERM_MASK);
|
||||||
} catch (SystemError & e) {
|
} catch (SysError & e) {
|
||||||
e.addTrace({}, "while making directory %1% accessible for deletion", PathFmt(path));
|
e.addTrace({}, "while making directory %1% accessible for deletion", PathFmt(path));
|
||||||
if (e.is(std::errc::operation_not_supported))
|
if (e.errNo == EOPNOTSUPP)
|
||||||
e.addTrace({}, "%1% is now a symlink, expected directory", PathFmt(path));
|
e.addTrace({}, "%1% is now a symlink, expected directory", PathFmt(path));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ inline void MonitorFdHup::runThread(int watchFd, int notifyFd)
|
|||||||
{
|
{
|
||||||
int kqResult = kqueue();
|
int kqResult = kqueue();
|
||||||
if (kqResult < 0) {
|
if (kqResult < 0) {
|
||||||
throw SystemError::fromPosix("MonitorFdHup kqueue");
|
throw SysError("MonitorFdHup kqueue");
|
||||||
}
|
}
|
||||||
AutoCloseFD kq{kqResult};
|
AutoCloseFD kq{kqResult};
|
||||||
|
|
||||||
@@ -78,14 +78,14 @@ inline void MonitorFdHup::runThread(int watchFd, int notifyFd)
|
|||||||
|
|
||||||
int result = kevent(kq.get(), kevs.data(), kevs.size(), nullptr, 0, nullptr);
|
int result = kevent(kq.get(), kevs.data(), kevs.size(), nullptr, 0, nullptr);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
throw SystemError::fromPosix("MonitorFdHup kevent add");
|
throw SysError("MonitorFdHup kevent add");
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
struct kevent event;
|
struct kevent event;
|
||||||
int numEvents = kevent(kq.get(), nullptr, 0, &event, 1, nullptr);
|
int numEvents = kevent(kq.get(), nullptr, 0, &event, 1, nullptr);
|
||||||
if (numEvents < 0) {
|
if (numEvents < 0) {
|
||||||
throw SystemError::fromPosix("MonitorFdHup kevent watch");
|
throw SysError("MonitorFdHup kevent watch");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numEvents > 0 && (event.flags & EV_EOF)) {
|
if (numEvents > 0 && (event.flags & EV_EOF)) {
|
||||||
@@ -112,7 +112,7 @@ inline void MonitorFdHup::runThread(int watchFd, int notifyFd)
|
|||||||
if (errno == EINTR || errno == EAGAIN) {
|
if (errno == EINTR || errno == EAGAIN) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
throw SystemError::fromPosix("in MonitorFdHup poll()");
|
throw SysError("in MonitorFdHup poll()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,6 @@ configdata_unix.set(
|
|||||||
description : 'Optionally used for changing the files and symlinks.',
|
description : 'Optionally used for changing the files and symlinks.',
|
||||||
)
|
)
|
||||||
|
|
||||||
configdata_unix.set(
|
|
||||||
'HAVE_F_GETPATH',
|
|
||||||
cxx.has_header_symbol('fcntl.h', 'F_GETPATH').to_int(),
|
|
||||||
description : 'Optionally used for getting the path of a file descriptor (macOS).',
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check for each of these functions, and create a define like `#define
|
# Check for each of these functions, and create a define like `#define
|
||||||
# HAVE_CLOSE_RANGE 1`.
|
# HAVE_CLOSE_RANGE 1`.
|
||||||
check_funcs_unix = [
|
check_funcs_unix = [
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ std::filesystem::path getHome()
|
|||||||
auto st = maybeStat(homeDir->c_str());
|
auto st = maybeStat(homeDir->c_str());
|
||||||
if (st && st->st_uid != geteuid())
|
if (st && st->st_uid != geteuid())
|
||||||
unownedUserHomeDir.swap(homeDir);
|
unownedUserHomeDir.swap(homeDir);
|
||||||
} catch (SystemError & e) {
|
} catch (SysError & e) {
|
||||||
warn(
|
warn(
|
||||||
"couldn't stat $HOME ('%s') for reason other than not existing, falling back to the one defined in the 'passwd' file: %s",
|
"couldn't stat $HOME ('%s') for reason other than not existing, falling back to the one defined in the 'passwd' file: %s",
|
||||||
*homeDir,
|
*homeDir,
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
using namespace nix::windows;
|
|
||||||
|
|
||||||
std::chrono::microseconds getCpuUserTime()
|
std::chrono::microseconds getCpuUserTime()
|
||||||
{
|
{
|
||||||
FILETIME creationTime;
|
FILETIME creationTime;
|
||||||
@@ -19,7 +17,7 @@ std::chrono::microseconds getCpuUserTime()
|
|||||||
|
|
||||||
if (!GetProcessTimes(GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime)) {
|
if (!GetProcessTimes(GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime)) {
|
||||||
auto lastError = GetLastError();
|
auto lastError = GetLastError();
|
||||||
throw WinError(lastError, "failed to get CPU time");
|
throw windows::WinError(lastError, "failed to get CPU time");
|
||||||
}
|
}
|
||||||
|
|
||||||
ULARGE_INTEGER uLargeInt;
|
ULARGE_INTEGER uLargeInt;
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ void writeFull(HANDLE handle, std::string_view s, bool allowInterrupts)
|
|||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
DWORD res;
|
DWORD res;
|
||||||
if (!WriteFile(handle, s.data(), s.size(), &res, NULL)) {
|
if (!WriteFile(handle, s.data(), s.size(), &res, NULL)) {
|
||||||
// Do this because `descriptorToPath` will overwrite the last error.
|
// Do this because `handleToPath` will overwrite the last error.
|
||||||
auto lastError = GetLastError();
|
auto lastError = GetLastError();
|
||||||
auto path = descriptorToPath(handle);
|
auto path = handleToPath(handle);
|
||||||
throw WinError(lastError, "writing to file %d:%s", handle, PathFmt(path));
|
throw WinError(lastError, "writing to file %d:%s", handle, PathFmt(path));
|
||||||
}
|
}
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
using namespace nix::windows;
|
||||||
|
|
||||||
namespace windows {
|
namespace windows {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -154,13 +156,13 @@ OsString readSymlinkTarget(HANDLE linkHandle)
|
|||||||
size_t path_buf_offset = offsetof(ReparseDataBuffer, SymbolicLinkReparseBuffer.PathBuffer[0]);
|
size_t path_buf_offset = offsetof(ReparseDataBuffer, SymbolicLinkReparseBuffer.PathBuffer[0]);
|
||||||
|
|
||||||
if (out < path_buf_offset) {
|
if (out < path_buf_offset) {
|
||||||
auto fullPath = descriptorToPath(linkHandle);
|
auto fullPath = handleToPath(linkHandle);
|
||||||
throw WinError(
|
throw WinError(
|
||||||
DWORD{ERROR_REPARSE_TAG_INVALID}, "invalid reparse data for %d:%s", linkHandle, PathFmt(fullPath));
|
DWORD{ERROR_REPARSE_TAG_INVALID}, "invalid reparse data for %d:%s", linkHandle, PathFmt(fullPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reparse->ReparseTag != IO_REPARSE_TAG_SYMLINK) {
|
if (reparse->ReparseTag != IO_REPARSE_TAG_SYMLINK) {
|
||||||
auto fullPath = descriptorToPath(linkHandle);
|
auto fullPath = handleToPath(linkHandle);
|
||||||
throw WinError(DWORD{ERROR_REPARSE_TAG_INVALID}, "not a symlink: %d:%s", linkHandle, PathFmt(fullPath));
|
throw WinError(DWORD{ERROR_REPARSE_TAG_INVALID}, "not a symlink: %d:%s", linkHandle, PathFmt(fullPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +179,7 @@ OsString readSymlinkTarget(HANDLE linkHandle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (path_buf_offset + name_offset + name_length > out) {
|
if (path_buf_offset + name_offset + name_length > out) {
|
||||||
auto fullPath = descriptorToPath(linkHandle);
|
auto fullPath = handleToPath(linkHandle);
|
||||||
throw WinError(
|
throw WinError(
|
||||||
DWORD{ERROR_REPARSE_TAG_INVALID}, "invalid symlink data for %d:%s", linkHandle, PathFmt(fullPath));
|
DWORD{ERROR_REPARSE_TAG_INVALID}, "invalid symlink data for %d:%s", linkHandle, PathFmt(fullPath));
|
||||||
}
|
}
|
||||||
@@ -208,8 +210,6 @@ bool isReparsePoint(HANDLE handle)
|
|||||||
|
|
||||||
} // namespace windows
|
} // namespace windows
|
||||||
|
|
||||||
using namespace nix::windows;
|
|
||||||
|
|
||||||
Descriptor openFileEnsureBeneathNoSymlinks(
|
Descriptor openFileEnsureBeneathNoSymlinks(
|
||||||
Descriptor dirFd, const CanonPath & path, ACCESS_MASK desiredAccess, ULONG createOptions, ULONG createDisposition)
|
Descriptor dirFd, const CanonPath & path, ACCESS_MASK desiredAccess, ULONG createOptions, ULONG createDisposition)
|
||||||
{
|
{
|
||||||
@@ -259,10 +259,9 @@ Descriptor openFileEnsureBeneathNoSymlinks(
|
|||||||
FILE_TRAVERSE | SYNCHRONIZE, // Just need traversal rights
|
FILE_TRAVERSE | SYNCHRONIZE, // Just need traversal rights
|
||||||
FILE_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT // Open directory, don't follow symlinks
|
FILE_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT // Open directory, don't follow symlinks
|
||||||
);
|
);
|
||||||
} catch (SystemError & e) {
|
} catch (WinError & e) {
|
||||||
/* Check if this is because it's a symlink */
|
/* Check if this is because it's a symlink */
|
||||||
auto err = e.ec().value();
|
if (e.lastError == ERROR_CANT_ACCESS_FILE || e.lastError == ERROR_ACCESS_DENIED) {
|
||||||
if (err == ERROR_CANT_ACCESS_FILE || err == ERROR_ACCESS_DENIED) {
|
|
||||||
throwIfSymlink(wcomponent, pathUpTo(std::next(it)));
|
throwIfSymlink(wcomponent, pathUpTo(std::next(it)));
|
||||||
}
|
}
|
||||||
throw;
|
throw;
|
||||||
@@ -287,9 +286,9 @@ Descriptor openFileEnsureBeneathNoSymlinks(
|
|||||||
desiredAccess,
|
desiredAccess,
|
||||||
createOptions | FILE_OPEN_REPARSE_POINT, // Don't follow symlinks on final component either
|
createOptions | FILE_OPEN_REPARSE_POINT, // Don't follow symlinks on final component either
|
||||||
createDisposition);
|
createDisposition);
|
||||||
} catch (SystemError & e) {
|
} catch (WinError & e) {
|
||||||
/* Check if final component is a symlink when we requested to not follow it */
|
/* Check if final component is a symlink when we requested to not follow it */
|
||||||
if (e.ec().value() == ERROR_CANT_ACCESS_FILE) {
|
if (e.lastError == ERROR_CANT_ACCESS_FILE) {
|
||||||
throwIfSymlink(finalComponent, path);
|
throwIfSymlink(finalComponent, path);
|
||||||
}
|
}
|
||||||
throw;
|
throw;
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ void deletePath(const std::filesystem::path & path, uint64_t & bytesFreed)
|
|||||||
deletePath(path);
|
deletePath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path descriptorToPath(Descriptor handle)
|
std::filesystem::path windows::handleToPath(HANDLE handle)
|
||||||
{
|
{
|
||||||
std::vector<wchar_t> buf(0x100);
|
std::vector<wchar_t> buf(0x100);
|
||||||
DWORD dw = GetFinalPathNameByHandleW(handle, buf.data(), buf.size(), FILE_NAME_OPENED);
|
DWORD dw = GetFinalPathNameByHandleW(handle, buf.data(), buf.size(), FILE_NAME_OPENED);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
namespace nix::windows::known_folders {
|
namespace nix::windows::known_folders {
|
||||||
|
|
||||||
|
using namespace nix::windows;
|
||||||
|
|
||||||
static std::filesystem::path getKnownFolder(REFKNOWNFOLDERID rfid)
|
static std::filesystem::path getKnownFolder(REFKNOWNFOLDERID rfid)
|
||||||
{
|
{
|
||||||
PWSTR str = nullptr;
|
PWSTR str = nullptr;
|
||||||
|
|||||||
@@ -7,17 +7,15 @@
|
|||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
using namespace nix::windows;
|
|
||||||
|
|
||||||
void MuxablePipePollState::poll(HANDLE ioport, std::optional<unsigned int> timeout)
|
void MuxablePipePollState::poll(HANDLE ioport, std::optional<unsigned int> timeout)
|
||||||
{
|
{
|
||||||
/* We are on at least Windows Vista / Server 2008 and can get many
|
/* We are on at least Windows Vista / Server 2008 and can get many
|
||||||
(countof(oentries)) statuses in one API call. */
|
(countof(oentries)) statuses in one API call. */
|
||||||
if (!GetQueuedCompletionStatusEx(
|
if (!GetQueuedCompletionStatusEx(
|
||||||
ioport, oentries, sizeof(oentries) / sizeof(*oentries), &removed, timeout ? *timeout : INFINITE, false)) {
|
ioport, oentries, sizeof(oentries) / sizeof(*oentries), &removed, timeout ? *timeout : INFINITE, false)) {
|
||||||
auto lastError = GetLastError();
|
windows::WinError winError("GetQueuedCompletionStatusEx");
|
||||||
if (lastError != WAIT_TIMEOUT)
|
if (winError.lastError != WAIT_TIMEOUT)
|
||||||
throw WinError(lastError, "GetQueuedCompletionStatusEx");
|
throw winError;
|
||||||
assert(removed == 0);
|
assert(removed == 0);
|
||||||
} else {
|
} else {
|
||||||
assert(0 < removed && removed <= sizeof(oentries) / sizeof(*oentries));
|
assert(0 < removed && removed <= sizeof(oentries) / sizeof(*oentries));
|
||||||
@@ -54,12 +52,12 @@ void MuxablePipePollState::iterate(
|
|||||||
// here is possible (but not obligatory) to call
|
// here is possible (but not obligatory) to call
|
||||||
// `handleRead` and repeat ReadFile immediately
|
// `handleRead` and repeat ReadFile immediately
|
||||||
} else {
|
} else {
|
||||||
auto lastError = GetLastError();
|
windows::WinError winError("ReadFile(%s, ..)", (*p)->readSide.get());
|
||||||
if (lastError == ERROR_BROKEN_PIPE) {
|
if (winError.lastError == ERROR_BROKEN_PIPE) {
|
||||||
handleEOF((*p)->readSide.get());
|
handleEOF((*p)->readSide.get());
|
||||||
nextp = channels.erase(p); // no need to maintain `channels` ?
|
nextp = channels.erase(p); // no need to maintain `channels` ?
|
||||||
} else if (lastError != ERROR_IO_PENDING)
|
} else if (winError.lastError != ERROR_IO_PENDING)
|
||||||
throw WinError(lastError, "ReadFile(%s, ..)", (*p)->readSide.get());
|
throw winError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
# define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix::windows {
|
||||||
|
|
||||||
std::string SystemError::renderWindowsError(DWORD lastError)
|
std::string WinError::renderError(DWORD lastError)
|
||||||
{
|
{
|
||||||
LPSTR errorText = NULL;
|
LPSTR errorText = NULL;
|
||||||
|
|
||||||
@@ -32,5 +32,5 @@ std::string SystemError::renderWindowsError(DWORD lastError)
|
|||||||
return fmt("CODE=%d", lastError);
|
return fmt("CODE=%d", lastError);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix::windows
|
||||||
#endif
|
#endif
|
||||||
@@ -17,7 +17,7 @@ void showManPage(const std::string & name)
|
|||||||
setEnv("MANPATH", (getNixManDir().string() + ":").c_str());
|
setEnv("MANPATH", (getNixManDir().string() + ":").c_str());
|
||||||
execlp("man", "man", name.c_str(), nullptr);
|
execlp("man", "man", name.c_str(), nullptr);
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
// Not SystemError because we don't want to suffix the errno, aka No such file or directory.
|
// Not SysError because we don't want to suffix the errno, aka No such file or directory.
|
||||||
throw Error(
|
throw Error(
|
||||||
"The '%1%' command was not found, but it is needed for '%2%' and some other '%3%' commands' help text. Perhaps you could install the '%1%' command?",
|
"The '%1%' command was not found, but it is needed for '%2%' and some other '%3%' commands' help text. Perhaps you could install the '%1%' command?",
|
||||||
"man",
|
"man",
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ void removeOldGenerations(std::filesystem::path dir)
|
|||||||
std::string link;
|
std::string link;
|
||||||
try {
|
try {
|
||||||
link = readLink(path);
|
link = readLink(path);
|
||||||
} catch (SystemError & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
if (e.is(std::errc::no_such_file_or_directory))
|
if (e.code() == std::errc::no_such_file_or_directory)
|
||||||
continue;
|
continue;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1419,6 +1419,7 @@ static int main_nix_env(int argc, char ** argv)
|
|||||||
replaceSymlink(defaultChannelsDir(profilesDirOpts), nixExprPath / "channels");
|
replaceSymlink(defaultChannelsDir(profilesDirOpts), nixExprPath / "channels");
|
||||||
if (!isRootUser())
|
if (!isRootUser())
|
||||||
replaceSymlink(rootChannelsDir(profilesDirOpts), nixExprPath / "channels_root");
|
replaceSymlink(rootChannelsDir(profilesDirOpts), nixExprPath / "channels_root");
|
||||||
|
} catch (std::filesystem::filesystem_error &) {
|
||||||
} catch (Error &) {
|
} catch (Error &) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user