1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 var symlinkOnce sync
.Once
16 var winSymlinkErr error
18 func initWinHasSymlink() {
19 tmpdir
, err
:= ioutil
.TempDir("", "symtest")
21 panic("failed to create temp directory: " + err
.Error())
23 defer os
.RemoveAll(tmpdir
)
25 err
= os
.Symlink("target", filepath
.Join(tmpdir
, "symlink"))
27 err
= err
.(*os
.LinkError
).Err
29 case syscall
.EWINDOWS
, syscall
.ERROR_PRIVILEGE_NOT_HELD
:
35 func hasSymlink() (ok
bool, reason
string) {
36 symlinkOnce
.Do(initWinHasSymlink
)
38 switch winSymlinkErr
{
41 case syscall
.EWINDOWS
:
42 return false, ": symlinks are not supported on your version of Windows"
43 case syscall
.ERROR_PRIVILEGE_NOT_HELD
:
44 return false, ": you don't have enough privileges to create symlinks"