v31.1-roots.1 · Commit 6: [PATCH 06/17] feat(wallet): preserve Roots signing and spend controls on v31
src/util/fs_helpers.cpp
Before: src/util/fs_helpers.cpp · After: src/util/fs_helpers.cpp
File metadata
index e7780d743c191e9207263fe352ff2978ea0fdb01..a4d5e40d5f6660a656edc06148e80a154866664c 100644
Download original patch · Release notes
Diff rows 1–41 of 41. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/util/fs_helpers.cpp
CHANGED
|
@@ -7,7 +7,9 @@
|
|
| 7 |
|
| 8 |
#include <util/fs_helpers.h>
|
| 9 |
|
|
|
|
| 10 |
#include <sync.h>
|
|
|
|
| 11 |
#include <util/fs.h>
|
| 12 |
#include <util/log.h>
|
| 13 |
#include <util/syserror.h>
|
|
@@ -315,3 +317,32 @@ FSType GetFilesystemType(const fs::path& path)
|
|
| 315 |
return FSType::OTHER;
|
| 316 |
}
|
| 317 |
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
#include <util/fs_helpers.h>
|
| 9 |
|
| 10 |
+
#include <random.h>
|
| 11 |
#include <sync.h>
|
| 12 |
+
#include <tinyformat.h>
|
| 13 |
#include <util/fs.h>
|
| 14 |
#include <util/log.h>
|
| 15 |
#include <util/syserror.h>
|
|
|
|
| 317 |
return FSType::OTHER;
|
| 318 |
}
|
| 319 |
#endif
|
| 320 |
+
|
| 321 |
+
bool IsDirWritable(const fs::path& dir_path)
|
| 322 |
+
{
|
| 323 |
+
// Attempt to create a tmp file in the directory
|
| 324 |
+
if (!fs::is_directory(dir_path)) throw std::runtime_error(strprintf("Path %s is not a directory", fs::PathToString(dir_path)));
|
| 325 |
+
FastRandomContext rng;
|
| 326 |
+
const auto tmp = dir_path / fs::PathFromString(strprintf(".tmp_%d", rng.rand64()));
|
| 327 |
+
|
| 328 |
+
if (const auto created{fsbridge::fopen(tmp, "wbx")}) {
|
| 329 |
+
std::fclose(created);
|
| 330 |
+
std::error_code ec;
|
| 331 |
+
fs::remove(tmp, ec); // clean up, ignore errors
|
| 332 |
+
return true;
|
| 333 |
+
}
|
| 334 |
+
return false;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
bool IsSymlink(const fs::path& path)
|
| 338 |
+
{
|
| 339 |
+
#ifdef WIN32
|
| 340 |
+
DWORD file_attrs = GetFileAttributesW(path.wstring().c_str());
|
| 341 |
+
if (file_attrs == INVALID_FILE_ATTRIBUTES) {
|
| 342 |
+
throw fs::filesystem_error("Unable to get file attributes", fs::PathToString(path), std::make_error_code(std::errc::invalid_argument));
|
| 343 |
+
}
|
| 344 |
+
return (file_attrs & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
|
| 345 |
+
#else
|
| 346 |
+
return fs::is_symlink(path);
|
| 347 |
+
#endif
|
| 348 |
+
}
|