【问题标题】:some error with the 'ln' scripts'ln' 脚本有一些错误
【发布时间】:2014-08-20 03:59:12
【问题描述】:

有人熟悉 etcd 项目吗?或者我们在谈论这个问题时最好忘记这个项目。问题是

$ build
ln: `gopath/src/github.com/coreos/etcd': cannot overwrite directory

当执行 build shell 内容是:

#!/bin/sh -e

if [ ! -h gopath/src/github.com/coreos/etcd ]; then
    mkdir -p gopath/src/github.com/coreos/
    ln -s ../../../.. gopath/src/github.com/coreos/etcd
fi

export GOBIN=${PWD}/bin
export GOPATH=${PWD}/gopath
export GOFMTPATH="./bench ./config ./discovery ./etcd ./error ./http ./log main.go ./metrics ./mod ./server ./store ./tests"

# Don't surprise user by formatting their codes by stealth
if [ "--fmt" = "$1" ]; then
    gofmt -s -w -l $GOFMTPATH
fi

go install github.com/coreos/etcd
go install github.com/coreos/etcd/bench

一些补充: 我的系统是windows 7
我在 git bash 上运行 shell。 问题重现:

step1: open the git bash
step2: git clone git@github.com:coreos/etcd.git
step3: cd etcd
step4: build

【问题讨论】:

  • 我看不出 java 与这里有什么关系。我已将其删除。
  • 奇怪,ln -s 我什至不能发出这样的错误。
  • 好的,告诉我:如果你转到带有构建脚本的目录,然后发出命令mkdir -p gopath/src/github.com/coreos/ln -s ../../../.. gopath/src/github.com/coreos/etcd — 会出现错误吗?
  • @Hi-Angel 你能看看我的编辑吗?

标签: linux windows shell go


【解决方案1】:

如“Git Bash Shell fails to create symbolic links”中所述(因为您在 Windows 7 上的 git bash 中使用该脚本)

msysGit 附带的ln 只是尝试复制其参数,而不是摆弄链接。这是因为链接只能(在某种程度上)在 NTFS 文件系统上工作,而 MSYS 团队不想重新实现 ln。

解决方法是从 Bash 运行 mklink
这也允许您创建Symlink or a Junction

因此,默认情况下,在 Git for Windows 附带的旧 shell 中,'ln' 不会按预期工作。

【讨论】:

    【解决方案2】:

    这里是解决方案。 Tbh 这是一种解决方法,但由于您使用的是 Windows,因此我看不到其他方法。

    启动一个命令行,并在那里输入脚本所在的目录。应该有一个路径gopath/src/github.com/coreos/(如果没有这样的路径,你必须创建它)。接下来发出命令

    mklink /D "gopath/src/github.com/coreos/etcd" "../../../../"
    

    接下来,您应该编辑构建脚本以删除带有创建符号链接和目录的行。例如。

    #!/bin/sh -e
    
    export GOBIN=${PWD}/bin
    export GOPATH=${PWD}/gopath
    export GOFMTPATH="./bench ./config ./discovery ./etcd ./error ./http ./log main.go ./metrics ./mod ./server ./store ./tests"
    
    # Don't surprise user by formatting their codes by stealth
    if [ "--fmt" = "$1" ]; then
        gofmt -s -w -l $GOFMTPATH
    fi
    
    go install github.com/coreos/etcd
    go install github.com/coreos/etcd/bench
    

    请注意,我刚刚删除了 4 行代码。接下来运行脚本,这应该可以工作。

    【讨论】:

    • 当执行 D:\Git\etcd>mklink \D gopath/src/github.com/coreos/etcd ../../../.. 它说“不可用的开关 - ” src'”
    • @user3231931,哦,对不起,我写错了斜线。应该是mklink /D gopath/src/github.com/coreos/etcd ../../../../。我将编辑答案。
    • 我试过这个。同样的结果“不可用的开关 - 'src'”它是有线的。
    • @user3231931 hm... 然后尝试添加引号,如下所示:mklink /D "gopath/src/github.com/coreos/etcd" "../../../../"
    • @Hi-Angel 我从来没有想过这个想法。我仍然认为你的答案比我的更好、更完整,很高兴你花时间进一步调查这个问题。
    【解决方案3】:

    您不应该使用 git clonebuild sh 脚本。使用go get 命令。例如,在 Windows 7 上,

    Microsoft Windows [Version 6.1.7601]
    C:\>set gopath
    GOPATH=C:\gopath
    C:\>go version
    go version go1.3 windows/amd64
    C:\>go get -v -u github.com/coreos/etcd
    github.com/coreos/etcd (download)
    github.com/coreos/etcd/third_party/bitbucket.org/kardianos/osext
    github.com/coreos/etcd/pkg/strings
    github.com/coreos/etcd/error
    github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd
    github.com/coreos/etcd/http
    github.com/coreos/etcd/third_party/github.com/coreos/go-log/log
    github.com/coreos/etcd/third_party/github.com/rcrowley/go-metrics
    github.com/coreos/etcd/mod/dashboard/resources
    github.com/coreos/etcd/log
    github.com/coreos/etcd/third_party/github.com/gorilla/context
    github.com/coreos/etcd/third_party/github.com/gorilla/mux
    github.com/coreos/etcd/mod/dashboard
    github.com/coreos/etcd/discovery
    github.com/coreos/etcd/pkg/btrfs
    github.com/coreos/etcd/pkg/http
    github.com/coreos/etcd/third_party/code.google.com/p/gogoprotobuf/proto
    github.com/coreos/etcd/mod/leader/v2
    github.com/coreos/etcd/mod/lock/v2
    github.com/coreos/etcd/metrics
    github.com/coreos/etcd/third_party/github.com/mreiferson/go-httpclient
    github.com/coreos/etcd/mod
    github.com/coreos/etcd/third_party/github.com/BurntSushi/toml
    github.com/coreos/etcd/third_party/github.com/goraft/raft/protobuf
    github.com/coreos/etcd/third_party/github.com/goraft/raft
    github.com/coreos/etcd/store
    github.com/coreos/etcd/server/v1
    github.com/coreos/etcd/server/v2
    github.com/coreos/etcd/store/v2
    github.com/coreos/etcd/server
    github.com/coreos/etcd/config
    github.com/coreos/etcd/etcd
    github.com/coreos/etcd
    C:\>
    

    【讨论】:

    • 这两种方式有区别吗?
    • @user3231931:是的。像 go get 这样的 Go 工具可以为您解决这个问题,您无需付出任何努力。您使用了依赖包和依赖于操作系统的构建脚本的软糖,该脚本目前适用于一个操作系统上的一个包,并且在其他地方不起作用。 Go 包不需要构建脚本。
    猜你喜欢
    • 2013-10-09
    • 2014-11-27
    • 1970-01-01
    • 2016-06-21
    • 2022-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多