-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Launching program from outside it's directory causes it to fail in locating relay.jar #6
Comments
I thought that issue was fixed in an earlier version according to the commit log. |
I downloaded the files about a week ago and ran them. I'm not sure if
they've updated since then.
…On Apr 9, 2017 2:36 PM, "Zero3K" ***@***.***> wrote:
I thought that issue was fixed in an earlier version according to the
commit log.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#6 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV-HfWwJ1YNQ7qnVhfhk8YOVSDoADOqcks5ruU9IgaJpZM4M3SMj>
.
|
So, you ran v1.0.1 of it? |
The gnirehtet script assumed that it was called from its own directory. To overcome this limitation, detect and move to the physical directory of the script. This requires to resolve symlinks first (in case the script is called through a symlink). Unfortunately, "realpath" is not always installed by default, and the "readlink" behavior is different on Mac OS. Therefore, implement a best effort solution. See <http://stackoverflow.com/a/17744637/1987178>. Related to <#6>.
Thank you for the report. Indeed, the script assumed (for simplicity) that it was called from its own directory. To make it callable from everywhere, we have to detect the actual directory of the script (after symlink resolution), which is unfortunately not easily done by calling commands in a portable way. Requirements: all the following commands must work on both Linux and Mac OS. The simple one, from the current directory:
By calling bash:
From another directory:
From a symlink:
I implemented a best effort solution (53542df, not merged into |
Isn't there a command to list current directory so you can find the jar
file in there? Or, is that more of an issue with bash not providing the
variable/function needed?
…On Apr 10, 2017 3:57 AM, "Romain Vimont (®om)" ***@***.***> wrote:
Thank you for the report. Indeed, the script assumed (for simplicity) that
it was called from its own directory.
To make it callable from everywhere, we have to detect the actual
directory of the script (after symlink resolution), which is unfortunately
not easily done by calling commands in a portable way.
Requirements: all the following commands must work on both Linux and Mac
OS.
The simple one, from the current directory:
./gnirehtet rt
By calling *bash*:
bash gnirehtet rt
From another directory:
gnirehtet/gnirehtet rt
From a symlink:
ln -s /the/gnirehtet/directory/gnirehtet /tmp
/tmp/gnirehtet rt
I implemented a *best effort* solution (53542df
<53542df>,
not merged into master), but by default it does not work on Mac OS (it
seems that brew install coreutils fixes the problem), so this would break
the script even with ./gnirehtet rt for them. So I think we have to find
a better solution.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#6 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV-HfWAAYmmELuojTfr4fcyOugEa8Ct-ks5rugsIgaJpZM4M3SMj>
.
|
@ThinkDigitalRepair The problem is to determine the physical directory of gnirehtet (which is not necessarily the current directory) from the command from which the script has been called (in the variable For instance, suppose you have these files:
And a symlink pointing in
Then, when you call The problem is to do it in a way that is:
Meanwhile, of course, as a workaround, you can enclose the call to
|
Understandable. Would it be possible to encapsulate relay.jar in the
gnirehtet executable? I think I used to do something similar in c++ or Java
a while ago
…On Apr 10, 2017 9:12 AM, "Romain Vimont (®om)" ***@***.***> wrote:
@ThinkDigitalRepair <https://github.com/ThinkDigitalRepair> The problem
is to determine the physical directory of *gnirehtet* (which is not
necessarily the current directory) from the command from which the script
has been called (in the variable $0).
For instance, suppose you have these files:
/home/rom/gnirehtet/gnirehtet
/home/rom/gnirehtet/gnirehtet.apk
/home/rom/gnirehtet/relay.jar
And a symlink pointing in /usr/bin, created by:
ln -s /home/rom/gnirehtet/gnirehtet /usr/bin/
Then, when you call gnirehtet or /usr/bin/gnirehtet, we have to retrieve
the path /home/rom/gnirehtet to find relay.jar. In theory, this is
straighforward: resolve symlinks recursively, then take the directory of
the result.
The problem is to do it in a way that is:
- portable (works natively on Linux and Mac OS)
- simple (do not reimplement the whell)
- consistent (should work whether it is called from another directory
and/or a symlink and/or by calling *bash* explicitly…)
This can cause issues when trying to write scripts that reside outside the
project's directory.
Meanwhile, of course, as a workaround, you can enclose the call to
gnirehtet by calls to cd:
cd /the/directory/of/gnirehtet
./gnirehtet rt
cd -
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV-HfTGX8lJT5x227MSqRATR8ggC5k3Mks5rulTjgaJpZM4M3SMj>
.
|
Would it be preferable to do so? gnirehtet is just a bash script. |
I guess it wouldn't. Thanks for your quick responses!
…On Apr 10, 2017 9:19 AM, "Romain Vimont (®om)" ***@***.***> wrote:
Would it be possible to encapsulate relay.jar in the gnirehtet executable?
Would it be preferable to do so?
*gnirehtet* is just a bash script.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV-HffyfguG0fQ4KOCV4dqd37Ibwx64_ks5rulaJgaJpZM4M3SMj>
.
|
@rom1v definitely it wouldn't be preferable |
This can cause issues when trying to write scripts that reside outside the project's directory.
The text was updated successfully, but these errors were encountered: