mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
HackStudio: Use Core::Process API to run template post-create programs
This commit is contained in:
parent
5205634ed4
commit
ae297e4405
1 changed files with 7 additions and 10 deletions
|
@ -11,10 +11,10 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibCore/DirIterator.h>
|
#include <LibCore/DirIterator.h>
|
||||||
|
#include <LibCore/Process.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <spawn.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -92,17 +92,14 @@ ErrorOr<void> ProjectTemplate::create_project(ByteString const& name, ByteString
|
||||||
|
|
||||||
// Generate a namespace-safe project name (replace hyphens with underscores)
|
// Generate a namespace-safe project name (replace hyphens with underscores)
|
||||||
auto namespace_safe = name.replace("-"sv, "_"sv, ReplaceMode::All);
|
auto namespace_safe = name.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||||
|
auto child_process = TRY(Core::Process::spawn({
|
||||||
char const* argv[] = { postcreate_script_path.characters(), name.characters(), path.characters(), namespace_safe.characters(), nullptr };
|
.executable = postcreate_script_path,
|
||||||
|
.arguments = { name, path, namespace_safe },
|
||||||
pid_t child_pid = TRY(Core::System::posix_spawn(postcreate_script_path, nullptr, nullptr, const_cast<char**>(argv), environ));
|
}));
|
||||||
|
|
||||||
// Command spawned, wait for exit.
|
// Command spawned, wait for exit.
|
||||||
auto waitpid_result = TRY(Core::System::waitpid(child_pid, 0));
|
auto child_exited_with_0 = TRY(child_process.wait_for_termination());
|
||||||
int child_error = WEXITSTATUS(waitpid_result.status);
|
if (!child_exited_with_0)
|
||||||
dbgln("Post-create script exited with code {}", child_error);
|
|
||||||
|
|
||||||
if (child_error != 0)
|
|
||||||
return Error::from_string_literal("Project post-creation script exited with non-zero error code.");
|
return Error::from_string_literal("Project post-creation script exited with non-zero error code.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue