Date: Tue, 24 Mar 1998 21:05:57 GMT From: David Malone <dwmalone@hamilton.maths.tcd.ie> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/6124: Getting md5 to reset access times. Message-ID: <199803242105.VAA07810@hamilton.maths.tcd.ie>
next in thread | raw e-mail | index | archive | help
>Number: 6124 >Category: bin >Synopsis: No problem - addition to make md5 to reset access times. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Mar 24 13:10:01 PST 1998 >Last-Modified: >Originator: David Malone >Organization: School of Mathematics, Trinity College Dublin. >Release: FreeBSD 3.0-CURRENT i386 >Environment: 2.2-STABLE (as of 2.2.6-RELEASE) and 3.0-CURRENT (98.03.02). >Description: If you are using md5 to checksum a load of files you probably don't want all the access times changed. This is a small patch which adds a "-r" flag which resets the access times to what they were before the file was checksumed. It doesn't take into account the possibility that the file is accessed while being checksumed. The diff's included seem to work OK on both stable and current. >How-To-Repeat: >Fix: *** /usr/src/sbin/md5/md5.c Mon Dec 29 14:05:49 1997 --- md5.c Tue Mar 24 20:51:14 1998 *************** *** 22,27 **** --- 22,28 ---- */ #include <sys/types.h> + #include <sys/stat.h> #include <md5.h> #include <stdio.h> *************** *** 60,72 **** int ch; char *p; char buf[33]; if (argc > 1) { ! while ((ch = getopt(argc, argv, "ps:tx")) != -1) { switch (ch) { case 'p': MDFilter(1); break; case 's': MDString(optarg); break; --- 61,80 ---- int ch; char *p; char buf[33]; + int reset_times = 0; + int times_ok; + struct stat sb; + struct timeval tv[2]; if (argc > 1) { ! while ((ch = getopt(argc, argv, "prs:tx")) != -1) { switch (ch) { case 'p': MDFilter(1); break; + case 'r': + reset_times = 1; + break; case 's': MDString(optarg); break; *************** *** 81,91 **** --- 89,106 ---- } } while (optind < argc) { + times_ok = reset_times && stat(argv[optind],&sb) == 0; p = MD5File(argv[optind], buf); if (!p) perror(argv[optind]); else printf("MD5 (%s) = %s\n", argv[optind], p); + if( times_ok ) { + TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec); + TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec); + + utimes(argv[optind],tv); + } optind++; } } else *************** *** 194,199 **** usage() { ! fprintf(stderr, "usage: md5 [-ptx] [-s string] [files ...]\n"); exit(1); } --- 209,214 ---- usage() { ! fprintf(stderr, "usage: md5 [-rptx] [-s string] [files ...]\n"); exit(1); } *** /usr/src/sbin/md5/md5.1 Mon Dec 29 03:40:37 1997 --- md5.1 Tue Mar 24 20:50:58 1998 *************** *** 6,12 **** .Nd calculate a message-digest fingerprint (checksum) for a file .Sh SYNOPSIS .Nm ! .Op Fl ptx .Op Fl s Ar string .Op Ar file ... .Sh DESCRIPTION --- 6,12 ---- .Nd calculate a message-digest fingerprint (checksum) for a file .Sh SYNOPSIS .Nm ! .Op Fl prtx .Op Fl s Ar string .Op Ar file ... .Sh DESCRIPTION *************** *** 37,42 **** --- 37,44 ---- .Ar string . .It Fl p echos stdin to stdout and appends the MD5 sum to stdout. + .It Fl r + resets the access time on files after reading. .It Fl t runs a built-in time trial. .It Fl x >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803242105.VAA07810>