Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding ability to configure field delimiter in results file #94

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
13 changes: 10 additions & 3 deletions Rdutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,9 +53,9 @@ Rdutil::printtofile(const std::string& filename) const

std::vector<Fileinfo>::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";
Expand Down
8 changes: 8 additions & 0 deletions Rdutil.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 5 additions & 1 deletion rdfind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <iostream>
#include <string>
#include <vector>
#include <limits>

// project
#include "CmdlineParser.hh"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions testcases/verify_outputdelimiter_option.sh
Original file line number Diff line number Diff line change
@@ -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 ]