-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix symlink error on windows,download and get api will return abs pat…
…h now
- Loading branch information
1 parent
c0787b9
commit 3bf181c
Showing
4 changed files
with
92 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) seasonjs. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
//go:build !windows | ||
|
||
package api | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
const useANSICodes = true | ||
|
||
func symlinkOrRename(src, dst string) error { | ||
if info, err := os.Stat(dst); err == nil && info != nil { | ||
return nil | ||
} | ||
|
||
absSrc, err := filepath.Abs(src) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
absDst, err := filepath.Abs(dst) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = os.Symlink(absSrc, absDst) | ||
if err != nil && !os.IsExist(err) { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) seasonjs. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
//go:build windows | ||
|
||
package api | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
const useANSICodes = true | ||
|
||
func symlinkOrRename(src, dst string) error { | ||
if info, err := os.Stat(dst); err == nil && info != nil { | ||
return nil | ||
} | ||
|
||
absSrc, err := filepath.Abs(src) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
absDst, err := filepath.Abs(dst) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = os.Link(absSrc, absDst); !os.IsExist(err) && err != nil { | ||
err = os.Rename(absSrc, absDst) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |