[cache_repair, thin_repair] fix bug introduced in recent patch

I hadn't realised that check_file_exists() also checked that it was
a regular file, which we don't want for the couple of uses I recently
added.

This patch adds an optional arg must_be_regular_file, and defaults
it to true, preserving the original behaviour.  The recent additions
have this set to false.
This commit is contained in:
Joe Thornber 2019-10-14 09:21:38 +01:00
parent 1dd7b454bb
commit 0fc7529c01
4 changed files with 5 additions and 5 deletions

View File

@ -66,13 +66,13 @@ file_utils::file_exists(string const &path) {
} }
void void
file_utils::check_file_exists(string const &file) { file_utils::check_file_exists(string const &file, bool must_be_regular_file) {
struct stat info; struct stat info;
int r = ::stat(file.c_str(), &info); int r = ::stat(file.c_str(), &info);
if (r) if (r)
throw runtime_error("Couldn't stat file"); throw runtime_error("Couldn't stat file");
if (!S_ISREG(info.st_mode)) if (must_be_regular_file && !S_ISREG(info.st_mode))
throw runtime_error("Not a regular file"); throw runtime_error("Not a regular file");
} }

View File

@ -10,7 +10,7 @@
namespace file_utils { namespace file_utils {
int open_file(std::string const &path, int flags); int open_file(std::string const &path, int flags);
bool file_exists(std::string const &path); bool file_exists(std::string const &path);
void check_file_exists(std::string const &file); void check_file_exists(std::string const &file, bool must_be_regular_file = true);
int create_block_file(std::string const &path, off_t file_size); int create_block_file(std::string const &path, off_t file_size);
int open_block_file(std::string const &path, off_t min_size, bool writeable, bool excl = true); int open_block_file(std::string const &path, off_t min_size, bool writeable, bool excl = true);
uint64_t get_file_length(std::string const &file); uint64_t get_file_length(std::string const &file);

View File

@ -32,7 +32,7 @@ namespace {
int repair(string const &old_path, string const &new_path) { int repair(string const &old_path, string const &new_path) {
bool metadata_touched = false; bool metadata_touched = false;
try { try {
file_utils::check_file_exists(new_path); file_utils::check_file_exists(new_path, false);
metadata_touched = true; metadata_touched = true;
metadata_dump(open_metadata_for_read(old_path), metadata_dump(open_metadata_for_read(old_path),
output_emitter(new_path), output_emitter(new_path),

View File

@ -22,7 +22,7 @@ namespace {
try { try {
// block size gets updated by the restorer // block size gets updated by the restorer
block_manager<>::ptr new_bm = open_bm(new_path, block_manager<>::READ_WRITE); block_manager<>::ptr new_bm = open_bm(new_path, block_manager<>::READ_WRITE);
file_utils::check_file_exists(old_path); file_utils::check_file_exists(old_path, false);
metadata_touched = true; metadata_touched = true;
metadata::ptr new_md(new metadata(new_bm, metadata::CREATE, 128, 0)); metadata::ptr new_md(new metadata(new_bm, metadata::CREATE, 128, 0));
emitter::ptr e = create_restore_emitter(new_md); emitter::ptr e = create_restore_emitter(new_md);