From 3d5dca6ae6c59eaf38bea5e2e6c3e2429553a8eb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 21 Mar 2020 18:01:36 +0000 Subject: [PATCH 2/8] chrealpath: Make symlink resolution optional. --- Src/hist.c | 21 ++++++++++++++++----- Src/subst.c | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Src/hist.c b/Src/hist.c index 5281e8718..db2cc4ad7 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -842,7 +842,7 @@ histsubchar(int c) break; case 'A': - if (!chrealpath(&sline)) { + if (!chrealpath(&sline, 'A')) { herrflush(); zerr("modifier failed: A"); return -1; @@ -1922,9 +1922,18 @@ chabspath(char **junkptr) return 1; } +/* + * Resolve symlinks in junkptr. + * + * If mode is 'A', resolve dot-dot before symlinks. Else, mode should be 'P'. + * Refer to the documentation of the :A and :P modifiers for details. + * + * Return 0 for error, non-zero for success. + */ + /**/ int -chrealpath(char **junkptr) +chrealpath(char **junkptr, char mode) { char *str; #ifdef HAVE_REALPATH @@ -1936,12 +1945,14 @@ chrealpath(char **junkptr) # endif #endif + DPUTS1(mode != 'A' && mode != 'P', "chrealpath: mode='%c' is invalid", mode); + if (!**junkptr) return 1; - /* Notice that this means ..'s are applied before symlinks are resolved! */ - if (!chabspath(junkptr)) - return 0; + if (mode == 'A') + if (!chabspath(junkptr)) + return 0; #ifndef HAVE_REALPATH return 1; diff --git a/Src/subst.c b/Src/subst.c index 79efc9ad2..7b3222d6e 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -4399,7 +4399,7 @@ modify(char **str, char **ptr, int inbrace) chabspath(©); break; case 'A': - chrealpath(©); + chrealpath(©, 'A'); break; case 'c': { @@ -4485,7 +4485,7 @@ modify(char **str, char **ptr, int inbrace) chabspath(str); break; case 'A': - chrealpath(str); + chrealpath(str, 'A'); break; case 'c': {