在Windows上的gem错误 – “openpath:path名太长”

我最近开始在运行gem或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中的dln_find.c文件,当它试图产生一个比系统上MAXPATHLEN值更长的路径时会引发这个错误。

按照这个MSDN参考 ,Windows API中许多函数的最大路径长度只有248个字符 – 因此,我猜测MAXPATHLEN在Ruby-for-Windows源代码中被定义为248。 (或者, dln_find.c源代码定义为1024,如果没有定义的话)。

如果你是程序员,在程序中有很多方法可以解决这个问题,但是在用户层面的解决方案可能是你必须使用一个短名称的目录。

(所以,什么目录需要更短?好吧,有错误消息告诉你什么文件,它是试图加载,这是chcpgit 。也许你的git升级改变了它的目录名太长,你需要把它移动到一个短名称的地方?或者…它看起来像这个查找代码可能会遍历PATH环境变量中的每个条目,并检查它,并抛出一个“太长”的错误,如果任何可能性太长 – – 也许你的PATH是腐败的或有一个新的很长的条目?)