Skip to content

Commit

Permalink
mtime-window: bugfix: work correctly when having sub-second diffs bet…
Browse files Browse the repository at this point in the history
…ween mtimes
  • Loading branch information
sahib committed Nov 21, 2016
1 parent aa1cc5f commit 3221b9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ static gint rm_file_cmp_full(const RmFile *file_a, const RmFile *file_b,
return 0;
}

/* Save to cast to an gint */
return diff;
return (diff < 0) ? -1 : +1;
}

return rm_pp_cmp_orig_criteria(file_a, file_b, session);
Expand All @@ -122,11 +121,12 @@ static gint rm_file_cmp_split(const RmFile *file_a, const RmFile *file_b,
*/
if(session->cfg->mtime_window >= 0) {
gdouble diff = file_a->mtime - file_b->mtime;
if(fabs(diff) <= session->cfg->mtime_window) {
if(FLOAT_IS_ZERO(diff - session->cfg->mtime_window) || fabs(diff) < session->cfg->mtime_window) {
return 0;
}

return diff;
/* Split the group. */
return (diff < 0) ? -1 : +1;
}

return 0;
Expand Down
6 changes: 6 additions & 0 deletions tests/test_options/test_mtime_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ def test_consider_mtime_subsecond():

head, *data, footer = run_rmlint('--mtime-window=2.0')
assert len(data) == 2

set_mtime('a', '2004-02-29 16:21:42.00')
set_mtime('b', '2004-02-29 16:21:42.99')

head, *data, footer = run_rmlint('--mtime-window=0')
assert len(data) == 0

0 comments on commit 3221b9b

Please sign in to comment.