Skip to content

Commit

Permalink
cmdline: add new -S criteria: hH: Sort by number of hardlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
sahib committed Nov 11, 2016
1 parent 7806cdc commit e4a99c0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
17 changes: 9 additions & 8 deletions docs/rmlint.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,15 @@ Original Detection Options

Sort the files in a group of duplicates by one or more criteria.

- **m**: keep lowest mtime (oldest) **M**: keep highest mtime (newest)
- **a**: keep first alphabetically **A**: keep last alphabetically
- **p**: keep first named path **P**: keep last named path
- **d**: keep path with lowest depth **D**: keep path with highest depth
- **l**: keep path with shortest basename **L**: keep path with longest basename
- **r**: keep paths matching regex **R**: keep path not matching regex
- **r**: keep paths matching regex **R**: keep path not matching regex
- **x**: keep basenames matching regex **X**: keep basenames not matching regex
- **m**: keep lowest mtime (oldest) **M**: keep highest mtime (newest)
- **a**: keep first alphabetically **A**: keep last alphabetically
- **p**: keep first named path **P**: keep last named path
- **d**: keep path with lowest depth **D**: keep path with highest depth
- **l**: keep path with shortest basename **L**: keep path with longest basename
- **r**: keep paths matching regex **R**: keep path not matching regex
- **r**: keep paths matching regex **R**: keep path not matching regex
- **x**: keep basenames matching regex **X**: keep basenames not matching regex
- **h**: keep file with lowest hardlink count **H**: keep file with highest hardlink count

Alphabetical sort will only use the basename of the file and ignore its case.
One can have multiple criteria, e.g.: ``-S am`` will choose first alphabetically; if tied then by mtime.
Expand Down
2 changes: 1 addition & 1 deletion lib/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ static gboolean rm_cmd_parse_rankby(_UNUSED const char *option_name, const gchar
return false;
}

if(!rm_cmd_check_lettervec(option_name, cfg->sort_criteria, "dlamprxDLAMPRX",
if(!rm_cmd_check_lettervec(option_name, cfg->sort_criteria, "dlamprxhDLAMPRXH",
error)) {
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ typedef struct RmFile {
*/
short depth;

/* Link count (number of hardlinks + 1) of the file as told by stat()
*/
short link_count;

/* Depth of the path of this file.
*/
guint8 path_depth;
Expand Down
3 changes: 3 additions & 0 deletions lib/preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ int rm_pp_cmp_orig_criteria(const RmFile *a, const RmFile *b, const RmSession *s
case 'd':
cmp = (short)a->depth - (short)b->depth;
break;
case 'h':
cmp = (long)a->link_count - (long)b->link_count;
break;
case 'p':
cmp = (long)a->path_index - (long)b->path_index;
break;
Expand Down
1 change: 1 addition & 0 deletions lib/traverse.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ static void rm_traverse_file(RmTravSession *trav_session, RmStat *statp,
file->is_symlink = is_symlink;
file->is_hidden = is_hidden;
file->is_on_subvol_fs = is_on_subvol_fs;
file->link_count = statp->st_nlink;

rm_file_list_insert_file(file, session);

Expand Down

2 comments on commit e4a99c0

@Awerick
Copy link

Choose a reason for hiding this comment

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

It seems you used tabs in three of the files – but the files use spaces ;-)
(When viewing the commit via github the lines are indented differently...)

@sahib
Copy link
Owner Author

@sahib sahib commented on e4a99c0 Nov 12, 2016

Choose a reason for hiding this comment

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

Indeed, a bit embarrassing. Shouldn't edit things in a hurry.

Please sign in to comment.