Artifacts Associated With Ticket 218931ffffffffff
Ticket change [f383a54820] (rid 129732) by nobody on 2000-10-26 01:08:06:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
OriginalBugID: 2806 RFE Version: 8.2 SubmitDate: '1999-09-16' LastModified: '1999-11-17' Severity: LOW Status: Released Submitter: techsupp ChangedBy: hobbs OS: Linux OSVersion: 2.0.34 SuSe and DLD, Sinix, NCR Unix Machine: Other FixedDate: '1999-11-17' FixedInVersion: 8.3b1 ClosedDate: '2000-10-25' Name: Ulrich Schöbel Extensions: depends. PlusPatch, DashPatch, Img, BLT, oratcl Comments: Both patches add the same functionality, they may be applied seperate or both, they don't interfere. I prefer the amtime.patch. DesiredBehavior: These are the amtime and attribute patches for 8.2.0. I submitted these patches for 8.0.5 about a week ago. They add different approaches to *set* the access and modification times of files. Patch: # amtime82.patch by Ulrich Schöbel, 13. Sept. 1999 # # This patch enables the "file atime" and "file mtime" # commands to *set* the access and/or modification times # of a file. # # Copy this file into the top directory of # the tcl8.2.0 source tree and do a # patch -p0 < amtime.patch # # *** generic/tclCmdAH.c.orig Mon Sep 13 13:26:05 1999 --- generic/tclCmdAH.c Mon Sep 13 14:31:47 1999 *************** *** 17,22 **** --- 17,23 ---- #include "tclInt.h" #include "tclPort.h" #include <locale.h> + #include <utime.h> typedef int (StatProc)_ANSI_ARGS_((CONST char *path, struct stat *buf)); *************** *** 788,793 **** --- 789,796 ---- Tcl_Obj *resultPtr; int index; + struct utimbuf tval; + /* * This list of constants should match the fileOption string array below. */ *************** *** 825,837 **** switch ((enum options) index) { case FILE_ATIME: { struct stat buf; ! if (objc != 3) { ! goto only3Args; } if (GetStatBuf(interp, objv[2], TclStat, &buf) != TCL_OK) { return TCL_ERROR; } Tcl_SetLongObj(resultPtr, (long) buf.st_atime); return TCL_OK; } --- 828,858 ---- switch ((enum options) index) { case FILE_ATIME: { struct stat buf; + char *fileName; ! if ((objc < 3)||(objc > 4)) { ! Tcl_AppendStringsToObj(resultPtr, "wrong # args: should be \"file atime name ?time?\"", (char *) NULL); ! return TCL_ERROR; } if (GetStatBuf(interp, objv[2], TclStat, &buf) != TCL_OK) { return TCL_ERROR; } + if (objc == 4) { + if (Tcl_GetLongFromObj(interp, objv[3], (long*)(&buf.st_atime)) != TCL_OK) { + Tcl_AppendStringsToObj(resultPtr, ": conversion error: should be \"file atime name ?time?\"", (char *) NULL); + return TCL_ERROR; + } + tval.actime = buf.st_atime; + tval.modtime = buf.st_mtime; + fileName = Tcl_GetStringFromObj(objv[2], (int *)NULL); + if (utime(fileName, &tval) != 0) { + Tcl_AppendStringsToObj(resultPtr, + "could not set access time for file \"", + fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + } Tcl_SetLongObj(resultPtr, (long) buf.st_atime); return TCL_OK; } *************** *** 976,988 **** } case FILE_MTIME: { struct stat buf; ! if (objc != 3) { ! goto only3Args; } if (GetStatBuf(interp, objv[2], TclStat, &buf) != TCL_OK) { return TCL_ERROR; } Tcl_SetLongObj(resultPtr, (long) buf.st_mtime); return TCL_OK; } --- 997,1028 ---- } case FILE_MTIME: { struct stat buf; + char *fileName; ! if ((objc < 3)||(objc > 4)) { ! Tcl_AppendStringsToObj(resultPtr, "wrong # args: should be \"file mtime name ?time?\"", (char *) NULL); ! return TCL_ERROR; } + if (GetStatBuf(interp, objv[2], TclStat, &buf) != TCL_OK) { return TCL_ERROR; } + if (objc == 4) { + if (Tcl_GetLongFromObj(interp, objv[3], (long*)(&buf.st_mtime)) != TCL_OK) { + Tcl_AppendStringsToObj(resultPtr, ": conversion error: should be \"file mtime name ?time?\"", (char *) NULL); + return TCL_ERROR; + } + tval.actime = buf.st_atime; + tval.modtime = buf.st_mtime; + fileName = Tcl_GetStringFromObj(objv[2], (int *)NULL); + if (utime(fileName, &tval) != 0) { + Tcl_AppendStringsToObj(resultPtr, + "could not set modification time for file \"", + fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + } Tcl_SetLongObj(resultPtr, (long) buf.st_mtime); return TCL_OK; } # attributes.patch by Ulrich Schöbel, 14. Sep. 1999 # # This patch extends the "file attributes" command by # the "-atime" and "-mtime" options, which can be used # to get and *set* the access and/or modification times # of a file. # # Copy this file into the top directory of # the tcl8.2.0 source tree and do a # patch -p0 < attributes.patch # # *** unix/tclUnixFCmd.c.orig Mon Sep 13 14:45:22 1999 --- unix/tclUnixFCmd.c Tue Sep 14 14:18:20 1999 *************** *** 79,84 **** --- 79,90 ---- static int GetPermissionsAttribute _ANSI_ARGS_(( Tcl_Interp *interp, int objIndex, CONST char *fileName, Tcl_Obj **attributePtrPtr)); + static int GetAtimeAttribute _ANSI_ARGS_(( + Tcl_Interp *interp, int objIndex, + CONST char *fileName, Tcl_Obj **attributePtrPtr)); + static int GetMtimeAttribute _ANSI_ARGS_(( + Tcl_Interp *interp, int objIndex, + CONST char *fileName, Tcl_Obj **attributePtrPtr)); static int SetGroupAttribute _ANSI_ARGS_((Tcl_Interp *interp, int objIndex, CONST char *fileName, Tcl_Obj *attributePtr)); *************** *** 88,93 **** --- 94,105 ---- static int SetPermissionsAttribute _ANSI_ARGS_(( Tcl_Interp *interp, int objIndex, CONST char *fileName, Tcl_Obj *attributePtr)); + static int SetAtimeAttribute _ANSI_ARGS_(( + Tcl_Interp *interp, int objIndex, + CONST char *fileName, Tcl_Obj *attributePtr)); + static int SetMtimeAttribute _ANSI_ARGS_(( + Tcl_Interp *interp, int objIndex, + CONST char *fileName, Tcl_Obj *attributePtr)); /* * Prototype for the TraverseUnixTree callback function. *************** *** 104,123 **** enum { UNIX_GROUP_ATTRIBUTE, UNIX_OWNER_ATTRIBUTE, ! UNIX_PERMISSIONS_ATTRIBUTE }; char *tclpFileAttrStrings[] = { "-group", "-owner", "-permissions", (char *) NULL }; CONST TclFileAttrProcs tclpFileAttrProcs[] = { {GetGroupAttribute, SetGroupAttribute}, {GetOwnerAttribute, SetOwnerAttribute}, ! {GetPermissionsAttribute, SetPermissionsAttribute} }; /* --- 116,141 ---- enum { UNIX_GROUP_ATTRIBUTE, UNIX_OWNER_ATTRIBUTE, ! UNIX_PERMISSIONS_ATTRIBUTE, ! UNIX_ATIME_ATTRIBUTE, ! UNIX_MTIME_ATTRIBUTE }; char *tclpFileAttrStrings[] = { "-group", "-owner", "-permissions", + "-atime", + "-mtime", (char *) NULL }; CONST TclFileAttrProcs tclpFileAttrProcs[] = { {GetGroupAttribute, SetGroupAttribute}, {GetOwnerAttribute, SetOwnerAttribute}, ! {GetPermissionsAttribute, SetPermissionsAttribute}, ! {GetAtimeAttribute, SetAtimeAttribute}, ! {GetMtimeAttribute, SetMtimeAttribute} }; /* *************** *** 1195,1200 **** --- 1213,1300 ---- } ^L /* + *---------------------------------------------------------------------- + * + * GetAtimeAttribute + * + * Gets the atime attribute of a file. + * + * Results: + * Standard TCL result. Returns a new Tcl_Obj in attributePtrPtr + * if there is no error. The object will have ref count 0. + * + * Side effects: + * A new object is allocated. + * + *---------------------------------------------------------------------- + */ + + static int + GetAtimeAttribute(interp, objIndex, fileName, attributePtrPtr) + Tcl_Interp *interp; /* The interp we are using for errors. */ + int objIndex; /* The index of the attribute. */ + CONST char *fileName; /* The name of the file (UTF-8). */ + Tcl_Obj **attributePtrPtr; /* A pointer to return the object with. */ + { + struct stat statBuf; + char returnString[11]; + + if (TclStat(fileName, &statBuf) != 0) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "could not stat file \"", fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + + sprintf(returnString, "%ld", statBuf.st_atime); + + *attributePtrPtr = Tcl_NewStringObj(returnString, -1); + + return TCL_OK; + } + ^L + /* + *---------------------------------------------------------------------- + * + * GetMtimeAttribute + * + * Gets the mtime attribute of a file. + * + * Results: + * Standard TCL result. Returns a new Tcl_Obj in attributePtrPtr + * if there is no error. The object will have ref count 0. + * + * Side effects: + * A new object is allocated. + * + *---------------------------------------------------------------------- + */ + + static int + GetMtimeAttribute(interp, objIndex, fileName, attributePtrPtr) + Tcl_Interp *interp; /* The interp we are using for errors. */ + int objIndex; /* The index of the attribute. */ + CONST char *fileName; /* The name of the file (UTF-8). */ + Tcl_Obj **attributePtrPtr; /* A pointer to return the object with. */ + { + struct stat statBuf; + char returnString[11]; + + if (TclStat(fileName, &statBuf) != 0) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "could not stat file \"", fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + + sprintf(returnString, "%ld", statBuf.st_mtime); + + *attributePtrPtr = Tcl_NewStringObj(returnString, -1); + + return TCL_OK; + } + ^L + /* *--------------------------------------------------------------------------- * * SetGroupAttribute -- *************** *** 1357,1362 **** --- 1457,1574 ---- Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } + return TCL_OK; + } + ^L + /* + *--------------------------------------------------------------------------- + * + * SetAtimeAttribute + * + * Sets the file to the given access time. + * + * Results: + * Standard TCL result. + * + * Side effects: + * The access time of the file is changed. + * + *--------------------------------------------------------------------------- + */ + + static int + SetAtimeAttribute(interp, objIndex, fileName, attributePtr) + Tcl_Interp *interp; /* The interp we are using for errors. */ + int objIndex; /* The index of the attribute. */ + CONST char *fileName; /* The name of the file (UTF-8). */ + Tcl_Obj *attributePtr; /* The attribute to set. */ + { + struct stat statBuf; + struct utimbuf timeBuf; + long aTime; + + CONST char *native; + Tcl_DString ds; + + if (TclStat(fileName, &statBuf) != 0) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "could not stat file \"", fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + if (Tcl_GetLongFromObj(interp, attributePtr, &aTime) != TCL_OK) { + return TCL_ERROR; + } + + timeBuf.modtime = statBuf.st_mtime; + timeBuf.actime = (time_t) aTime; + + native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds); + + if (utime(native, &timeBuf) != 0) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "could not set access time for file \"", fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + + Tcl_DStringFree(&ds); + return TCL_OK; + } + ^L + /* + *--------------------------------------------------------------------------- + * + * SetMtimeAttribute + * + * Sets the file to the given modification time. + * + * Results: + * Standard TCL result. + * + * Side effects: + * The modification time of the file is changed. + * + *--------------------------------------------------------------------------- + */ + + static int + SetMtimeAttribute(interp, objIndex, fileName, attributePtr) + Tcl_Interp *interp; /* The interp we are using for errors. */ + int objIndex; /* The index of the attribute. */ + CONST char *fileName; /* The name of the file (UTF-8). */ + Tcl_Obj *attributePtr; /* The attribute to set. */ + { + struct stat statBuf; + struct utimbuf timeBuf; + long mTime; + + CONST char *native; + Tcl_DString ds; + + if (TclStat(fileName, &statBuf) != 0) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "could not stat file \"", fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + if (Tcl_GetLongFromObj(interp, attributePtr, &mTime) != TCL_OK) { + return TCL_ERROR; + } + + timeBuf.modtime = (time_t) mTime; + timeBuf.actime = statBuf.st_atime; + + native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds); + + if (utime(native, &timeBuf) != 0) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "could not set modification time for file \"", fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + + Tcl_DStringFree(&ds); return TCL_OK; } /* PatchFiles: amtime.patch: generic/tclCmdAH.c attributes.patch: unix/tclUnixFCmd.c Added in 8.3b1. -- 11/17/1999 hobbs - foundin initialized to: "obsolete: 8.2"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "37. File System"
- title initialized to: "touch functionality"
- type initialized to: "Bug"
Ticket change [ba3c02934f] (rid 129291) by welch on 2000-10-26 08:32:13:
- closedate changed to: "2000-10-26T01:32:13"
- closer changed to: "welch"
- priority changed to: "2"
- resolution changed to: "Fixed"
- status changed to: "Closed"