1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:57:45 +00:00

LibCore: Use StringView instead of char * in Account

This commit is contained in:
Lucas CHOLLET 2022-06-10 20:06:06 +02:00 committed by Sam Atkins
parent 0396b6da82
commit 507cb411c2
10 changed files with 33 additions and 36 deletions

View file

@ -30,11 +30,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
int gid = 0;
bool lock = false;
bool unlock = false;
char const* new_home_directory = nullptr;
StringView new_home_directory;
bool move_home = false;
char const* shell = nullptr;
char const* gecos = nullptr;
char const* username = nullptr;
StringView shell;
StringView gecos;
StringView username;
auto args_parser = Core::ArgsParser();
args_parser.set_general_help("Modify a user account");
@ -62,7 +62,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (move_home) {
TRY(Core::System::unveil(target_account.home_directory(), "c"sv));
TRY(Core::System::unveil({ new_home_directory, strlen(new_home_directory) }, "wc"sv));
TRY(Core::System::unveil(new_home_directory, "wc"sv));
}
unveil(nullptr, nullptr);
@ -98,11 +98,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
target_account.set_password_enabled(true);
}
if (new_home_directory) {
if (!new_home_directory.is_empty()) {
if (move_home) {
int rc = rename(target_account.home_directory().characters(), new_home_directory);
if (rc < 0) {
if (errno == EXDEV) {
auto maybe_error = Core::System::rename(target_account.home_directory(), new_home_directory);
if (maybe_error.is_error()) {
if (maybe_error.error().code() == EXDEV) {
auto result = Core::File::copy_file_or_directory(
new_home_directory, target_account.home_directory().characters(),
Core::File::RecursionMode::Allowed,
@ -113,11 +113,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
warnln("usermod: could not move directory {} : {}", target_account.home_directory().characters(), static_cast<Error const&>(result.error()));
return 1;
}
rc = unlink(target_account.home_directory().characters());
if (rc < 0)
warnln("usermod: unlink {} : {}", target_account.home_directory().characters(), strerror(errno));
maybe_error = Core::System::unlink(target_account.home_directory());
if (maybe_error.is_error())
warnln("usermod: unlink {} : {}", target_account.home_directory(), maybe_error.error().code());
} else {
warnln("usermod: could not move directory {} : {}", target_account.home_directory().characters(), strerror(errno));
warnln("usermod: could not move directory {} : {}", target_account.home_directory(), maybe_error.error().code());
}
}
}
@ -125,11 +125,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
target_account.set_home_directory(new_home_directory);
}
if (shell) {
if (!shell.is_empty()) {
target_account.set_shell(shell);
}
if (gecos) {
if (!gecos.is_empty()) {
target_account.set_gecos(gecos);
}