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

Add 'match-dirname' option #623

Open
wants to merge 1 commit into
base: master
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 lib/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef struct RmCfg {
gboolean limits_specified;
gboolean filter_mtime;
gboolean match_basename;
gboolean match_dirname;
gboolean unmatched_basenames;
gboolean match_with_extension;
gboolean match_without_extension;
Expand Down
1 change: 1 addition & 0 deletions lib/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ bool rm_cmd_parse_args(int argc, char **argv, RmSession *session) {
{"must-match-tagged" , 'm' , 0 , G_OPTION_ARG_NONE , &cfg->must_match_tagged , _("Must have twin in tagged dir") , NULL} ,
{"must-match-untagged" , 'M' , 0 , G_OPTION_ARG_NONE , &cfg->must_match_untagged , _("Must have twin in untagged dir") , NULL} ,
{"match-basename" , 'b' , 0 , G_OPTION_ARG_NONE , &cfg->match_basename , _("Only find twins with same basename") , NULL} ,
{"match-dirname" , 'B' , 0 , G_OPTION_ARG_NONE , &cfg->match_dirname , _("Only find twins with same dirname") , NULL} ,
{"match-extension" , 'e' , 0 , G_OPTION_ARG_NONE , &cfg->match_with_extension , _("Only find twins with same extension") , NULL} ,
{"match-without-extension" , 'i' , 0 , G_OPTION_ARG_NONE , &cfg->match_without_extension , _("Only find twins with same basename minus extension") , NULL} ,
{"merge-directories" , 'D' , EMPTY , G_OPTION_ARG_CALLBACK , FUNC(merge_directories) , _("Find duplicate directories") , NULL} ,
Expand Down
7 changes: 7 additions & 0 deletions lib/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ gint rm_file_basenames_cmp(const RmFile *file_a, const RmFile *file_b) {
return g_ascii_strcasecmp(file_a->folder->basename, file_b->folder->basename);
}

gint rm_file_dirnames_cmp(const RmFile *file_a, const RmFile *file_b) {
if (!file_a->folder->parent || !file_b->folder->parent)
return 0;

return g_ascii_strcasecmp(file_a->folder->parent->basename, file_b->folder->parent->basename);
}

void rm_file_hardlink_add(RmFile *head, RmFile *link) {
if(!head->hardlinks) {
head->hardlinks = g_queue_new();
Expand Down
4 changes: 4 additions & 0 deletions lib/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,8 @@ RmFile *rm_file_copy(RmFile *file);
*/
gint rm_file_basenames_cmp(const RmFile *file_a, const RmFile *file_b);


gint rm_file_dirnames_cmp(const RmFile *file_a, const RmFile *file_b);


#endif /* end of include guard */
5 changes: 5 additions & 0 deletions lib/preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ gint rm_file_cmp(const RmFile *file_a, const RmFile *file_b) {

RmCfg *cfg = file_a->session->cfg;

if(cfg->match_dirname) {
result = rm_file_dirnames_cmp(file_a, file_b);
RETURN_IF_NONZERO(result);
}

if(cfg->match_basename) {
result = rm_file_basenames_cmp(file_a, file_b);
RETURN_IF_NONZERO(result);
Expand Down