【问题标题】:gems error on windows - "openpath: pathname too long"Windows 上的 gems 错误 - “openpath:路径名太长”
【发布时间】:2011-12-01 17:09:03
【问题描述】:

我最近在运行 gems 或 bundler 时开始收到此错误。 我能记得我最近改变的唯一一件事是升级我的 git 版本。

我使用 MINGW32 作为 shell,一年多来一直运行良好。

我已确保 git 在我的 PATH 中,但现在不确定接下来要查找什么。

接下来我可以做些什么来解决这个问题?

这是我得到的输出示例。此示例显示了 heroku gem,但我在运行 bundle install 时得到了相同的结果

$ heroku console
openpath: pathname too long (ignored)
        Directory ""
        File "chcp"
openpath: pathname too long (ignored)
        Directory ""
        File "git"
c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/lib/heroku/helpers.rb:111:in ``': No such file or directory -  git --version  (Errno::ENOENT)
        from c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/lib/heroku/helpers.rb:111:in `has_git?'
        from c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/lib/heroku/helpers.rb:116:in `git'
        from c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/lib/heroku/command/base.rb:192:in `git_remotes'
        from c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/lib/heroku/command/base.rb:170:in `extract_app_in_dir'
        from c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/lib/heroku/command/base.rb:162:in `extract_app'
        from c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/lib/heroku/command/run.rb:72:in `console'
        from c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/lib/heroku/command.rb:114:in `run'
        from c:/Ruby192/lib/ruby/gems/1.9.1/gems/heroku-2.14.0/bin/heroku:14:in `<top (required)>'
        from c:/Ruby192/bin/heroku:19:in `load'
        from c:/Ruby192/bin/heroku:19:in `<main>'

这是上面引用的 helpers.rb 中的第 111 行。

def has_git?
  %x{ git --version } #this is 111
  $?.success?
end

【问题讨论】:

  • 你已经弄清楚了吗?看起来 ruby​​ 无法运行或找不到您的 git 可执行文件。

标签: ruby windows git rubygems


【解决方案1】:

此错误消息来自 Ruby 中的 dln_find.c 文件,当它尝试生成比系统上的 MAXPATHLEN 值更长的路径时会引发此错误。

根据this MSDN reference,Windows API 中许多函数的最大路径长度仅为 248 个字符——因此,我猜MAXPATHLEN 在 Ruby-for-Windows 源代码中定义为 248。 (或者,dln_find.c 来源将其定义为 1024,如果未另行定义。)

如果您是程序员,可以通过多种方法在程序中解决此问题,但在用户级别的解决方案可能是您必须使用名称较短的目录。

(那么,什么目录需要更短?嗯,有线索告诉你它正在尝试加载哪个文件,即chcpgit。也许你的 git upgrade 将其目录名称更改为东西太长了,你需要把它移到一个名字更短的地方吗?或者......看起来这个查找代码可能会遍历你的PATH环境变量中的每个条目并检查它并抛出“太长”如果任何给定的可能性太长,则会出错 - 也许您的 PATH 已损坏或有一个新的非常长的条目?)

【讨论】:

  • 谢谢,我没有机会验证,但会奖励赏金,因为我认为这是一个非常棒的答案,非常详细,它为我提供了多个开始检查的地方。非常感谢。
  • 不客气!当您有机会开始检查时,我很想知道您发现了什么。
  • 我在从我的下载文件夹安装 Eclipse 时遇到了类似的问题。我的解决方法是将安装文件(一个 zip 文件)移动到根目录下的文件夹并重命名。我不再得到那个错误。不确定这是否是最好的方法,但它让我克服了这个问题。
猜你喜欢
  • 2016-09-05
  • 2021-06-04
  • 1970-01-01
  • 2016-06-08
  • 1970-01-01
  • 1970-01-01
  • 2016-02-27
  • 2016-07-13
  • 2018-12-16
相关资源
最近更新 更多