markfasheh / duperemove

Tools for deduping file systems
GNU General Public License v2.0
794 stars 78 forks source link

Excluding using wildcard (*) does not work. #247

Closed halvors closed 3 years ago

halvors commented 3 years ago

Hi!

I'm trying to use the --exclude option to exclude my snapshots, my snapshots is in the format "@apt-snapshot-[DATE]-[TIME]" where date and time is when the snapshot was taken.

Problem is that with the --exclude option i am trying to exclude using "-exclude=@apt-snapshot-*" to exclude them all, this is simply ignored as if i never passed that option.

I tested with just "-exclude=*" doesn't seem to work either, am i doing something wrong here?

How is this supposed to work? I've also tested against the lastest commit on master, 047978e147483f8c03b2885459099e7132d724e3

lorddoskias commented 3 years ago

you need to pass the full path for the pattern. For example I'm running duperemove like so:

./duperemove --exclude @apt-snapshot-* mnt-test/ and the out I get ( I added some debug statements I get) :

Gathering file list...
file /home/nborisov/projects/kernel/duperemove/mnt-test didn't match pattern @apt-snapshot-*
file /home/nborisov/projects/kernel/duperemove/mnt-test/file1 didn't match pattern @apt-snapshot-*
file /home/nborisov/projects/kernel/duperemove/mnt-test/@apt-snapshot-1 didn't match pattern @apt-snapshot-*
file /home/nborisov/projects/kernel/duperemove/mnt-test/@apt-snapshot-2 didn't match pattern @apt-snapshot-*
file /home/nborisov/projects/kernel/duperemove/mnt-test/@apt-snapshot-3 didn't match pattern @apt-snapshot-*
file /home/nborisov/projects/kernel/duperemove/mnt-test/@apt-snapshot-4 didn't match pattern @apt-snapshot-*

So the reason is that by passing just the filename the pattern can never match because internally duperemove works with absolute paths. Additionally if you don't encase your pattern with quotes the shell will expand the * to the first filename. I.e:

./duperemove --exclude $(pwd)/mnt-test/@apt-snapshot-* mnt-test/
Adding pattern /home/nborisov/projects/kernel/duperemove/mnt-test/@apt-snapshot-1

So the actual fix is to run duperemove with the following command line option:

./duperemove --exclude "$(pwd)/mnt-test/@apt-snapshot-*" mnt-test/
Adding pattern /home/nborisov/projects/kernel/duperemove/mnt-test/@apt-snapshot-*
lorddoskias commented 3 years ago

I used the occasion to improve the man page, you can check the changes @ https://github.com/markfasheh/duperemove/pull/248/commits/01e0376776b4703f905dc98eaab2c2d0f5a6b100 , care to comment if it makes things clearer?

halvors commented 3 years ago

Thanks for quick reply, thanks for clarifying. Your changes to the manpage explains it crystal clear :+1: But i cannot see what branch that commit is committed on? At least it's not on master.

Should i close this issue as this resolves it for me?

lorddoskias commented 3 years ago

It's not committed I just created it today and made a pr just wanted to be sure that when someone else who is not me reads it it's understandable. Now that I have your confirmation I will merge it to master and close this issue as resolved.

halvors commented 3 years ago

+1