Skip to content

Commit

Permalink
Remove DirIsWritable, GetUniquePath
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Jul 14, 2023
1 parent fac932a commit fac69b3
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 88 deletions.
3 changes: 0 additions & 3 deletions src/Makefile.am
Expand Up @@ -297,7 +297,6 @@ BITCOIN_CORE_H = \
util/fees.h \
util/fs.h \
util/fs_helpers.h \
util/getuniquepath.h \
util/golombrice.h \
util/hash_type.h \
util/hasher.h \
Expand Down Expand Up @@ -728,7 +727,6 @@ libbitcoin_util_a_SOURCES = \
util/fees.cpp \
util/fs.cpp \
util/fs_helpers.cpp \
util/getuniquepath.cpp \
util/hasher.cpp \
util/sock.cpp \
util/syserror.cpp \
Expand Down Expand Up @@ -970,7 +968,6 @@ libbitcoinkernel_la_SOURCES = \
util/exception.cpp \
util/fs.cpp \
util/fs_helpers.cpp \
util/getuniquepath.cpp \
util/hasher.cpp \
util/moneystr.cpp \
util/rbf.cpp \
Expand Down
24 changes: 4 additions & 20 deletions src/test/fs_tests.cpp
Expand Up @@ -5,7 +5,6 @@
#include <test/util/setup_common.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/getuniquepath.h>

#include <boost/test/unit_test.hpp>

Expand Down Expand Up @@ -101,29 +100,14 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream)
BOOST_CHECK_EQUAL(tmpfile1, fsbridge::AbsPathJoin(tmpfile1, ""));
BOOST_CHECK_EQUAL(tmpfile1, fsbridge::AbsPathJoin(tmpfile1, {}));
}
{
fs::path p1 = GetUniquePath(tmpfolder);
fs::path p2 = GetUniquePath(tmpfolder);
fs::path p3 = GetUniquePath(tmpfolder);

// Ensure that the parent path is always the same.
BOOST_CHECK_EQUAL(tmpfolder, p1.parent_path());
BOOST_CHECK_EQUAL(tmpfolder, p2.parent_path());
BOOST_CHECK_EQUAL(tmpfolder, p3.parent_path());

// Ensure that generated paths are actually different.
BOOST_CHECK(p1 != p2);
BOOST_CHECK(p2 != p3);
BOOST_CHECK(p1 != p3);
}
}

BOOST_AUTO_TEST_CASE(rename)
{
const fs::path tmpfolder{m_args.GetDataDirBase()};

const fs::path path1{GetUniquePath(tmpfolder)};
const fs::path path2{GetUniquePath(tmpfolder)};
const fs::path path1{tmpfolder/"a"};
const fs::path path2{tmpfolder/"b"};

const std::string path1_contents{"1111"};
const std::string path2_contents{"2222"};
Expand Down Expand Up @@ -158,13 +142,13 @@ BOOST_AUTO_TEST_CASE(create_directories)
// Test fs::create_directories workaround.
const fs::path tmpfolder{m_args.GetDataDirBase()};

const fs::path dir{GetUniquePath(tmpfolder)};
const fs::path dir{tmpfolder/"a"};
fs::create_directory(dir);
BOOST_CHECK(fs::exists(dir));
BOOST_CHECK(fs::is_directory(dir));
BOOST_CHECK(!fs::create_directories(dir));

const fs::path symlink{GetUniquePath(tmpfolder)};
const fs::path symlink{tmpfolder/"b"};
fs::create_directory_symlink(dir, symlink);
BOOST_CHECK(fs::exists(symlink));
BOOST_CHECK(fs::is_symlink(symlink));
Expand Down
17 changes: 0 additions & 17 deletions src/test/util_tests.cpp
Expand Up @@ -12,7 +12,6 @@
#include <util/bitdeque.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/getuniquepath.h>
#include <util/message.h> // For MessageSign(), MessageVerify(), MESSAGE_MAGIC
#include <util/moneystr.h>
#include <util/overflow.h>
Expand Down Expand Up @@ -1233,22 +1232,6 @@ BOOST_AUTO_TEST_CASE(test_LockDirectory)
fs::remove_all(dirname);
}

BOOST_AUTO_TEST_CASE(test_DirIsWritable)
{
// Should be able to write to the data dir.
fs::path tmpdirname = m_args.GetDataDirBase();
BOOST_CHECK_EQUAL(DirIsWritable(tmpdirname), true);

// Should not be able to write to a non-existent dir.
tmpdirname = GetUniquePath(tmpdirname);
BOOST_CHECK_EQUAL(DirIsWritable(tmpdirname), false);

fs::create_directory(tmpdirname);
// Should be able to write to it now.
BOOST_CHECK_EQUAL(DirIsWritable(tmpdirname), true);
fs::remove(tmpdirname);
}

BOOST_AUTO_TEST_CASE(test_ToLower)
{
BOOST_CHECK_EQUAL(ToLower('@'), '@');
Expand Down
14 changes: 0 additions & 14 deletions src/util/fs_helpers.cpp
Expand Up @@ -12,7 +12,6 @@
#include <logging.h>
#include <sync.h>
#include <util/fs.h>
#include <util/getuniquepath.h>

#include <cerrno>
#include <fstream>
Expand Down Expand Up @@ -91,19 +90,6 @@ void ReleaseDirectoryLocks()
dir_locks.clear();
}

bool DirIsWritable(const fs::path& directory)
{
fs::path tmpFile = GetUniquePath(directory);

FILE* file = fsbridge::fopen(tmpFile, "a");
if (!file) return false;

fclose(file);
remove(tmpFile);

return true;
}

bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes)
{
constexpr uint64_t min_disk_space = 52428800; // 50 MiB
Expand Down
1 change: 0 additions & 1 deletion src/util/fs_helpers.h
Expand Up @@ -44,7 +44,6 @@ enum class LockResult {
[[nodiscard]] LockResult LockDirectory(const fs::path& directory, const fs::path& lockfile_name, bool probe_only = false);
} // namespace util
void UnlockDirectory(const fs::path& directory, const fs::path& lockfile_name);
bool DirIsWritable(const fs::path& directory);
bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);

/** Get the size of a file by scanning it.
Expand Down
14 changes: 0 additions & 14 deletions src/util/getuniquepath.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions src/util/getuniquepath.h

This file was deleted.

0 comments on commit fac69b3

Please sign in to comment.