Skip to content
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

Modernize usage of File.dirname(__FILE__) to support symlinks #46

Open
pcbeard opened this issue Jun 25, 2017 · 1 comment
Open

Modernize usage of File.dirname(__FILE__) to support symlinks #46

pcbeard opened this issue Jun 25, 2017 · 1 comment

Comments

@pcbeard
Copy link

pcbeard commented Jun 25, 2017

I tried to create a symlink to ftpd/bin/ftpdrb, but this broke the relative path name loading code:

unless $:.include?(File.dirname(__FILE__) + '/../lib')
  $:.unshift(File.dirname(__FILE__) + '/../lib')
end

This stack overflow article suggests using __dir__ as the equivalent of File.dirname(File.realpath(__FILE__)) which is precisely what's needed to compute the proper relative paths. Here's a patch:

diff --git a/bin/ftpdrb b/bin/ftpdrb
index 4513597..dcd222d 100755
--- a/bin/ftpdrb
+++ b/bin/ftpdrb
@@ -2,8 +2,8 @@
 #
 # Ftpd is a pure Ruby FTP server library. CLI version
 #
-unless $:.include?(File.dirname(__FILE__) + '/../lib')
-  $:.unshift(File.dirname(__FILE__) + '/../lib')
+unless $:.include?(__dir__ + '/../lib')
+  $:.unshift(__dir__ + '/../lib')
 end
 
 require 'ftpd'
@wconrad
Copy link
Owner

wconrad commented Jul 17, 2017

ftpd currently supports Ruby versions going back to 1.9.3. __dir__ was introduced in 2.0, I think.

Can you tell me more about the symlink? Normally, if a gem is installed, its executables should automatically be in your path, so there'd be no need to create a symlink to it.

By the way, I found that ftpdrb wasn't running correctly at all when run from an installed gem. I fixed that in 9be1d37 and that fix is in 2.0.2 which I released today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants