mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:37:36 +00:00
LibCore: Add utility class for temporary files and directories
Core::TempFile is a RAII type that creates a temporary file or directory on construction and deletes it on destruction.
This commit is contained in:
parent
28a6686f2c
commit
95545648bd
3 changed files with 97 additions and 0 deletions
37
Userland/Libraries/LibCore/TempFile.h
Normal file
37
Userland/Libraries/LibCore/TempFile.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/String.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class TempFile {
|
||||
AK_MAKE_NONCOPYABLE(TempFile);
|
||||
AK_MAKE_NONMOVABLE(TempFile);
|
||||
|
||||
public:
|
||||
enum class Type {
|
||||
File,
|
||||
Directory
|
||||
};
|
||||
|
||||
static NonnullOwnPtr<TempFile> create(Type = Type::File);
|
||||
~TempFile();
|
||||
|
||||
String path() const { return m_path; }
|
||||
|
||||
private:
|
||||
TempFile(Type);
|
||||
static String create_temp(Type);
|
||||
|
||||
Type m_type { Type::File };
|
||||
String m_path;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue