-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround
Errno::ENOENT
error in rubygems
When trying to `require` a gem running in an unlinked directory, an exception is thrown because `Dir.pwd` is called (see rubygems/rubygems#3087). Until the fix lands in an official release, we monkey patch `Dir.pwd` to return '/' if a `Errno::ENOENT` exception is raised while loading the colorls gem. This should work for all Unixes. On Windows, this error cannot happen since you cannot unlink a directory which is still in use by a process. Fixes #351.
- Loading branch information
Showing
3 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# workaround https://github.com/rubygems/rubygems/issues/3087 | ||
|
||
# rubocop:disable Style/GlobalVars | ||
$loading = true | ||
|
||
class Dir | ||
@@old_pwd = singleton_method(:pwd) # rubocop:disable Style/ClassVars | ||
|
||
def self.pwd | ||
@@old_pwd.call | ||
rescue Errno::ENOENT => e | ||
return '/' if $loading | ||
|
||
raise e | ||
end | ||
end | ||
|
||
require 'colorls' | ||
|
||
$loading = false | ||
# rubocop:enable Style/GlobalVars | ||
|
||
ColorLS::Flags.new(*ARGV).process | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters