From: Andre Noll Date: Mon, 29 May 2017 17:53:47 +0000 (+0200) Subject: server: Introduce hash sort for ls command. X-Git-Tag: v0.6.1~50^2 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=dbfda9d10638e1f64e7013f82a7ca1996981cccb;ds=sidebyside server: Introduce hash sort for ls command. This allows to specify -s=hash (or -s=h) as options to the ls server command to sort the list of audio files by the SHA1 hash of the file content. We already had the LS_SORT_BY_HASH enum constant but the feature was never implemented. It's easy to do though, so here it is. --- diff --git a/aft.c b/aft.c index 4a812448..a548afbc 100644 --- a/aft.c +++ b/aft.c @@ -1104,6 +1104,12 @@ out: return ret; } +static int ls_hash_compare(const void *a, const void *b) +{ + struct ls_data *d1 = *(struct ls_data **)a, *d2 = *(struct ls_data **)b; + return memcmp(d1->hash, d2->hash, HASH_SIZE); +} + static int ls_audio_format_compare(const void *a, const void *b) { struct ls_data *d1 = *(struct ls_data **)a, *d2 = *(struct ls_data **)b; @@ -1221,6 +1227,8 @@ static int sort_matching_paths(struct ls_options *options) compar = ls_duration_compare; break; case LS_SORT_BY_AUDIO_FORMAT: compar = ls_audio_format_compare; break; + case LS_SORT_BY_HASH: + compar = ls_hash_compare; break; default: return -E_BAD_SORT; } @@ -1369,7 +1377,6 @@ out: return ret; } -/* TODO: flags -h (sort by hash) */ static int com_ls(struct command_context *cc, struct lls_parse_result *lpr) { const struct lls_command *cmd = SERVER_CMD_CMD_PTR(LS); @@ -1435,6 +1442,8 @@ static int com_ls(struct command_context *cc, struct lls_parse_result *lpr) opts->sorting = LS_SORT_BY_DURATION; else if (!strcmp(val, "a") || !strcmp(val, "audio-format")) opts->sorting = LS_SORT_BY_AUDIO_FORMAT; + else if (!strcmp(val, "h") || !strcmp(val, "hash")) + opts->sorting = LS_SORT_BY_HASH; else { ret = -E_AFT_SYNTAX; goto out; diff --git a/m4/lls/server_cmd.suite.m4 b/m4/lls/server_cmd.suite.m4 index e2bd162d..5ac7f16a 100644 --- a/m4/lls/server_cmd.suite.m4 +++ b/m4/lls/server_cmd.suite.m4 @@ -284,6 +284,8 @@ aux_info_prefix = Permissions: audio-format (a) + hash (h) + If --sort is not given, path sort is implied. [/help]