set(
source_files
Args.cpp
- AtomicFile.cpp
Config.cpp
Context.cpp
Depfile.cpp
#include "Config.hpp"
-#include "AtomicFile.hpp"
#include "MiniTrace.hpp"
#include "Util.hpp"
#include "assertions.hpp"
+#include <core/AtomicFile.hpp>
#include <core/common.hpp>
#include <core/exceptions.hpp>
#include <core/types.hpp>
FMT("failed to write to {}: ", resolved_path));
}
- AtomicFile output(resolved_path, AtomicFile::Mode::text);
+ core::AtomicFile output(resolved_path, core::AtomicFile::Mode::text);
bool found = false;
if (!parse_config_file(
#include "hashutil.hpp"
#include "language.hpp"
-#include <AtomicFile.hpp>
#include <core/CacheEntry.hpp>
#include <core/Manifest.hpp>
#include <core/MsvcShowIncludesOutput.hpp>
// this program; if not, write to the Free Software Foundation, Inc., 51
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#include "AtomicFile.hpp"
-
-#include "assertions.hpp"
-
+#include <assertions.hpp>
+#include <core/AtomicFile.hpp>
#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/TemporaryFile.hpp>
namespace fs = util::filesystem;
-AtomicFile::AtomicFile(const std::string& path, Mode mode) : m_path(path)
+namespace core {
+
+AtomicFile::AtomicFile(const fs::path& path, Mode mode) : m_path(path)
{
auto tmp_file =
util::value_or_throw<core::Fatal>(util::TemporaryFile::create(path));
result.error().message()));
}
}
+
+} // namespace core
#include <cstdint>
#include <cstdio>
#include <filesystem>
-#include <string>
+#include <string_view>
+
+namespace core {
// This class represents a file whose data will be atomically written to a path
-// by renaming a temporary file in place.
+// by renaming a temporary file in place. Throws core::Error on error.
class AtomicFile
{
public:
enum class Mode { binary, text };
- AtomicFile(const std::string& path, Mode mode);
+ AtomicFile(const std::filesystem::path& path, Mode mode);
~AtomicFile();
FILE* stream();
void commit();
private:
- const std::string m_path;
+ std::filesystem::path m_path;
std::filesystem::path m_tmp_path;
FILE* m_stream;
};
{
return m_stream;
}
+
+} // namespace core
set(
sources
+ AtomicFile.cpp
CacheEntry.cpp
FileRecompressor.cpp
Manifest.cpp
#include "FileRecompressor.hpp"
-#include <AtomicFile.hpp>
#include <Util.hpp>
+#include <core/AtomicFile.hpp>
#include <core/CacheEntry.hpp>
#include <core/exceptions.hpp>
#include <util/expected.hpp>
#include "LocalStorage.hpp"
-#include <AtomicFile.hpp>
#include <Config.hpp>
#include <Context.hpp>
#include <File.hpp>
#include <MiniTrace.hpp>
#include <Util.hpp>
#include <assertions.hpp>
+#include <core/AtomicFile.hpp>
#include <core/CacheEntry.hpp>
#include <core/FileRecompressor.hpp>
#include <core/Manifest.hpp>
namespace fs = util::filesystem;
+using core::AtomicFile;
using core::Statistic;
using core::StatisticsCounters;
using util::DirEntry;
-// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "StatsFile.hpp"
-#include <AtomicFile.hpp>
#include <Logging.hpp>
+#include <core/AtomicFile.hpp>
#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/LockFile.hpp>
auto counters = read();
function(counters);
- AtomicFile file(m_path, AtomicFile::Mode::text);
+ core::AtomicFile file(m_path, core::AtomicFile::Mode::text);
for (size_t i = 0; i < counters.size(); ++i) {
file.write(FMT("{}\n", counters.get_raw(i)));
}
#include "FileStorage.hpp"
-#include <AtomicFile.hpp>
#include <Logging.hpp>
#include <Util.hpp>
#include <assertions.hpp>
+#include <core/AtomicFile.hpp>
#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/Bytes.hpp>
LOG("Writing {}", path);
try {
- AtomicFile file(path, AtomicFile::Mode::binary);
+ core::AtomicFile file(path, core::AtomicFile::Mode::binary);
file.write(value);
file.commit();
return true;
TestUtil.cpp
main.cpp
test_Args.cpp
- test_AtomicFile.cpp
test_Config.cpp
test_Depfile.cpp
test_Hash.cpp
test_ccache.cpp
test_compopt.cpp
test_compression_types.cpp
+ test_core_AtomicFile.cpp
test_core_MsvcShowIncludesOutput.cpp
test_core_Statistics.cpp
test_core_StatisticsCounters.cpp
// this program; if not, write to the Free Software Foundation, Inc., 51
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#include "../src/AtomicFile.hpp"
#include "TestUtil.hpp"
+#include <core/AtomicFile.hpp>
#include <util/DirEntry.hpp>
#include <util/file.hpp>
#include <string>
#include <vector>
+using core::AtomicFile;
using TestUtil::TestContext;
-TEST_SUITE_BEGIN("AtomicFile");
+TEST_SUITE_BEGIN("core::AtomicFile");
TEST_CASE("Base case")
{