summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorCameron Youell <cameronyouell@gmail.com>2023-03-22 02:36:18 +1100
committerLinus Groh <mail@linusgroh.de>2023-03-21 19:03:21 +0000
commit752f06f228119a70c59e844dcd2b9560e757b0ff (patch)
tree639eb770fb4db090adc69bfa77a19655fea4fa77 /Userland/Libraries/LibCore
parent492e5c3c14e4c15c2a655b876f4c77c1df30bb00 (diff)
downloadserenity-752f06f228119a70c59e844dcd2b9560e757b0ff.zip
LibFileSystem: Move `TempFile` from `LibCore` to `LibFileSystem`
As suggested in commit de18485
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibCore/TempFile.cpp43
-rw-r--r--Userland/Libraries/LibCore/TempFile.h41
3 files changed, 0 insertions, 85 deletions
diff --git a/Userland/Libraries/LibCore/CMakeLists.txt b/Userland/Libraries/LibCore/CMakeLists.txt
index 6dee12a65c..1a5b3fcbd3 100644
--- a/Userland/Libraries/LibCore/CMakeLists.txt
+++ b/Userland/Libraries/LibCore/CMakeLists.txt
@@ -30,7 +30,6 @@ set(SOURCES
System.cpp
SystemServerTakeover.cpp
TCPServer.cpp
- TempFile.cpp
Timer.cpp
UDPServer.cpp
Version.cpp
diff --git a/Userland/Libraries/LibCore/TempFile.cpp b/Userland/Libraries/LibCore/TempFile.cpp
deleted file mode 100644
index 8558847e43..0000000000
--- a/Userland/Libraries/LibCore/TempFile.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2020-2023, the SerenityOS developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "TempFile.h"
-#include <LibCore/DeprecatedFile.h>
-#include <LibCore/System.h>
-
-namespace Core {
-
-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));
-}
-
-ErrorOr<NonnullOwnPtr<TempFile>> TempFile::create_temp_file()
-{
- char file_path[] = "/tmp/tmp.XXXXXX";
- TRY(Core::System::mkstemp(file_path));
-
- auto string = TRY(String::from_utf8({ file_path, sizeof file_path }));
- return adopt_nonnull_own_or_enomem(new (nothrow) TempFile(Type::File, string));
-}
-
-TempFile::~TempFile()
-{
- // Temporary files aren't removed by anyone else, so we must do it ourselves.
- auto recursion_mode = DeprecatedFile::RecursionMode::Disallowed;
- if (m_type == Type::Directory)
- recursion_mode = DeprecatedFile::RecursionMode::Allowed;
-
- auto result = DeprecatedFile::remove(m_path, recursion_mode);
- if (result.is_error()) {
- warnln("Removal of temporary file failed: {}", result.error().string_literal());
- }
-}
-
-}
diff --git a/Userland/Libraries/LibCore/TempFile.h b/Userland/Libraries/LibCore/TempFile.h
deleted file mode 100644
index ac1743a165..0000000000
--- a/Userland/Libraries/LibCore/TempFile.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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;
-};
-
-}