mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
LibCore: Return a ByteString from System::mkdtemp
Paths are not necessarily UTF-8. While it doesn't matter much here, for consistency with other parts of the system, let's use ByteStrings for paths.
This commit is contained in:
1 parent
486f092675
commit
155c847d6c
4 files changed
+7
-6
No files matched your search
@@ -1159,14 +1159,14 @@ ErrorOr<int> mkstemp(Span<char> pattern)
|
||||
return fd;
|
||||
}
|
||||
|
||||
ErrorOr<String> mkdtemp(Span<char> pattern)
|
||||
ErrorOr<ByteString> mkdtemp(Span<char> pattern)
|
||||
{
|
||||
auto* path = ::mkdtemp(pattern.data());
|
||||
if (path == nullptr) {
|
||||
return Error::from_errno(errno);
|
||||
}
|
||||
|
||||
return String::from_utf8(StringView { path, strlen(path) });
|
||||
return ByteString { path, strlen(path) };
|
||||
}
|
||||
|
||||
ErrorOr<void> rename(StringView old_path, StringView new_path)
|
||||
|
||||
@@ -185,7 +185,7 @@ ErrorOr<void> chdir(StringView path);
|
||||
ErrorOr<void> rmdir(StringView path);
|
||||
ErrorOr<pid_t> fork();
|
||||
ErrorOr<int> mkstemp(Span<char> pattern);
|
||||
ErrorOr<String> mkdtemp(Span<char> pattern);
|
||||
ErrorOr<ByteString> mkdtemp(Span<char> pattern);
|
||||
ErrorOr<void> fchmod(int fd, mode_t mode);
|
||||
ErrorOr<void> fchown(int fd, uid_t, gid_t);
|
||||
ErrorOr<void> rename(StringView old_path, StringView new_path);
|
||||
|
||||
@@ -28,7 +28,8 @@ ErrorOr<NonnullOwnPtr<TempFile>> TempFile::create_temp_directory()
|
||||
char pattern[] = "/tmp/tmp.XXXXXX";
|
||||
|
||||
auto path = TRY(Core::System::mkdtemp(pattern));
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) TempFile(Type::Directory, path));
|
||||
auto string = TRY(String::from_byte_string(path));
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) TempFile(Type::Directory, string));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<TempFile>> TempFile::create_temp_file()
|
||||
|
||||
@@ -23,12 +23,12 @@ static ErrorOr<void> create_custom_vfs_root_context_layout(JsonArray const& layo
|
||||
char pattern[] = "/tmp/container_root_XXXXXX";
|
||||
auto temp_directory_path = TRY(Core::System::mkdtemp(pattern));
|
||||
TRY(LayoutParsing::create_root_mount_point(temp_directory_path, layout_creation_sequence));
|
||||
auto vfs_root_context_layout = TRY(VFSRootContextLayout::create_with_root_mount_point(temp_directory_path.bytes_as_string_view()));
|
||||
auto vfs_root_context_layout = TRY(VFSRootContextLayout::create_with_root_mount_point(temp_directory_path));
|
||||
TRY(LayoutParsing::handle_creation_sequence(*vfs_root_context_layout, layout_creation_sequence));
|
||||
|
||||
TRY(vfs_root_context_layout->apply_mounts_on_vfs_root_context_id());
|
||||
|
||||
TRY(Core::System::umount({}, temp_directory_path.bytes_as_string_view()));
|
||||
TRY(Core::System::umount({}, temp_directory_path));
|
||||
|
||||
TRY(Core::System::rmdir(temp_directory_path));
|
||||
|
||||
|
||||
Reference in new issue
Block a user