summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2024-09-17 15:35:29 (GMT)
committersebres <sebres@users.sourceforge.net>2024-09-17 15:35:29 (GMT)
commit5f45cd9b777956bc9e8c879676d3f728db948756 (patch)
tree3add7505c1de8a74e3f344aaafbe20ec1b7b5018 /unix
parent36f92e4f3a7b7c2145d7423d944b9a5d79c4d74a (diff)
parent617e81d982e512223c456a95df28eab0141a4f21 (diff)
downloadtcl-5f45cd9b777956bc9e8c879676d3f728db948756.zip
tcl-5f45cd9b777956bc9e8c879676d3f728db948756.tar.gz
tcl-5f45cd9b777956bc9e8c879676d3f728db948756.tar.bz2
merge 8.7: avoid unneeded (but expensive) path normalization for several file subsystem commands and operations;
closes [02d5d65d70adab97] and probably [411f52ed87e313dd49e2]
Diffstat (limited to 'unix')
-rw-r--r--unix/tclUnixChan.c21
-rw-r--r--unix/tclUnixFile.c4
2 files changed, 23 insertions, 2 deletions
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c
index 693720c..0500147 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
@@ -1771,6 +1772,26 @@ 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.
+ * Note: since paths starting with ~ are absolute, it also considers tilde expansion,
+ * (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",
(char *)NULL);
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c
index e91ed41..2b0b5b0 100644
--- a/unix/tclUnixFile.c
+++ b/unix/tclUnixFile.c
@@ -1119,9 +1119,9 @@ TclNativeCreateNativeRep(
Tcl_Obj *validPathPtr;
Tcl_Size len;
- if (TclFSCwdIsNative()) {
+ if (TclFSCwdIsNative() || Tcl_FSGetPathType(pathPtr) == TCL_PATH_ABSOLUTE) {
/*
- * The cwd is native, which means we can use the translated path
+ * The cwd is native (or path is absolute), use the translated path
* without worrying about normalization (this will also usually be
* shorter so the utf-to-external conversion will be somewhat faster).
*/