aurora / rmate

Remote TextMate 2 implemented as shell script
GNU General Public License v3.0
887 stars 123 forks source link

unable to open symlinks with relative paths #68

Closed elgarfo closed 5 years ago

elgarfo commented 6 years ago

cmdline: rmate -P 30698 /etc/apache2/sites-enabled/my.awesome.site-ssl.conf

actual result:

unable to cd to ../sites-available/my.awesome.site-ssl.conf directory
/usr/local/bin/rmate: line 300: /my.awesome.site-ssl.conf: No such file or directory
cat: /my.awesome.site-ssl.conf: No such file or directory

expected result: rmate opening and sending the real file the symlink points to

additional info: symlink points to "../sites-available/my.awesome.site-ssl.conf"

elgarfo commented 6 years ago

works for me (on debian 8): adding "-f" to the command line switches for readlink (from the man pages: https://linux.die.net/man/1/readlink)

diff --git a/bin/rmate b/bin/rmate
index 7c04097..025b3b3 100755
--- a/bin/rmate
+++ b/bin/rmate
@@ -138,7 +138,7 @@ function canonicalize {
     local dir=$(dirpath "$filepath")

     if [ -L "$filepath" ]; then
-        relativepath=$(cd "$dir" || { echo "unable to cd to $dir" 1>&2; exit; } ; readlink "$(basename "$filepath")")
+        relativepath=$(cd "$dir" || { echo "unable to cd to $dir" 1>&2; exit; } ; readlink -f "$(basename "$filepath")")
         result=$(dirpath "$relativepath")/$(basename "$relativepath")
     else
         result=$(basename "$filepath")
aurora commented 6 years ago

Hi, the problem is, that -f is not available on some systems (eg.: macOS). But i'll have a look into the issue.

hadisfr commented 6 years ago

Take a look at here and here please. Perhaps we can use uname or $OSTYPE to determine OS type (as mentioned here) and use readlink -f or realpath based on it.

duzun commented 6 years ago

I've made a small C program and compile it when realpath is not available in the system, on first invocation. Here is the realpath folder with the code.

aurora commented 5 years ago

This is now fixed in master branch. Thanks all for suggestions and help.