From patchwork Wed Mar 7 15:46:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martijn Dekker X-Patchwork-Id: 10264293 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9C462602BD for ; Wed, 7 Mar 2018 15:46:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8740D2875A for ; Wed, 7 Mar 2018 15:46:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B47D28868; Wed, 7 Mar 2018 15:46:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A122C2875A for ; Wed, 7 Mar 2018 15:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933756AbeCGPq2 (ORCPT ); Wed, 7 Mar 2018 10:46:28 -0500 Received: from kahlil.inlv.org ([37.59.109.123]:38600 "EHLO kahlil.inlv.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933723AbeCGPq1 (ORCPT ); Wed, 7 Mar 2018 10:46:27 -0500 Received: from [192.168.1.81] (host86-129-6-191.range86-129.btcentralplus.com [86.129.6.191]) (authenticated bits=0) by kahlil.inlv.org (8.14.9/8.14.4) with ESMTP id w27FkHnh028278 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 7 Mar 2018 16:46:17 +0100 Subject: Re: Greater resolution in test -nt / test -ot To: Herbert Xu , =?UTF-8?B?UGV0ciBTa2/EjcOtaw==?= Cc: dash@vger.kernel.org References: <9903b02c-041f-38b6-e510-06b9f8744fbb@gmail.com> <20180306091901.GA30659@gondor.apana.org.au> From: Martijn Dekker Message-ID: Date: Wed, 7 Mar 2018 15:46:15 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180306091901.GA30659@gondor.apana.org.au> Content-Language: en-GB Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Op 06-03-18 om 09:19 schreef Herbert Xu: > On Thu, Jun 22, 2017 at 10:30:02AM +0200, Petr Skočík wrote: >> would you be willing to pull something like this? [...] >> I could use greater resolution in `test -nt` / `test -ot`, and st_mtim >> field is standardized under POSIX.1-2008 (or so stat(2) says). > > Sure. But your patch is corrupted. Fixed patch attached. But I wouldn't apply it as is. My system does not have st_mtim. So I think it needs a configure test and a fallback to the old method. - M. diff --git a/src/bltin/test.c b/src/bltin/test.c index 58c05fe..7ea02f2 100644 --- a/src/bltin/test.c +++ b/src/bltin/test.c @@ -478,7 +478,9 @@ newerf (const char *f1, const char *f2) return (stat (f1, &b1) == 0 && stat (f2, &b2) == 0 && - b1.st_mtime > b2.st_mtime); + ( b1.st_mtim.tv_sec > b2.st_mtim.tv_sec || + (b1.st_mtim.tv_sec == b2.st_mtim.tv_sec && (b1.st_mtim.tv_nsec > b2.st_mtim.tv_nsec ))) + ); } static int @@ -488,7 +490,9 @@ olderf (const char *f1, const char *f2) return (stat (f1, &b1) == 0 && stat (f2, &b2) == 0 && - b1.st_mtime < b2.st_mtime); + (b1.st_mtim.tv_sec < b2.st_mtim.tv_sec || + (b1.st_mtim.tv_sec == b2.st_mtim.tv_sec && (b1.st_mtim.tv_nsec < b2.st_mtim.tv_nsec ))) + ); } static int