Ticket #3575: 0002-Ticket-3575-generate-timestamps-with-nanosecond-prec.patch

File 0002-Ticket-3575-generate-timestamps-with-nanosecond-prec.patch, 4.2 KB (added by ag, 8 years ago)
  • src/vfs/fish/fish.c

    From 04d7a5fcb45950be3e0b86c91c7852bc92e11c49 Mon Sep 17 00:00:00 2001
    From: Andrey Gursky <andrey.gursky@e-mail.ua>
    Date: Sat, 29 Oct 2016 02:31:40 +0200
    Subject: [PATCH] Ticket #3575: generate timestamps with nanosecond precision
     for touch
    
    Sample fish/utime helper content:
    
    if TZ=UTC touch -m -d "$FISH_TOUCHMTIME_W_NSEC" "/${FISH_FILENAME}" 2>/dev/null &&
       TZ=UTC touch -a -d "$FISH_TOUCHATIME_W_NSEC" "/${FISH_FILENAME}" 2>/dev/null; then
      echo "### 000"
    else
      echo "### 500"
    fi
    ---
     src/vfs/fish/fish.c | 44 ++++++++++++++++++++++++++------------------
     1 file changed, 26 insertions(+), 18 deletions(-)
    
    diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c
    index e04c877..dab1d90 100644
    a b fish_chown (const vfs_path_t * vpath, uid_t owner, gid_t group) 
    13231323 
    13241324/* --------------------------------------------------------------------------------------------- */ 
    13251325 
    1326 static time_t 
    1327 fish_get_atime (mc_timesbuf_t * times) 
     1326static void 
     1327fish_get_atime (mc_timesbuf_t * times, time_t * sec, long * nsec) 
    13281328{ 
    1329     time_t ret; 
    1330  
    13311329#ifdef HAVE_UTIMENSAT 
    1332     ret = (*times)[0].tv_sec; 
     1330    *sec = (*times)[0].tv_sec; 
     1331    *nsec = (*times)[0].tv_nsec; 
    13331332#else 
    1334     ret = times->actime; 
     1333    *sec = times->actime; 
     1334    *nsec = 0; 
    13351335#endif 
    1336     return ret; 
    13371336} 
    13381337 
    13391338/* --------------------------------------------------------------------------------------------- */ 
    13401339 
    1341 static time_t 
    1342 fish_get_mtime (mc_timesbuf_t * times) 
     1340static void 
     1341fish_get_mtime (mc_timesbuf_t * times, time_t * sec, long * nsec) 
    13431342{ 
    1344     time_t ret; 
    1345  
    13461343#ifdef HAVE_UTIMENSAT 
    1347     ret = (*times)[1].tv_sec; 
     1344    *sec = (*times)[1].tv_sec; 
     1345    *nsec = (*times)[1].tv_nsec; 
    13481346#else 
    1349     ret = times->modtime; 
     1347    *sec = times->modtime; 
     1348    *nsec = 0; 
    13501349#endif 
    1351     return ret; 
    13521350} 
    13531351 
    13541352/* --------------------------------------------------------------------------------------------- */ 
    fish_utime (const vfs_path_t * vpath, mc_timesbuf_t * times) 
    13581356{ 
    13591357    gchar *shell_commands = NULL; 
    13601358    char utcatime[16], utcmtime[16]; 
     1359    char utcatime_w_nsec[30], utcmtime_w_nsec[30]; 
    13611360    time_t atime, mtime; 
     1361    long atime_nsec, mtime_nsec; 
    13621362    struct tm *gmt; 
    13631363    char buf[BUF_LARGE]; 
    13641364    const char *crpath; 
    fish_utime (const vfs_path_t * vpath, mc_timesbuf_t * times) 
    13731373        return -1; 
    13741374    rpath = strutils_shell_escape (crpath); 
    13751375 
    1376     atime = fish_get_atime (times); 
     1376    fish_get_atime (times, &atime, &atime_nsec); 
    13771377    gmt = gmtime (&atime); 
    13781378    g_snprintf (utcatime, sizeof (utcatime), "%04d%02d%02d%02d%02d.%02d", 
    13791379                gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday, 
    13801380                gmt->tm_hour, gmt->tm_min, gmt->tm_sec); 
     1381    g_snprintf (utcatime_w_nsec, sizeof (utcatime_w_nsec), "%04d-%02d-%02d %02d:%02d:%02d.%09ld", 
     1382                gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday, 
     1383                gmt->tm_hour, gmt->tm_min, gmt->tm_sec, atime_nsec); 
    13811384 
    1382     mtime = fish_get_mtime (times); 
     1385    fish_get_mtime (times, &mtime, &mtime_nsec); 
    13831386    gmt = gmtime (&mtime); 
    13841387    g_snprintf (utcmtime, sizeof (utcmtime), "%04d%02d%02d%02d%02d.%02d", 
    13851388                gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday, 
    13861389                gmt->tm_hour, gmt->tm_min, gmt->tm_sec); 
     1390    g_snprintf (utcmtime_w_nsec, sizeof (utcmtime_w_nsec), "%04d-%02d-%02d %02d:%02d:%02d.%09ld", 
     1391                gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday, 
     1392                gmt->tm_hour, gmt->tm_min, gmt->tm_sec, mtime_nsec); 
    13871393 
    13881394    shell_commands = 
    13891395        g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILEATIME=%ld FISH_FILEMTIME=%ld ", 
    1390                      "FISH_TOUCHATIME=%s FISH_TOUCHMTIME=%s;\n", SUP->scr_utime, (char *) NULL); 
     1396                     "FISH_TOUCHATIME=%s FISH_TOUCHMTIME=%s ", 
     1397                     "FISH_TOUCHATIME_W_NSEC=\"%s\" FISH_TOUCHMTIME_W_NSEC=\"%s\";\n", 
     1398                     SUP->scr_utime, (char *) NULL); 
    13911399    g_snprintf (buf, sizeof (buf), shell_commands, rpath, (long) atime, (long) mtime, 
    1392                 utcatime, utcmtime); 
     1400                utcatime, utcmtime, utcatime_w_nsec, utcmtime_w_nsec); 
    13931401    g_free (shell_commands); 
    13941402    g_free (rpath); 
    13951403    return fish_send_command (path_element->class, super, buf, OPT_FLUSH);