Move check_file_exists() to file_utils.{h,cc}
This commit is contained in:
parent
ea424c4134
commit
14122d6875
@ -18,16 +18,6 @@ using namespace std;
|
|||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void check_file_exists(string const &file) {
|
|
||||||
struct stat info;
|
|
||||||
int r = ::stat(file.c_str(), &info);
|
|
||||||
if (r)
|
|
||||||
throw runtime_error("Couldn't stat file");
|
|
||||||
|
|
||||||
if (!S_ISREG(info.st_mode))
|
|
||||||
throw runtime_error("Not a regular file");
|
|
||||||
}
|
|
||||||
|
|
||||||
int restore(string const &xml_file, string const &dev) {
|
int restore(string const &xml_file, string const &dev) {
|
||||||
try {
|
try {
|
||||||
block_manager<>::ptr bm = open_bm(dev, block_io<>::READ_ONLY);
|
block_manager<>::ptr bm = open_bm(dev, block_io<>::READ_ONLY);
|
||||||
|
@ -54,4 +54,15 @@ persistent_data::open_bm(std::string const &dev_path, block_io<>::mode m)
|
|||||||
return block_manager<>::ptr(new block_manager<>(dev_path, nr_blocks, 1, m));
|
return block_manager<>::ptr(new block_manager<>(dev_path, nr_blocks, 1, m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
persistent_data::check_file_exists(string const &file) {
|
||||||
|
struct stat info;
|
||||||
|
int r = ::stat(file.c_str(), &info);
|
||||||
|
if (r)
|
||||||
|
throw runtime_error("Couldn't stat file");
|
||||||
|
|
||||||
|
if (!S_ISREG(info.st_mode))
|
||||||
|
throw runtime_error("Not a regular file");
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
@ -3,11 +3,16 @@
|
|||||||
|
|
||||||
#include "persistent-data/block.h"
|
#include "persistent-data/block.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
|
// FIXME: move to a different unit
|
||||||
namespace persistent_data {
|
namespace persistent_data {
|
||||||
persistent_data::block_address get_nr_blocks(string const &path);
|
persistent_data::block_address get_nr_blocks(string const &path);
|
||||||
block_manager<>::ptr open_bm(std::string const &dev_path, block_io<>::mode m);
|
block_manager<>::ptr open_bm(std::string const &dev_path, block_io<>::mode m);
|
||||||
|
|
||||||
|
void check_file_exists(std::string const &file);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user