om

om - the most recently modified file in a directory
git clone git://git.larryhynes.net/om
Log | Files | Refs | README | LICENSE

commit 18e06b186d41bbcea72b8a065c413342f1f43f71
parent c102fbe4c9a52d6c4b572115ba7d2a6c4f1cf44a
Author: Larry Hynes <larry@larryhynes.com>
Date:   Wed,  5 Jul 2017 01:06:28 +0100

If mtimes are equal, compare by inode number

I'm not totally sure about this, and may revert it, but we'll see.
om is all about the most recently modified file, but sometimes,
files in a directory have the same mtime, in which case we probably
want the most recently created. So if two files are 'tied' by mtime,
the winner is the one with the highest inode number.

I will probably have to rip all this out at some stage and implement
a proper sort.

Diffstat:
om.c | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)

diff --git a/om.c b/om.c @@ -79,6 +79,15 @@ om() errx(1, "Filename too long"); mtime = sb.st_mtime; } + if (sb.st_mtime == mtime) { + if (sb.st_ino > ino) { + len = strlcpy(res, ent->d_name, + sizeof(res)); + if (len >= sizeof(res)) + errx(1, "Filename too long"); + ino = sb.st_ino; + } + } } }