mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 04:12:39 +00:00
- We were using primitive versions of mkstemp and mkdtemp, they have been converted to use LibCore::System. - If an error occurred whilst creating a temporary directory or file, it was thrown and the program would crash. Now, we use ErrorOr<T> so that the caller can handle the error accordingly - The `Type` enumeration has been made private, and `create_temp` has been "split" (although rewritten) into create_temp_directory and create_temp_file. The old pattern of TempFile::create_temp(Type::File) felt a bit awkward, and TempFile::create_temp_file() feels a bit nicer to use! :^) Once the Core::Filesystem PR is merged (#17789), it would be better for this helper to be merged in with that. But until then, this is a nice improvement.
41 lines
659 B
C++
41 lines
659 B
C++
/*
|
|
* Copyright (c) 2020-2023, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <AK/String.h>
|
|
|
|
namespace Core {
|
|
|
|
class TempFile {
|
|
|
|
public:
|
|
static ErrorOr<NonnullOwnPtr<TempFile>> create_temp_directory();
|
|
static ErrorOr<NonnullOwnPtr<TempFile>> create_temp_file();
|
|
|
|
~TempFile();
|
|
|
|
String const& path() const { return m_path; }
|
|
|
|
private:
|
|
enum class Type {
|
|
Directory,
|
|
File
|
|
};
|
|
|
|
TempFile(Type type, String path)
|
|
: m_type(type)
|
|
, m_path(move(path))
|
|
{
|
|
}
|
|
|
|
Type m_type;
|
|
String m_path;
|
|
};
|
|
|
|
}
|