New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows: added Ansible.IO c# code to work on paths greater than 260 #43666

wants to merge 6 commits into
base: devel


None yet
4 participants

jborean93 commented Aug 4, 2018


This PR adds the namespace Ansible.IO to the Ansible.ModuleUtils.FileUtil that allows modules to interact with paths that exceeds MAX_PATH (~260 chars). This namespace is designed to replicate the functionality of System.IO.Directory/DirectoryInfo/File/FileInfo/Path but also to add support for the following;

  • Interact with paths that exceed MAX_PATH when using the \\?\ prefix
  • Automatic privilege enablement when setting ACLs that require the relevant privileges
  • Added Compress() and Decompress() methods to enable the toggling of the Compress attribute
  • Added the ability to manipulate sparse files and clear ranges within a sparse file
  • More functions to enumerate alternative streams and read/write to these streams

Further changes to this PR are to LinkUtil which changes;

  • Support for links greater than MAX_PATH
  • Support for creating symlinks/junction points against a missing target
  • Support for creating relative symlinks
  • Support for creating symlinks on newer Windows versions without having admin privileges
  • Only enable the SeBackupPrivilege when required instead of doing it globally

First part to achieve #43060.

  • Feature Pull Request



There is a lot of code in the Ansible.ModuleUtils.FileUtil.psm1 is slightly modified from which is licensed under the MIT license. When doing some testing against devel, the win_stat tests only took an extra 1-3 seconds so the extra code does not seem to slow anything down dramatically.


This comment has been minimized.


This comment has been minimized.


ansibot commented Aug 5, 2018

@jborean93 jborean93 force-pushed the jborean93:win_max_path branch 3 times, most recently Aug 5, 2018

@ansibot ansibot added core_review and removed needs_revision labels Aug 6, 2018

@ryansb ryansb removed the needs_triage label Aug 7, 2018

# Test-Path -IsValid failed when the long path prefix is there, we don't want
# to check this ourselves and just rely on Windows to validate the path when
# using it
if ((-not ($value.StartsWith("\\?\"))) -and (-not (Test-Path -Path $value -IsValid))) {

This comment has been minimized.


jborean93 Aug 8, 2018


I'm wondering whether we should not even run Expand-Environment on the value if it starts with \\?\ to allow people to force a file/dir name with a value that's like an env var.

@ansibot ansibot added needs_revision and removed core_review labels Aug 8, 2018


This comment has been minimized.


mattclay commented Aug 10, 2018

I've restarted the failing CI job multiple times, but it keeps coming back unstable:


This comment has been minimized.


jborean93 commented Aug 10, 2018

@mattclay thanks, looks like there's still an issue with async. Will look into it.

@jborean93 jborean93 force-pushed the jborean93:win_max_path branch Aug 10, 2018

@ansibot ansibot added the core_review label Aug 10, 2018

@jborean93 jborean93 force-pushed the jborean93:win_max_path branch Aug 12, 2018

jborean93 added some commits Jan 3, 2018

@jborean93 jborean93 force-pushed the jborean93:win_max_path branch to d1d90f9 Aug 19, 2018

jborean93 added some commits Aug 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment