From 148ced9ceeadb0fede7d548f209c3ade2af8291b Mon Sep 17 00:00:00 2001 From: vincentdarley Date: Thu, 9 Jan 2003 10:38:28 +0000 Subject: non-ascii chars in file mtime fix --- ChangeLog | 11 +++++++++++ generic/tclIOUtil.c | 32 ++------------------------------ generic/tclInt.h | 4 +++- mac/tclMacFile.c | 31 ++++++++++++++++++++++++++++++- tests/cmdAH.test | 18 +++++++++++++++++- unix/tclUnixFile.c | 25 ++++++++++++++++++++++++- win/tclWin32Dll.c | 4 +++- win/tclWinFile.c | 36 +++++++++++++++++++++++++++++++++++- win/tclWinInt.h | 5 ++++- 9 files changed, 129 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7eb4132..632468b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,17 @@ * generic/tclFileName.c: remove unused variable 'macSpecialCase' [Bug 664749] + + * generic/tclIOUtil.c: + * generic/tclInt.h: + * unix/tclUnixFile.c: + * mac/tclMacFile.c: + * win/tclWinFile.c: + * win/tclWinInt.h: + * win/tclWin32Dll.c: + * tests/cmdAH.test: fix to non-ascii chars in paths when + setting mtime and atime through 'file (a|m)time $path $time' + [Bug 634151] 2003-01-08 Don Porter diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index 2145fa2..b1bca76 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -17,7 +17,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIOUtil.c,v 1.67 2002/12/06 23:22:08 hobbs Exp $ + * RCS: @(#) $Id: tclIOUtil.c,v 1.68 2003/01/09 10:38:29 vincentdarley Exp $ */ #include "tclInt.h" @@ -342,7 +342,6 @@ static Tcl_FSCreateInternalRepProc NativeCreateNativeRep; static Tcl_FSFileAttrStringsProc NativeFileAttrStrings; static Tcl_FSFileAttrsGetProc NativeFileAttrsGet; static Tcl_FSFileAttrsSetProc NativeFileAttrsSet; -static Tcl_FSUtimeProc NativeUtime; /* * The only reason these functions are not static is that they @@ -396,7 +395,7 @@ static Tcl_Filesystem tclNativeFilesystem = { &TclpObjAccess, &TclpOpenFileChannel, &TclpMatchInDirectory, - &NativeUtime, + &TclpUtime, #ifndef S_IFLNK NULL, #else @@ -4987,33 +4986,6 @@ Tcl_FSEqualPaths(firstPtr, secondPtr) } return 0; } - -/* - * utime wants a normalized, NOT native path. I assume a native - * version of 'utime' doesn't exist (at least under that name) on NT/2000. - * If a native function does exist somewhere, then we could use: - * - * return native_utime(Tcl_FSGetNativePath(pathPtr),tval); - * - * This seems rather strange when compared with stat, lstat, access, etc. - * all of which want a native path. - */ -static int -NativeUtime(pathPtr, tval) - Tcl_Obj *pathPtr; - struct utimbuf *tval; -{ -#ifdef MAC_TCL - long gmt_offset=TclpGetGMTOffset(); - struct utimbuf local_tval; - local_tval.actime=tval->actime+gmt_offset; - local_tval.modtime=tval->modtime+gmt_offset; - return utime(Tcl_GetString(Tcl_FSGetNormalizedPath(NULL,pathPtr)), - &local_tval); -#else - return utime(Tcl_GetString(Tcl_FSGetNormalizedPath(NULL,pathPtr)),tval); -#endif -} /* Everything from here on is contained in this obsolete ifdef */ #ifdef USE_OBSOLETE_FS_HOOKS diff --git a/generic/tclInt.h b/generic/tclInt.h index c7ffc1d..956ec4d 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.113 2002/11/12 02:25:05 hobbs Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.114 2003/01/09 10:38:29 vincentdarley Exp $ */ #ifndef _TCLINT @@ -1805,6 +1805,8 @@ EXTERN int TclpDlopen _ANSI_ARGS_((Tcl_Interp *interp, Tcl_Obj *pathPtr, Tcl_LoadHandle *loadHandle, Tcl_FSUnloadFileProc **unloadProcPtr)); +EXTERN int TclpUtime _ANSI_ARGS_((Tcl_Obj *pathPtr, + struct utimbuf *tval)); /* *---------------------------------------------------------------- diff --git a/mac/tclMacFile.c b/mac/tclMacFile.c index 5e4d363..c20d056 100644 --- a/mac/tclMacFile.c +++ b/mac/tclMacFile.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclMacFile.c,v 1.25 2002/10/09 11:54:24 das Exp $ + * RCS: @(#) $Id: tclMacFile.c,v 1.26 2003/01/09 10:38:29 vincentdarley Exp $ */ /* @@ -1240,3 +1240,32 @@ TclpFilesystemPathType(pathObjPtr) /* All native paths are of the same type */ return NULL; } + +/* + *--------------------------------------------------------------------------- + * + * TclpUtime -- + * + * Set the modification date for a file. + * + * Results: + * 0 on success, -1 on error. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ +int +TclpUtime(pathPtr, tval) + Tcl_Obj *pathPtr; /* File to modify */ + struct utimbuf *tval; /* New modification date structure */ +{ + long gmt_offset=TclpGetGMTOffset(); + struct utimbuf local_tval; + local_tval.actime=tval->actime+gmt_offset; + local_tval.modtime=tval->modtime+gmt_offset; + return utime(Tcl_GetString(Tcl_FSGetNormalizedPath(NULL,pathPtr)), + &local_tval); +} + diff --git a/tests/cmdAH.test b/tests/cmdAH.test index 51667fb..fe16def 100644 --- a/tests/cmdAH.test +++ b/tests/cmdAH.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: cmdAH.test,v 1.29 2002/07/11 08:25:24 dkf Exp $ +# RCS: @(#) $Id: cmdAH.test,v 1.30 2003/01/09 10:38:32 vincentdarley Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2.1 @@ -1369,6 +1369,22 @@ test cmdAH-24.8 {Tcl_FileObjCmd: mtime touch} { set modmtime [file mtime $file $newmtime] expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"} } 1 +test cmdAH-24.9 {Tcl_FileObjCmd: mtime touch with non-ascii chars} { + set oldfile $file + # introduce some non-ascii characters. + append file \u2022 + file delete -force $file + file rename $oldfile $file + set mtime [file mtime $file] + after 1100; # pause a sec to notice change in mtime + set newmtime [clock seconds] + set err [catch {file mtime $file $newmtime} modmtime] + file rename $file $oldfile + if {$err} { + error $modmtime + } + expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"} +} 1 removeFile touch.me # owned diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index 0fe97d6..2dacb64 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixFile.c,v 1.28 2002/09/03 02:01:42 hobbs Exp $ + * RCS: @(#) $Id: tclUnixFile.c,v 1.29 2003/01/09 10:38:34 vincentdarley Exp $ */ #include "tclInt.h" @@ -813,3 +813,26 @@ TclpFilesystemPathType(pathObjPtr) /* All native paths are of the same type */ return NULL; } + +/* + *--------------------------------------------------------------------------- + * + * TclpUtime -- + * + * Set the modification date for a file. + * + * Results: + * 0 on success, -1 on error. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ +int +TclpUtime(pathPtr, tval) + Tcl_Obj *pathPtr; /* File to modify */ + struct utimbuf *tval; /* New modification date structure */ +{ + return utime(Tcl_FSGetNativePath(pathPtr),tval); +} diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 506cf78..038cf83 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWin32Dll.c,v 1.18 2002/12/06 23:22:59 hobbs Exp $ + * RCS: @(#) $Id: tclWin32Dll.c,v 1.19 2003/01/09 10:38:34 vincentdarley Exp $ */ #include "tclWinInt.h" @@ -92,6 +92,7 @@ static TclWinProcs asciiProcs = { */ NULL, NULL, + (int (__cdecl*)(CONST TCHAR *, struct _utimbuf *)) _utime, }; static TclWinProcs unicodeProcs = { @@ -138,6 +139,7 @@ static TclWinProcs unicodeProcs = { */ NULL, NULL, + (int (__cdecl*)(CONST TCHAR *, struct _utimbuf *)) _wutime, }; TclWinProcs *tclWinProcs; diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 04c5fa8..0023433 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinFile.c,v 1.39 2002/07/20 01:01:41 vincentdarley Exp $ + * RCS: @(#) $Id: tclWinFile.c,v 1.40 2003/01/09 10:38:35 vincentdarley Exp $ */ //#define _WIN32_WINNT 0x0500 @@ -2222,3 +2222,37 @@ TclpObjNormalizePath(interp, pathPtr, nextCheckpoint) Tcl_DStringFree(&dsNorm); return nextCheckpoint; } + +/* + *--------------------------------------------------------------------------- + * + * TclpUtime -- + * + * Set the modification date for a file. + * + * Results: + * 0 on success, -1 on error. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ +int +TclpUtime(pathPtr, tval) + Tcl_Obj *pathPtr; /* File to modify */ + struct utimbuf *tval; /* New modification date structure */ +{ + int res; + /* + * Windows uses a slightly different structure name and, possibly, + * contents, so we have to copy the information over + */ + struct _utimbuf buf; + + buf.actime = tval->actime; + buf.modtime = tval->modtime; + + res = (*tclWinProcs->utimeProc)(Tcl_FSGetNativePath(pathPtr),&buf); + return res; +} diff --git a/win/tclWinInt.h b/win/tclWinInt.h index b6f144d..6a65f04 100644 --- a/win/tclWinInt.h +++ b/win/tclWinInt.h @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinInt.h,v 1.17 2002/10/29 14:17:58 vincentdarley Exp $ + * RCS: @(#) $Id: tclWinInt.h,v 1.18 2003/01/09 10:38:35 vincentdarley Exp $ */ #ifndef _TCLWININT @@ -100,6 +100,9 @@ typedef struct TclWinProcs { GET_FILEEX_INFO_LEVELS, LPVOID); BOOL (WINAPI *createHardLinkProc)(CONST TCHAR*, CONST TCHAR*, LPSECURITY_ATTRIBUTES); + + INT (__cdecl *utimeProc)(CONST TCHAR*, struct _utimbuf *); + } TclWinProcs; EXTERN TclWinProcs *tclWinProcs; -- cgit v0.12