]> Cypherpunks repositories - gostls13.git/commitdiff
os: use filepathlite.FromSlash
authorqmuntal <quimmuntal@gmail.com>
Tue, 30 Apr 2024 12:46:05 +0000 (14:46 +0200)
committerDamien Neil <dneil@google.com>
Tue, 30 Apr 2024 15:38:38 +0000 (15:38 +0000)
Change-Id: Id15ebd9e97a8626e64665f6830a662e62432a619
Reviewed-on: https://go-review.googlesource.com/c/go/+/582500
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/os/file_windows.go
src/os/path_windows.go

index 245f99432128de9c1231977eed2e30ac70d948fc..cf652ca1bb3f17dbdda543814de451dec8901337 100644 (file)
@@ -288,7 +288,7 @@ func Link(oldname, newname string) error {
 // If there is an error, it will be of type *LinkError.
 func Symlink(oldname, newname string) error {
        // '/' does not work in link's content
-       oldname = fromSlash(oldname)
+       oldname = filepathlite.FromSlash(oldname)
 
        // need the exact location of the oldname when it's relative to determine if it's a directory
        destpath := oldname
index 162b63194c63565afa185a04fa4d09eff001c956..4d7bdb2fa2b2463afa2bb596317a17424d696216 100644 (file)
@@ -45,28 +45,6 @@ func basename(name string) string {
        return name
 }
 
-func fromSlash(path string) string {
-       // Replace each '/' with '\\' if present
-       var pathbuf []byte
-       var lastSlash int
-       for i, b := range path {
-               if b == '/' {
-                       if pathbuf == nil {
-                               pathbuf = make([]byte, len(path))
-                       }
-                       copy(pathbuf[lastSlash:], path[lastSlash:i])
-                       pathbuf[i] = '\\'
-                       lastSlash = i + 1
-               }
-       }
-       if pathbuf == nil {
-               return path
-       }
-
-       copy(pathbuf[lastSlash:], path[lastSlash:])
-       return string(pathbuf)
-}
-
 func dirname(path string) string {
        vol := filepathlite.VolumeName(path)
        i := len(path) - 1