]> Cypherpunks repositories - gostls13.git/commit
os: support UNC paths and .. segments in fixLongPath
authorqmuntal <quimmuntal@gmail.com>
Tue, 12 Mar 2024 11:26:53 +0000 (12:26 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Mon, 18 Mar 2024 18:31:42 +0000 (18:31 +0000)
commit2e8d84f148c69404b8eec86d9149785a3f4e3e92
treea015722201f01fa62cce37fa484d8bcef638728a
parentb40dc30d24afe877f4b7d80c69b827765531cdc7
os: support UNC paths and .. segments in fixLongPath

This CL reimplements fixLongPath using syscall.GetFullPathName instead
of a custom implementation that was not handling UNC paths and ..
segments correctly. It also fixes a bug here multiple trailing \
were removed instead of replaced by a single one.

The new implementation is slower than the previous one, as it does a
syscall and needs to convert UTF-8 to UTF-16 (and back), but it is
correct and should be fast enough for most use cases.

goos: windows
goarch: amd64
pkg: os
cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
            │   old.txt    │                new.txt                 │
            │    sec/op    │    sec/op      vs base                 │
LongPath-12   1.007µ ± 53%   4.093µ ± 109%  +306.41% (p=0.000 n=10)

            │  old.txt   │               new.txt                │
            │    B/op    │    B/op      vs base                 │
LongPath-12   576.0 ± 0%   1376.0 ± 0%  +138.89% (p=0.000 n=10)

            │  old.txt   │              new.txt               │
            │ allocs/op  │ allocs/op   vs base                │
LongPath-12   2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=10)

Fixes #41734.

Change-Id: Iced5cf47f56f6ab0ca74a6e2374c31a75100902d
Reviewed-on: https://go-review.googlesource.com/c/go/+/570995
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/os/path_windows.go
src/os/path_windows_test.go