【问题标题】:Why does Rake drop the drive-letter from a rooted path used as a file task name?为什么 Rake 会从用作文件任务名称的根路径中删除驱动器号?
【发布时间】:2014-05-20 22:03:26
【问题描述】:

为了安全和移动性,我将我的 dotfiles 放在 git 存储库中。我写了一个简单的 Rake 任务来用存储库中的点文件覆盖我的用户目录中的点文件,如果它是新的。这是一个简单的file 任务。例如,这里有一个文件任务全部拼写出来,所以我们不知道发生了什么愚蠢的事情......

file File.expand_path("~/.bashrc") => ".bashrc" do |task|
  system "cp #{task.source} #{task.name}"
end

但是,当我让 Rake 检查任务依赖项时,我丢失了驱动器号!

$ rake -P
rake /Users/anthony/.bashrc
    lib/.bashrc

如果我设置一个“默认”任务,它使用与依赖项相同的路径而不是名称,我会得到驱动器号。

task :default => [File.expand_path("~/.bashrc")]
$ rake -P
rake default
    C:/Users/anthony/.bashrc

我在 Windows 7 Pro x64 上使用 Ruby 1.9.3p484 (2013-11-22) [i386-mingw32] 在 32 位 shell 中。

【问题讨论】:

    标签: ruby path rake


    【解决方案1】:

    这不再是观察到的行为。拿那个 rakefile

    file File.expand_path("~/.bashrc") => ".bashrc" do |task|
      system("cp #{task.source} #{task.name}")
    end
    

    还有输出

    $ rake -P
    rake c:/Users/eacwpku/.bashrc
        .bashrc
    

    我的系统并没有太大变化......

    • Windows 7 Pro x64
    • ruby 1.9.3p545 (2014-02-24) [i386-mingw32]
    • PowerShell 3.0 或 mingw (Git Bash)

    【讨论】:

      猜你喜欢
      • 2011-12-08
      • 2020-05-04
      • 1970-01-01
      • 2013-02-10
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      相关资源
      最近更新 更多