2

anybody is familiar with the etcd project? Or we'd better forget the project when talk about this issue. The issue is

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

when exec the build shell and the content is:

#!/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

Some addition: My system is windows 7
I run the shell on git bash. issue reproduce:

step1: open the git bash
step2: git clone git@github.com:coreos/etcd.git
step3: cd etcd
step4: build
peterSO
  • 158,998
  • 31
  • 281
  • 276
user3231931
  • 331
  • 1
  • 2
  • 8

3 Answers3

1

As mentioned in "Git Bash Shell fails to create symbolic links" (since you are using the script in a git bash on Windows 7)

the ln that shipped with msysGit simply tries to copy its arguments, rather than fiddle with links. This is because links only work (sort of) on NTFS filesystems, and the MSYS team didn't want to reimplement ln.

A workaround is to run mklink from Bash.
This also allows you to create either a Symlink or a Junction.

So 'ln' wouldn't work as expected by default, in the old shell that ships with Git for Windows.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Here's solution. Tbh it is a workaround, but since you're on Windows, I don't see another way.

Start a command line, and enter there to the directory with the script. There should be a path gopath/src/github.com/coreos/ (if no such a path, you must create it). Next issue a command

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

Next you should edit the build script to delete a lines with creation symlink and a directory. E.g.

#!/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

Note, that I am just removed 4 lines of code. Next you run the script, and this should work.

Hi-Angel
  • 4,933
  • 8
  • 63
  • 86
  • when exec the D:\Git\etcd>mklink \D gopath/src/github.com/coreos/etcd ../../../.. it says “unavailable switch - 'src'” – user3231931 Aug 20 '14 at 06:37
  • @user3231931, oh, sorry, I wrote a wrong slash. It should be `mklink /D gopath/src/github.com/coreos/etcd ../../../../`. I will edit the answer. – Hi-Angel Aug 20 '14 at 06:46
  • I've tried this. the same result “unavailable switch - 'src'” it's wired. – user3231931 Aug 20 '14 at 06:53
  • @user3231931 hm... Try then add a quotes, like this: `mklink /D "gopath/src/github.com/coreos/etcd" "../../../../"` – Hi-Angel Aug 20 '14 at 06:53
  • yes, now it works by add the quotes. I try other parts. – user3231931 Aug 20 '14 at 06:55
  • Good workaround, more detailed than my answer who mentioned first the issue. +1 – VonC Aug 20 '14 at 06:58
  • @Hi-Angel sign.another issue when exec the build shell after remove the `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` can't load package: package github.com/coreos/etcd: open d:\git\etcd\gopath\src\github.com\coreos\etcd: Access is denied. – user3231931 Aug 20 '14 at 07:00
  • @user3231931 I know why is this. The `../../../../` path refers to an unxistent directory that is above even "disk D:". I think that the script probably should had some other relevant directory there, and I have no idea what the directory this could be. – Hi-Angel Aug 20 '14 at 07:05
  • @user3231931 this is really weird. Perhaps you should ask about it(about the directory) on the mailing list of the `etcd`, or on IRC. – Hi-Angel Aug 20 '14 at 07:11
  • @Hi-Angel Ok. I will ask about it on the mailing list, thank you so much – user3231931 Aug 20 '14 at 07:14
  • @VonC, if you occasionally thought that I am saw your answer, and decided to stole it, this isn't true. I didn't refreshed the page, and doesn't saw an answers at the moment. I didn't even knew what the issue was with `ln` and what `etcd` is. I just saw the script, after some comments figured out, that the author using Windows®, and BASH probably executed via some emulating interpreter that is failing on `ln`, and recall that the Windows has some support of symlink. Then googled what the command was to create these, and — voilà. – Hi-Angel Aug 20 '14 at 10:52
  • 1
    @Hi-Angel The thought never cross my mind. I still consider your answer better and more complete than mine, and I am glad you took the time to investigate the issue further. – VonC Aug 20 '14 at 10:53
0

You shouldn't be using git clone and the build sh script. Use the go get command. For example, on 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:\>
peterSO
  • 158,998
  • 31
  • 281
  • 276
  • is there any difference between these two ways? – user3231931 Aug 20 '14 at 07:05
  • @user3231931: Yes. The Go tools like `go get` take care of this for you with no effort on your part. You used a fudge of an package dependent and OS dependent build script which currently works for one package on one operating system and won't work elsewhere. Go packages don't need build scripts. – peterSO Aug 20 '14 at 07:27