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

Skip firstbytes / lastbytes #89

Open
wants to merge 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ test-driver
nettle32bit/
*.log
rdfind-*.tar.gz
.vs/slnx.sqlite
3 changes: 3 additions & 0 deletions rdfind.1
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ is true.
What type of checksum to be used: md5, sha1 or sha256. The default is
sha1 since version 1.4.0.
.TP
.BR \-skip " " \fIfirstbytes\fR|\fIlastbytes\fR
Skip some steps during the candidates pruning. This argument can be repeated.
.TP
.BR \-deterministic " " \fItrue\fR|\fIfalse\fR
If set (the default), sort files of equal rank in an unspecified but
deterministic order. This makes the behaviour independent of in which
Expand Down
24 changes: 22 additions & 2 deletions rdfind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ usage()
"device and inode\n"
<< " -checksum md5 |(sha1)| sha256\n"
<< " checksum type\n"
<< " -skip firstbytes | lastbytes\n"
<< " skip some check\n"
<< " -deterministic (true)| false makes results independent of order\n"
<< " from listing the filesystem\n"
<< " -makesymlinks true |(false) replace duplicate files with "
Expand Down Expand Up @@ -102,6 +104,8 @@ struct Options
bool followsymlinks = false; // follow symlinks
bool dryrun = false; // only dryrun, don't destroy anything
bool remove_identical_inode = true; // remove files with identical inodes
bool usefirstbytes = true; // use first bytes to check for differences
bool uselastbytes = true; // use last bytes to check for differences
bool usemd5 = false; // use md5 checksum to check for similarity
bool usesha1 = false; // use sha1 checksum to check for similarity
bool usesha256 = false; // use sha256 checksum to check for similarity
Expand Down Expand Up @@ -178,6 +182,16 @@ parseOptions(Parser& parser)
<< parser.get_parsed_string() << "\"\n";
std::exit(EXIT_FAILURE);
}
} else if (parser.try_parse_string("-skip")) {
if (parser.parsed_string_is("firstbytes")) {
o.usefirstbytes = false;
} else if (parser.parsed_string_is("lastbytes")) {
o.uselastbytes = false;
} else {
std::cerr << "expected firstbytes/lastbytes, not \""
<< parser.get_parsed_string() << "\"\n";
std::exit(EXIT_FAILURE);
}
} else if (parser.try_parse_string("-sleep")) {
const auto nextarg = std::string(parser.get_parsed_string());
if (nextarg == "1ms") {
Expand Down Expand Up @@ -352,9 +366,15 @@ main(int narg, const char* argv[])
// candidates. start looking at the contents.
std::vector<std::pair<Fileinfo::readtobuffermode, const char*>> modes{
{ Fileinfo::readtobuffermode::NOT_DEFINED, "" },
{ Fileinfo::readtobuffermode::READ_FIRST_BYTES, "first bytes" },
{ Fileinfo::readtobuffermode::READ_LAST_BYTES, "last bytes" },
};
if (o.usefirstbytes) {
modes.emplace_back(Fileinfo::readtobuffermode::READ_FIRST_BYTES,
"first bytes");
}
if (o.uselastbytes) {
modes.emplace_back(Fileinfo::readtobuffermode::READ_LAST_BYTES,
"last bytes");
}
if (o.usemd5) {
modes.emplace_back(Fileinfo::readtobuffermode::CREATE_MD5_CHECKSUM,
"md5 checksum");
Expand Down
22 changes: 22 additions & 0 deletions testcases/skip_options.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Test that selection of skip works as expected.


set -e
. "$(dirname "$0")/common_funcs.sh"





for skiptype in firstbytes lastbytes; do
reset_teststate
dbgecho "trying skip $skiptype"
echo skiptype >a
echo skiptype >b
$rdfind -skip $skiptype -deleteduplicates true a b
[ -e a ]
[ ! -e b ]
Comment on lines +17 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing that the new options are accepted. Which is good. But would be possible to even check the output and see if the option really took effects? Or that another invalid option lead to error?

Just a new user of this program, please ignore if the suggestion does not make sense.

done

dbgecho "all is good in this test!"