microsoft / go-winio

Win32 IO-related utilities for Go
MIT License
939 stars 181 forks source link

Add `fs.ResolvePath` to resolve symbolic links #275

Closed helsaawy closed 1 year ago

helsaawy commented 1 year ago

filepath.EvalSymlinks does not work well on Windows, and can loop indefinitely in certain situations and error out.

Add ResolvePath, which uses the Win32 GetFinalPathNameByHandle to resolve the final path of a file by first opening it. Add "internal/stringbuffer".WString struct to maintain a pool of []uint16 buffers for use with interacting with the Win32APIs Add "internal/fs" pkg with Win32 CreateFile, GetFinalPathNameByHandle, and associated flags and access masks

Core implementation is based off of: https://github.com/containerd/containerd/pull/5411

Signed-off-by: Hamza El-Saawy hamzaelsaawy@microsoft.com

kevpar commented 1 year ago

Can we carry over the tests from https://github.com/containerd/containerd/blob/main/pkg/os/os_windows_test.go?

helsaawy commented 1 year ago

Can we carry over the tests from https://github.com/containerd/containerd/blob/main/pkg/os/os_windows_test.go?

I wanted to avoid that since that would hcsshim as a dependency for this package, which could cause weird cyclic import issues. The alternative would be add computestorage bindings here, but I would rather save that for a separate PR

helsaawy commented 1 year ago

Can we carry over the tests from https://github.com/containerd/containerd/blob/main/pkg/os/os_windows_test.go?

I wanted to avoid that since that would hcsshim as a dependency for this package, which could cause weird cyclic import issues. The alternative would be add computestorage bindings here, but I would rather save that for a separate PR

@kevpar I added tests and needed APIs to this PR: #276