Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug with :P modifier when current directory is the root



On Mar 11,  8:47am, Daniel Shahaf wrote:
}
} zgetcwd() can return "." if the current working directory has been
} deleted by another process.

One of those cases it's annoying to have to waste time on, since it is
so rare and the result will be broken anyway, but I suppose I should
commit it like the below.

diff --git a/Src/subst.c b/Src/subst.c
index 2214b3d..e639c96 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -4336,7 +4336,11 @@ modify(char **str, char **ptr)
 			break;
 		    case 'P':
 			if (*copy != '/') {
-			    copy = zhtricat(metafy(zgetcwd(), -1, META_HEAPDUP), "/", copy);
+			    char *here = zgetcwd();
+			    if (here[strlen(here)-1] != '/')
+				copy = zhtricat(metafy(here, -1, META_HEAPDUP), "/", copy);
+			    else
+				copy = dyncat(here, copy);
 			}
 			copy = xsymlink(copy, 1);
 			break;
@@ -4418,7 +4422,11 @@ modify(char **str, char **ptr)
 		    break;
 		case 'P':
 		    if (**str != '/') {
-			*str = zhtricat(metafy(zgetcwd(), -1, META_HEAPDUP), "/", *str);
+			char *here = zgetcwd();
+			if (here[strlen(here)-1] != '/')
+			    *str = zhtricat(metafy(here, -1, META_HEAPDUP), "/", *str);
+			else
+			    *str = dyncat(here, *str);
 		    }
 		    *str = xsymlink(*str, 1);
 		    break;



Messages sorted by: Reverse Date, Date, Thread, Author