diff options
author | sebres <sebres@users.sourceforge.net> | 2024-09-13 14:26:26 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2024-09-13 14:26:26 (GMT) |
commit | f2b14cb7f00034cf7c9ee3e5681e4c912ca7ff9c (patch) | |
tree | 4b4c9c10fce59f32c11fad58a6bcc896c9f810dd | |
parent | bddda240611ea5ba0974d4e6d424c29f29f7057c (diff) | |
download | tcl-f2b14cb7f00034cf7c9ee3e5681e4c912ca7ff9c.zip tcl-f2b14cb7f00034cf7c9ee3e5681e4c912ca7ff9c.tar.gz tcl-f2b14cb7f00034cf7c9ee3e5681e4c912ca7ff9c.tar.bz2 |
small amend: move the normalization to the block where the error message really neededcore-bug-02d5d65d70adab97
-rw-r--r-- | generic/tclIOUtil.c | 21 | ||||
-rw-r--r-- | unix/tclUnixChan.c | 19 | ||||
-rw-r--r-- | win/tclWinChan.c | 21 |
3 files changed, 40 insertions, 21 deletions
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index c553ef3..847d191 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -2235,27 +2235,6 @@ Tcl_FSOpenFileChannel( const Tcl_Filesystem *fsPtr; Tcl_Channel retVal = NULL; - /* - * We need this just to ensure we return the correct error messages under - * some circumstances (relative paths only), so because the normalization - * is very expensive, don't invoke it for native or absolute paths. - * Note: TODO - check one needs consider tilde expansion after TIP#602, - * (proper error message of tests *io-40.17 "tilde substitution in open") - */ - - if ( - ( - ( - !TclFSCwdIsNative() && - (Tcl_FSGetPathType(pathPtr) != TCL_PATH_ABSOLUTE) - ) || - (*TclGetString(pathPtr) == '~') /* possible tilde expansion */ - ) && - Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL - ) { - return NULL; - } - fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); if (fsPtr != NULL && fsPtr->openFileChannelProc != NULL) { int mode, seekFlag, binary; diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 1844a23..e072cd7 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -12,6 +12,7 @@ */ #include "tclInt.h" /* Internal definitions for Tcl. */ +#include "tclFileSystem.h" #include "tclIO.h" /* To get Channel type declaration. */ #undef SUPPORTS_TTY @@ -1418,6 +1419,24 @@ TclpOpenFileChannel( native = (const char *)Tcl_FSGetNativePath(pathPtr); if (native == NULL) { if (interp != (Tcl_Interp *) NULL) { + /* + * We need this just to ensure we return the correct error messages under + * some circumstances (relative paths only), so because the normalization + * is very expensive, don't invoke it for native or absolute paths. + */ + if ( + ( + ( + !TclFSCwdIsNative() && + (Tcl_FSGetPathType(pathPtr) != TCL_PATH_ABSOLUTE) + ) || + (*TclGetString(pathPtr) == '~') /* possible tilde expansion */ + ) && + Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL + ) { + return NULL; + } + Tcl_AppendResult(interp, "couldn't open \"", TclGetString(pathPtr), "\": filename is invalid on this platform", (char *)NULL); diff --git a/win/tclWinChan.c b/win/tclWinChan.c index 666a0b1..0199a37 100644 --- a/win/tclWinChan.c +++ b/win/tclWinChan.c @@ -11,6 +11,7 @@ */ #include "tclWinInt.h" +#include "tclFileSystem.h" #include "tclIO.h" /* @@ -866,6 +867,26 @@ TclpOpenFileChannel( nativeName = (const WCHAR *)Tcl_FSGetNativePath(pathPtr); if (nativeName == NULL) { if (interp != (Tcl_Interp *) NULL) { + /* + * We need this just to ensure we return the correct error messages under + * some circumstances (relative paths only), so because the normalization + * is very expensive, don't invoke it for native or absolute paths. + * Note: TODO - check one needs consider tilde expansion after TIP#602, + * (proper error message of tests *io-40.17 "tilde substitution in open") + */ + if ( + ( + ( + !TclFSCwdIsNative() && + (Tcl_FSGetPathType(pathPtr) != TCL_PATH_ABSOLUTE) + ) || + (*TclGetString(pathPtr) == '~') /* possible tilde expansion */ + ) && + Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL + ) { + return NULL; + } + Tcl_AppendResult(interp, "couldn't open \"", TclGetString(pathPtr), "\": filename is invalid on this platform", NULL); |