aurora / rmate

Remote TextMate 2 implemented as shell script

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unable to open symlinks with relative paths

elgarfo opened this issue · comments

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"

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")

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

commented

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.

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.

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