diff --git a/Makefile.am b/Makefile.am index 446eb39..2e16a76 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,8 @@ TESTS=testcases/largefilesupport.sh \ testcases/verify_deterministic_operation.sh \ testcases/checksum_options.sh \ testcases/md5collisions.sh \ - testcases/sha1collisions.sh + testcases/sha1collisions.sh \ + testcases/verify_outputdelimiter_option.sh AUXFILES=testcases/common_funcs.sh \ testcases/md5collisions/letter_of_rec.ps \ diff --git a/Rdutil.cc b/Rdutil.cc index f1f2ed7..ed00a5d 100644 --- a/Rdutil.cc +++ b/Rdutil.cc @@ -25,8 +25,15 @@ // class declaration #include "Rdutil.hh" + int Rdutil::printtofile(const std::string& filename) const +{ + return printtofile(filename, " "); +} + +int +Rdutil::printtofile(const std::string& filename, const std::string& delimiter) const { // open a file to print to std::ofstream f1; @@ -46,9 +53,9 @@ Rdutil::printtofile(const std::string& filename) const std::vector::iterator it; for (it = m_list.begin(); it != m_list.end(); ++it) { - output << Fileinfo::getduptypestring(*it) << " " << it->getidentity() << " " - << it->depth() << " " << it->size() << " " << it->device() << " " - << it->inode() << " " << it->get_cmdline_index() << " " << it->name() + output << Fileinfo::getduptypestring(*it) << delimiter << it->getidentity() << delimiter + << it->depth() << delimiter << it->size() << delimiter << it->device() << delimiter + << it->inode() << delimiter << it->get_cmdline_index() << delimiter << it->name() << '\n'; } output << "# end of file\n"; diff --git a/Rdutil.hh b/Rdutil.hh index e5693ab..8d46ea9 100644 --- a/Rdutil.hh +++ b/Rdutil.hh @@ -27,6 +27,14 @@ public: */ int printtofile(const std::string& filename) const; + /** + * print file names to a file, with extra information. + * @param filename + * @param delimiter + * @return zero on success + */ + int printtofile(const std::string& filename, const std::string& delimiter) const; + /// mark files with a unique number void markitems(); diff --git a/rdfind.cc b/rdfind.cc index fbd6cb8..afed07d 100644 --- a/rdfind.cc +++ b/rdfind.cc @@ -11,6 +11,7 @@ #include #include #include +#include // project #include "CmdlineParser.hh" @@ -108,6 +109,7 @@ struct Options bool deterministic = true; // be independent of filesystem order long nsecsleep = 0; // number of nanoseconds to sleep between each file read. std::string resultsfile = "results.txt"; // results file name. + std::string results_delimiter = " "; // fields delimiter in results file }; Options @@ -136,6 +138,8 @@ parseOptions(Parser& parser) o.makeresultsfile = parser.get_parsed_bool(); } else if (parser.try_parse_string("-outputname")) { o.resultsfile = parser.get_parsed_string(); + } else if (parser.try_parse_string("-outputdelimiter")){ + o.results_delimiter = parser.get_parsed_string(); } else if (parser.try_parse_bool("-ignoreempty")) { if (parser.get_parsed_bool()) { o.minimumfilesize = 1; @@ -397,7 +401,7 @@ main(int narg, const char* argv[]) if (o.makeresultsfile) { std::cout << dryruntext << "Now making results file " << o.resultsfile << std::endl; - gswd.printtofile(o.resultsfile); + gswd.printtofile(o.resultsfile, o.results_delimiter); } // traverse the list and replace with symlinks diff --git a/testcases/verify_outputdelimiter_option.sh b/testcases/verify_outputdelimiter_option.sh new file mode 100755 index 0000000..11466b3 --- /dev/null +++ b/testcases/verify_outputdelimiter_option.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# Ensures the exclusion of empty files work as intended. +# + + +set -e +. "$(dirname "$0")/common_funcs.sh" + + + +makefiles() { + #make pairs of files, with specific sizes + for i in $(seq 0 4) ; do + head -c$i /dev/zero >a$i + head -c$i /dev/zero >b$i + done +} + + +reset_teststate +makefiles +$rdfind -outputdelimiter "," a* b* + +fields=$(grep -m 1 DUPTYPE results.txt | awk -F "," '{print NF}') +verify [ ${fields} -eq 8 ] + + +reset_teststate +makefiles +$rdfind -outputdelimiter " " a* b* + +fields=$(grep -m 1 DUPTYPE results.txt | awk -F " " '{print NF}') +verify [ ${fields} -eq 8 ]