mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:17:41 +00:00
LibFileSystem: Move TempFile
from LibCore
to LibFileSystem
As suggested in commit de18485
This commit is contained in:
parent
492e5c3c14
commit
752f06f228
6 changed files with 22 additions and 23 deletions
|
@ -23,9 +23,9 @@
|
||||||
#include <LibCore/Process.h>
|
#include <LibCore/Process.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibCore/TempFile.h>
|
|
||||||
#include <LibDesktop/Launcher.h>
|
#include <LibDesktop/Launcher.h>
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
|
#include <LibFileSystem/TempFile.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/ActionGroup.h>
|
#include <LibGUI/ActionGroup.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
|
@ -115,7 +115,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
if (!FileSystem::is_directory(initial_location)) {
|
if (!FileSystem::is_directory(initial_location)) {
|
||||||
// We want to extract zips to a temporary directory when FileManager is launched with a .zip file as its first argument
|
// We want to extract zips to a temporary directory when FileManager is launched with a .zip file as its first argument
|
||||||
if (path.has_extension(".zip"sv)) {
|
if (path.has_extension(".zip"sv)) {
|
||||||
auto temp_directory = Core::TempFile::create_temp_directory();
|
auto temp_directory = FileSystem::TempFile::create_temp_directory();
|
||||||
if (temp_directory.is_error()) {
|
if (temp_directory.is_error()) {
|
||||||
dbgln("Failed to create temporary directory during zip extraction: {}", temp_directory.error());
|
dbgln("Failed to create temporary directory during zip extraction: {}", temp_directory.error());
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include "TerminalWrapper.h"
|
#include "TerminalWrapper.h"
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
#include <LibCore/TempFile.h>
|
|
||||||
|
|
||||||
namespace HackStudio {
|
namespace HackStudio {
|
||||||
class ProjectBuilder {
|
class ProjectBuilder {
|
||||||
|
|
|
@ -30,7 +30,6 @@ set(SOURCES
|
||||||
System.cpp
|
System.cpp
|
||||||
SystemServerTakeover.cpp
|
SystemServerTakeover.cpp
|
||||||
TCPServer.cpp
|
TCPServer.cpp
|
||||||
TempFile.cpp
|
|
||||||
Timer.cpp
|
Timer.cpp
|
||||||
UDPServer.cpp
|
UDPServer.cpp
|
||||||
Version.cpp
|
Version.cpp
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
FileSystem.cpp
|
FileSystem.cpp
|
||||||
|
TempFile.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_lib(LibFileSystem filesystem)
|
serenity_lib(LibFileSystem filesystem)
|
||||||
|
|
|
@ -1,14 +1,27 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020-2023, the SerenityOS developers.
|
* Copyright (c) 2020-2023, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "TempFile.h"
|
|
||||||
#include <LibCore/DeprecatedFile.h>
|
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
|
#include <LibFileSystem/FileSystem.h>
|
||||||
|
#include <LibFileSystem/TempFile.h>
|
||||||
|
|
||||||
namespace Core {
|
namespace FileSystem {
|
||||||
|
|
||||||
|
TempFile::~TempFile()
|
||||||
|
{
|
||||||
|
// Temporary files aren't removed by anyone else, so we must do it ourselves.
|
||||||
|
auto recursion_mode = RecursionMode::Disallowed;
|
||||||
|
if (m_type == Type::Directory)
|
||||||
|
recursion_mode = RecursionMode::Allowed;
|
||||||
|
|
||||||
|
auto result = FileSystem::remove(m_path, recursion_mode);
|
||||||
|
if (result.is_error())
|
||||||
|
warnln("Removal of temporary file failed '{}': {}", m_path, result.error().string_literal());
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullOwnPtr<TempFile>> TempFile::create_temp_directory()
|
ErrorOr<NonnullOwnPtr<TempFile>> TempFile::create_temp_directory()
|
||||||
{
|
{
|
||||||
|
@ -27,17 +40,4 @@ ErrorOr<NonnullOwnPtr<TempFile>> TempFile::create_temp_file()
|
||||||
return adopt_nonnull_own_or_enomem(new (nothrow) TempFile(Type::File, string));
|
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,16 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020-2023, the SerenityOS developers.
|
* Copyright (c) 2020-2023, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/NonnullOwnPtr.h>
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
|
||||||
namespace Core {
|
namespace FileSystem {
|
||||||
|
|
||||||
class TempFile {
|
class TempFile {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue