Skip to content

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

@pcbeard

Description

@pcbeard

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions