From e4a99c0afd14bb18aee445a1cb14102bf4767def Mon Sep 17 00:00:00 2001 From: Chris P Date: Fri, 11 Nov 2016 17:51:54 +0100 Subject: [PATCH] cmdline: add new -S criteria: hH: Sort by number of hardlinks --- docs/rmlint.1.rst | 17 +++++++++-------- lib/cmdline.c | 2 +- lib/file.h | 4 ++++ lib/preprocess.c | 3 +++ lib/traverse.c | 1 + 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/rmlint.1.rst b/docs/rmlint.1.rst index d98ceb9b..7fa8814c 100644 --- a/docs/rmlint.1.rst +++ b/docs/rmlint.1.rst @@ -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. diff --git a/lib/cmdline.c b/lib/cmdline.c index bbafe9a3..09676fb7 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -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; } diff --git a/lib/file.h b/lib/file.h index 0345b6e4..5c311328 100644 --- a/lib/file.h +++ b/lib/file.h @@ -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; diff --git a/lib/preprocess.c b/lib/preprocess.c index 78883167..8524fa08 100644 --- a/lib/preprocess.c +++ b/lib/preprocess.c @@ -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; diff --git a/lib/traverse.c b/lib/traverse.c index 88a88829..19070625 100644 --- a/lib/traverse.c +++ b/lib/traverse.c @@ -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);