diff --git a/include/vcpkg/base/files.h b/include/vcpkg/base/files.h index d9b08a46fc..4e0ce2274b 100644 --- a/include/vcpkg/base/files.h +++ b/include/vcpkg/base/files.h @@ -334,6 +334,8 @@ namespace vcpkg virtual bool last_write_time(DiagnosticContext& context, const Path& target, int64_t new_time) const = 0; + virtual bool set_executable(DiagnosticContext& context, const Path& target) const = 0; + using ReadOnlyFilesystem::current_path; virtual void current_path(const Path& new_current_path, std::error_code&) const = 0; void current_path(const Path& new_current_path, LineInfo li) const; diff --git a/src/vcpkg/base/files.cpp b/src/vcpkg/base/files.cpp index 617250284b..251651a2b3 100644 --- a/src/vcpkg/base/files.cpp +++ b/src/vcpkg/base/files.cpp @@ -4051,6 +4051,31 @@ namespace vcpkg #endif // ^^^ !_WIN32 } + virtual bool set_executable(DiagnosticContext& context, const Path& target) const override + { +#if defined(_WIN32) + // On Windows, executability is determined by file extension, not permissions. + (void)context; + (void)target; + return true; +#else // ^^^ _WIN32 // !_WIN32 vvv + if (::chmod(target.c_str(), 0755) != 0) + { + auto local_errno = errno; + context.report( + DiagnosticLine{DiagKind::Error, + target, + msg::format(msgSystemApiErrorMessage, + msg::system_api = "chmod", + msg::exit_code = local_errno, + msg::error_msg = std::generic_category().message(local_errno))}); + return false; + } + + return true; +#endif // ^^^ !_WIN32 + } + virtual void write_contents(const Path& file_path, StringView data, std::error_code& ec) const override { StatsTimer t(g_us_filesystem_stats); @@ -4494,6 +4519,19 @@ namespace vcpkg return false; } + bool set_executable(DiagnosticContext& context, const Path&) const override + { + context.report_system_error("set_executable", +#if defined(_WIN32) + ERROR_NOT_SUPPORTED +#else + ENOTSUP +#endif + ); + + return false; + } + void current_path(const Path&, std::error_code& ec) const override { assign_not_supported(ec); } std::unique_ptr take_exclusive_file_lock(DiagnosticContext& context, diff --git a/src/vcpkg/tools.cpp b/src/vcpkg/tools.cpp index e2e2a899f1..3bb3ff57b5 100644 --- a/src/vcpkg/tools.cpp +++ b/src/vcpkg/tools.cpp @@ -1052,6 +1052,7 @@ namespace vcpkg return nullopt; } + fs.set_executable(context, exe_path); return exe_path; }