diff options
author | Timo Weingärtner <timo@tiwe.de> | 2021-01-14 00:10:41 +0100 |
---|---|---|
committer | Timo Weingärtner <timo@tiwe.de> | 2021-01-14 00:10:41 +0100 |
commit | c0d0f8c94a31fc7e9f71a1640eda9d8cb557f74a (patch) | |
tree | ad221e73bfd6cc4ebcd0a6d6e1919a4fd969e4b7 /hadori.C | |
parent | bfaa37ae068f8b8a877b4653df840648d86a5448 (diff) | |
parent | 3d3fe99d72668bc1d0a4e16d9bc3a5b1d86c4935 (diff) | |
download | hadori-c0d0f8c94a31fc7e9f71a1640eda9d8cb557f74a.tar.gz |
Merge tag '1.1' into debian
1.1
Diffstat (limited to 'hadori.C')
-rw-r--r-- | hadori.C | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -40,8 +40,8 @@ namespace po = boost::program_options; #include "version.h" -po::variables_map config; -std::ostream debug(std::clog.rdbuf()), verbose(std::clog.rdbuf()), error(std::clog.rdbuf()); +static po::variables_map config; +static std::ostream debug(std::clog.rdbuf()), verbose(std::clog.rdbuf()), error(std::clog.rdbuf()); struct inode { std::string const filename; @@ -59,7 +59,7 @@ inline bool compare (inode const & l, inode const & r) { rf.read(rbuffer, sizeof(rbuffer)); if (lf.gcount() != rf.gcount()) return false; - if (memcmp(lbuffer, rbuffer, lf.gcount())) + if (memcmp(lbuffer, rbuffer, static_cast<size_t>(lf.gcount()))) return false; } return true; @@ -70,7 +70,9 @@ inline std::ostream& operator<< (std::ostream& os, inode const & i) { return os; } -void do_link (inode const & i, std::string const & other) { +static void do_link (inode const & i, std::string const & other) { + if (config.count("dry-run")) + return; if (!link(i.filename.c_str(), other.c_str())) { error << "linking " << i << " to " << other << " succeeded before unlinking (race condition)" << std::endl; exit(EX_UNAVAILABLE); @@ -92,7 +94,7 @@ void do_link (inode const & i, std::string const & other) { } } -void handle_file(std::string const & path, struct stat const & s) { +static void handle_file (std::string const & path, struct stat const & s) { static std::unordered_map<ino_t, inode const> kept; static std::unordered_map<ino_t, ino_t const> to_link; static std::unordered_multimap<off_t, ino_t const> sizes; @@ -129,8 +131,7 @@ void handle_file(std::string const & path, struct stat const & s) { verbose << "linking " << candidate << " to " << path << std::endl; if (s.st_nlink > 1) to_link.insert({s.st_ino, it.second}); - if (not config.count("dry-run")) - do_link(candidate, path); + do_link(candidate, path); return; } debug << "we keep " << f << std::endl; @@ -138,7 +139,7 @@ void handle_file(std::string const & path, struct stat const & s) { sizes.insert({s.st_size, s.st_ino}); } -void recurse (std::string const & dir, dev_t const dev) { +static void recurse (std::string const & dir, dev_t const dev) { DIR* D; struct dirent *d; struct stat s; @@ -179,7 +180,7 @@ void recurse (std::string const & dir, dev_t const dev) { } } -void recurse_start (std::string const & dir) { +static void recurse_start (std::string const & dir) { struct stat s; if (lstat(dir.c_str(), &s)) { @@ -201,7 +202,7 @@ void recurse_start (std::string const & dir) { } int main (int const argc, char const * const * const argv) { - po::options_description opts("OPTIONS"); + po::options_description opts("Options"); opts.add_options() ("help,h", "print this help message") ("version,V", "print version information") @@ -223,13 +224,16 @@ int main (int const argc, char const * const * const argv) { po::notify(config); if (config.count("help")) { - std::cout << "Invocation: hadori [ OPTIONS ] [ ARGUMENTS ]" << std::endl; - std::cout << opts << std::endl; + std::cout << "Usage: hadori [ OPTIONS ] [ ARGUMENTS ]\n"; + std::cout << opts; return EX_OK; } if (config.count("version")) { - std::cout << HADORI_VERSION << std::endl; + std::cout << HADORI_VERSION "\n"; + std::cout << "Written by Timo Weingärtner.\n"; + std::cout << "Report bugs to the Debian BTS at https://bugs.debian.org/\n"; + std::cout << "or by mail to timo@tiwe.de.\n"; return EX_OK; } |