mirror of
https://github.com/golang/go.git
synced 2025-05-20 23:03:26 +00:00
os: use filepathlite.IsAbs
It is better to have a single implementation of IsAbs, which is quite tricky to get right on Windows. Change-Id: I45933b0ceff2920d9eddb61e62aacb2602c3dc8c Reviewed-on: https://go-review.googlesource.com/c/go/+/582498 Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
150f45b2c4
commit
d95fa7aca7
@ -6,6 +6,7 @@ package os
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"internal/filepathlite"
|
||||||
"internal/godebug"
|
"internal/godebug"
|
||||||
"internal/poll"
|
"internal/poll"
|
||||||
"internal/syscall/windows"
|
"internal/syscall/windows"
|
||||||
@ -313,7 +314,7 @@ func Symlink(oldname, newname string) error {
|
|||||||
return &LinkError{"symlink", oldname, newname, err}
|
return &LinkError{"symlink", oldname, newname, err}
|
||||||
}
|
}
|
||||||
var o *uint16
|
var o *uint16
|
||||||
if isAbs(oldname) {
|
if filepathlite.IsAbs(oldname) {
|
||||||
o, err = syscall.UTF16PtrFromString(fixLongPath(oldname))
|
o, err = syscall.UTF16PtrFromString(fixLongPath(oldname))
|
||||||
} else {
|
} else {
|
||||||
// Do not use fixLongPath on oldname for relative symlinks,
|
// Do not use fixLongPath on oldname for relative symlinks,
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package os
|
package os
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"internal/filepathlite"
|
||||||
"internal/syscall/windows"
|
"internal/syscall/windows"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
@ -44,18 +45,6 @@ func basename(name string) string {
|
|||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
func isAbs(path string) (b bool) {
|
|
||||||
v := volumeName(path)
|
|
||||||
if v == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
path = path[len(v):]
|
|
||||||
if path == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return IsPathSeparator(path[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
func volumeName(path string) (v string) {
|
func volumeName(path string) (v string) {
|
||||||
if len(path) < 2 {
|
if len(path) < 2 {
|
||||||
return ""
|
return ""
|
||||||
@ -174,7 +163,7 @@ func addExtendedPrefix(path string) string {
|
|||||||
// The MSDN docs appear to say that a normal path that is 248 bytes long
|
// The MSDN docs appear to say that a normal path that is 248 bytes long
|
||||||
// will work; empirically the path must be less then 248 bytes long.
|
// will work; empirically the path must be less then 248 bytes long.
|
||||||
pathLength := len(path)
|
pathLength := len(path)
|
||||||
if !isAbs(path) {
|
if !filepathlite.IsAbs(path) {
|
||||||
// If the path is relative, we need to prepend the working directory
|
// If the path is relative, we need to prepend the working directory
|
||||||
// plus a separator to the path before we can determine if it's too long.
|
// plus a separator to the path before we can determine if it's too long.
|
||||||
// We don't want to call syscall.Getwd here, as that call is expensive to do
|
// We don't want to call syscall.Getwd here, as that call is expensive to do
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package os
|
package os
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"internal/filepathlite"
|
||||||
"internal/godebug"
|
"internal/godebug"
|
||||||
"internal/syscall/windows"
|
"internal/syscall/windows"
|
||||||
"sync"
|
"sync"
|
||||||
@ -338,7 +339,7 @@ func (fs *fileStat) loadFileId() error {
|
|||||||
// and set name from path.
|
// and set name from path.
|
||||||
func (fs *fileStat) saveInfoFromPath(path string) error {
|
func (fs *fileStat) saveInfoFromPath(path string) error {
|
||||||
fs.path = path
|
fs.path = path
|
||||||
if !isAbs(fs.path) {
|
if !filepathlite.IsAbs(fs.path) {
|
||||||
var err error
|
var err error
|
||||||
fs.path, err = syscall.FullPath(fs.path)
|
fs.path, err = syscall.FullPath(fs.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user