Hi Rob, I saw this email and thought this patch might help make `relative_path()` better.
Commit Message: While trying to add features to `readlink` and `realpath` I saw that adding a "/" to the end of the `from` variable, made it possible for me to get `realpath --relative-to=DIR` to work. The change seems like a hack, but I saw Rob's email https://www.mail-archive.com/toybox@lists.landley.net/msg06136.html and though this might be able to help. This works for `realpath` because `--relative-to` is only supposed to take a directory. ~Andrew PS: I hope this email looks correct. I made it by hand because of Gmail deciding not to give me the original message. https://www.mail-archive.com/toybox@lists.landley.net/msg06136.html On 08 Nov 2019 18:27:44 -0800, Rob via Toybox wrote: > In theory if you're using toybox cp you can use a relative path, which was > part > of why I did relative_path but darn it it's STILL broken:
From e8296ba33bf950894f7f289ec4106f842c222baf Mon Sep 17 00:00:00 2001 From: Andrew Ilijic <ilijic.and...@gmail.com> Date: Wed, 13 Nov 2019 09:48:18 -0500 Subject: [PATCH] Change `relative_path()` so `from` ends with "/" While trying to add features to `readlink` and `realpath` I saw that adding a "/" to the end of the `from` variable, made it possible for me to get `realpath --relative-to=DIR` to work. The change seems like a hack but I saw Rob's email https://www.mail-archive.com/toybox@lists.landley.net/msg06136.html and though this might be able to help. This works for `realpath` because `--relative-to` is only supposed to take a directory. --- lib/lib.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/lib.c b/lib/lib.c index 3bfee2ef..8460db35 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1038,6 +1038,10 @@ char *relative_path(char *from, char *to) if (!(from = xabspath(from, -1))) return 0; if (!(to = xabspath(to, -1))) goto error; + size_t len = strlen(from); + from = xrealloc(from, len + 2); + from[len]='/'; from[len + 1]='\0'; + // skip common directories from root for (i = j = 0; from[i] && from[i] == to[i]; i++) if (to[i] == '/') j = i+1; -- 2.11.0
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net