We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[bug] crash on Windows when trying to obtain USERNAME from environment
<!--
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.

  To help us debug your issue please explain:
-->

### Environment Details (include every applicable attribute)
  * Operating System+version: Windows 11
  * Compiler+version: N/A
  * Conan version: 1.48
  * Python version: 3.10.4

### Steps to reproduce (Include if Applicable)
Powershell in which `USERNAME` is not set as a variable

```powershell
git clone https://github.com/ultimaker/libarcus.git
cd libarcus
git checkout CURA-9177_fix_CI_CT
conan create . arcus/5.0.0-PullRequest0137.67@ultimaker/testing -pr:b cura_build.jinja -pr:h cura_release.jinja --build=missing
```

### Logs (Executed commands with output) (Include/Attach if Applicable)

Traceback
```shell
Traceback (most recent call last):
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\command.py", line 2238, in run
    method(args[0][1:])
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\command.py", line 382, in create
    info = self._conan.create(args.path, name=name, version=version, user=user,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\conan_api.py", line 93, in wrapper
    return f(api, *args, **kwargs)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\conan_api.py", line 388, in create
    deps_install(app=app,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\manager.py", line 58, in deps_install
    deps_graph = graph_manager.load_graph(ref_or_path, create_reference, graph_info, build_modes,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 127, in load_graph
    deps_graph = self._resolve_graph(root_node, profile_host, profile_build, graph_lock,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 289, in _resolve_graph
    deps_graph = self._load_graph(root_node, check_updates, update,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 410, in _load_graph
    self._recurse_build_requires(graph, builder, check_updates, update, build_mode,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 336, in _recurse_build_requires
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 410, in _load_graph
    self._recurse_build_requires(graph, builder, check_updates, update, build_mode,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 336, in _recurse_build_requires
    self._binary_analyzer.evaluate_graph(graph, build_mode, update, remotes, nodes_subset, root)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_binaries.py", line 431, in evaluate_graph
    self._evaluate_node(node, build_mode, update, remotes)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_binaries.py", line 202, in _evaluate_node
    self._process_node(node, pref, build_mode, update, remotes)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_binaries.py", line 275, in _process_node
    if package_layout.package_id_exists(pref.id) and pref.id in metadata.packages:
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\paths\package_layouts\package_cache_layout.py", line 133, in package_id_exists
    pkg_folder = self.package(PackageReference(self._ref, package_id))
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\paths\package_layouts\package_cache_layout.py", line 32, in wrap
    return path_shortener(p, self._short_paths)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\util\windows.py", line 88, in path_shortener
    userdomain, username = os.getenv("USERDOMAIN"), os.environ["USERNAME"]
  File "C:\Program Files\Python310\lib\os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'USERNAME'

ERROR: 'USERNAME'
```

Environmental variables
```powershell
PS C:\dev\libarcus> gci env:* | sort-object name

Name                           Value
----                           -----                                                                                                                                                                                                                                                                                                                                                                                                 
__INTELLIJ_COMMAND_HISTFILE__  C:\Users\********\AppData\Local\JetBrains\CLion2022.1\terminal\history\libarcus-history                                                                                                                                                                                                                                                                                                              
ALLUSERSPROFILE                C:\ProgramData                                                                                                                                                                                                                                                                                                                                                                                        
APPDATA                        C:\Users\********\AppData\Roaming                                                                                                                                                                                                                                                                                                                                                                    
CommonProgramFiles             C:\Program Files\Common Files                                                                                                                                                                                                                                                                                                                                                                         
CommonProgramFiles(x86)        C:\Program Files (x86)\Common Files                                                                                                                                                                                                                                                                                                                                                                   
CommonProgramW6432             C:\Program Files\Common Files                                                                                                                                                                                                                                                                                                                                                                         
COMPUTERNAME                   ********                                                                                                                                                                                                                                                                                                                                                                                              
ComSpec                        C:\windows\system32\cmd.exe                                                                                                                                                                                                                                                                                                                                                                           
DriverData                     C:\Windows\System32\Drivers\DriverData                                                                                                                                                                                                                                                                                                                                                                
FPS_BROWSER_APP_PROFILE_STRING Internet Explorer                                                                                                                                                                                                                                                                                                                                                                                     
FPS_BROWSER_USER_PROFILE_ST... Default                                                                                                                                                                                                                                                                                                                                                                                               
HOMEDRIVE                      C:                                                                                                                                                                                                                                                                                                                                                                                                    
HOMEPATH                       \Users\********
IDEA_INITIAL_DIRECTORY         C:\
JAVA_HOME                      C:\Program Files\Amazon Corretto\jre8
LOCALAPPDATA                   C:\Users\********\AppData\Local
LOGONSERVER                    \\********
NUMBER_OF_PROCESSORS           12
OneDrive                       C:\Users\********\OneDrive - ***********
OneDriveCommercial             C:\Users\********\OneDrive - ***********
OS                             Windows_NT
Path                           C:\Program Files\Python310\Scripts\;C:\Program Files\Python310\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Amazon Corretto\jre8\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Users\********\AppDat... 
PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW;.CPL
PROCESSOR_ARCHITECTURE         AMD64
PROCESSOR_IDENTIFIER           Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
PROCESSOR_LEVEL                6
PROCESSOR_REVISION             a502
ProgramData                    C:\ProgramData
ProgramFiles                   C:\Program Files
ProgramFiles(x86)              C:\Program Files (x86)
ProgramW6432                   C:\Program Files
PSModulePath                   C:\Users\********\OneDrive - ***********\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\windows\system32\WindowsPow
SESSIONNAME                    Console
SystemDrive                    C:
SystemRoot                     C:\windows
TEMP                           C:\Users\JC9C9~1.SPI\AppData\Local\Temp
TERM_SESSION_ID                d1e664b1-b85c-49eb-85d8-be45055fdd9c
TERMINAL_EMULATOR              JetBrains-JediTerm
TMP                            C:\Users\JC9C9~1.SPI\AppData\Local\Temp
USERDOMAIN_ROAMINGPROFILE      ********
USERPROFILE                    C:\Users\********
windir                         C:\windows

```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conans/util/windows.py`
Content:
```
1 import os
2 import subprocess
3 import tempfile
4 
5 from conans.client.tools.oss import OSInfo
6 from conans.errors import ConanException
7 from conans.util.env_reader import get_env
8 from conans.util.files import decode_text
9 from conans.util.files import load, mkdir, rmdir, save
10 from conans.util.log import logger
11 from conans.util.sha import sha256
12 
13 CONAN_LINK = ".conan_link"
14 CONAN_REAL_PATH = "real_path.txt"
15 
16 
17 def conan_expand_user(path):
18     """ wrapper to the original expanduser function, to workaround python returning
19     verbatim %USERPROFILE% when some other app (git for windows) sets HOME envvar
20     """
21     if path[:1] != '~':
22         return path
23     # In win these variables should exist and point to user directory, which
24     # must exist. Using context to avoid permanent modification of os.environ
25     old_env = dict(os.environ)
26     try:
27         home = os.environ.get("HOME")
28         # Problematic cases of wrong HOME variable
29         # - HOME = %USERPROFILE% verbatim, as messed by some other tools
30         # - MSYS console, that defines a different user home in /c/mingw/msys/users/xxx
31         # In these cases, it is safe to remove it and rely on USERPROFILE directly
32         if home and (not os.path.exists(home) or
33                      (os.getenv("MSYSTEM") and os.getenv("USERPROFILE"))):
34             del os.environ["HOME"]
35         result = os.path.expanduser(path)
36     finally:
37         os.environ.clear()
38         os.environ.update(old_env)
39     return result
40 
41 
42 def path_shortener(path, short_paths):
43     """ short_paths is 4-state:
44     False: Never shorten the path
45     True: Always shorten the path, create link if not existing
46     None: Use shorten path only if already exists, not create
47     """
48     use_always_short_paths = get_env("CONAN_USE_ALWAYS_SHORT_PATHS", False)
49     short_paths = use_always_short_paths or short_paths
50 
51     if short_paths is False or os.getenv("CONAN_USER_HOME_SHORT") == "None":
52         return path
53     link = os.path.join(path, CONAN_LINK)
54     if os.path.exists(link):
55         return load(link)
56     elif short_paths is None:
57         return path
58 
59     if os.path.exists(path):
60         rmdir(path)
61 
62     short_home = os.getenv("CONAN_USER_HOME_SHORT")
63     if not short_home:
64         if OSInfo().is_cygwin:
65             try:
66                 cmd = ['cygpath', path, '--unix']
67                 out, _ = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False).communicate()
68                 out = decode_text(out)
69                 if out.startswith('/cygdrive/'):  # It was a Windows 'path'
70                     _, _, drive, _ = out.split('/', 3)
71                     short_home = os.path.join('/cygdrive', drive, '.conan')
72                 else:  # It was a cygwin path, use a path inside the user home
73                     short_home = os.path.join(os.path.expanduser("~"), '.conan_short')
74             except Exception:
75                 raise ConanException("Conan failed to create the short_paths home for path '{}'"
76                                      " in Cygwin. Please report this issue. You can use environment"
77                                      " variable 'CONAN_USER_HOME_SHORT' to set the short_paths"
78                                      " home.".format(path))
79         else:
80             drive = os.path.splitdrive(path)[0]
81             short_home = os.path.join(drive, os.sep, ".conan")
82     mkdir(short_home)
83 
84     # Workaround for short_home living in NTFS file systems. Give full control permission
85     # to current user to avoid
86     # access problems in cygwin/msys2 windows subsystems when using short_home folder
87     try:
88         userdomain, username = os.getenv("USERDOMAIN"), os.environ["USERNAME"]
89         domainname = "%s\%s" % (userdomain, username) if userdomain else username
90         cmd = r'cacls %s /E /G "%s":F' % (short_home, domainname)
91         subprocess.check_output(cmd, stderr=subprocess.STDOUT)  # Ignoring any returned output, quiet
92     except (subprocess.CalledProcessError, EnvironmentError):
93         # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.
94         pass
95 
96     redirect = hashed_redirect(short_home, path)
97     if not redirect:
98         logger.warning("Failed to create a deterministic short path in %s", short_home)
99         redirect = tempfile.mkdtemp(dir=short_home, prefix="")
100 
101     # Save the full path of the local cache directory where the redirect is from.
102     # This file is for debugging purposes and not used by Conan.
103     save(os.path.join(redirect, CONAN_REAL_PATH), path)
104 
105     # This "1" is the way to have a non-existing directory, so commands like
106     # shutil.copytree() to it, works. It can be removed without compromising the
107     # temp folder generator and conan-links consistency
108     redirect = os.path.join(redirect, "1")
109     save(link, redirect)
110     return redirect
111 
112 
113 def rm_conandir(path):
114     """removal of a directory that might contain a link to a short path"""
115     link = os.path.join(path, CONAN_LINK)
116     if os.path.exists(link):
117         short_path = load(link)
118         rmdir(os.path.dirname(short_path))
119     rmdir(path)
120 
121 
122 def hashed_redirect(base, path, min_length=6, attempts=10):
123     max_length = min_length + attempts
124 
125     full_hash = sha256(path.encode())
126     assert len(full_hash) > max_length
127 
128     for length in range(min_length, max_length):
129         redirect = os.path.join(base, full_hash[:length])
130         if not os.path.exists(redirect):
131             return redirect
132     else:
133         return None
134
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/conans/util/windows.py b/conans/util/windows.py
--- a/conans/util/windows.py
+++ b/conans/util/windows.py
@@ -89,7 +89,7 @@
         domainname = "%s\%s" % (userdomain, username) if userdomain else username
         cmd = r'cacls %s /E /G "%s":F' % (short_home, domainname)
         subprocess.check_output(cmd, stderr=subprocess.STDOUT)  # Ignoring any returned output, quiet
-    except (subprocess.CalledProcessError, EnvironmentError):
+    except (subprocess.CalledProcessError, EnvironmentError, KeyError):
         # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.
         pass

{"golden_diff": "diff --git a/conans/util/windows.py b/conans/util/windows.py\n--- a/conans/util/windows.py\n+++ b/conans/util/windows.py\n@@ -89,7 +89,7 @@\n         domainname = \"%s\\%s\" % (userdomain, username) if userdomain else username\n         cmd = r'cacls %s /E /G \"%s\":F' % (short_home, domainname)\n         subprocess.check_output(cmd, stderr=subprocess.STDOUT)  # Ignoring any returned output, quiet\n-    except (subprocess.CalledProcessError, EnvironmentError):\n+    except (subprocess.CalledProcessError, EnvironmentError, KeyError):\n         # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.\n         pass\n", "issue": "[bug] crash on Windows when trying to obtain USERNAME from environment\n<!--\r\n  Please don't forget to update the issue title.\r\n  Include all applicable information to help us reproduce your problem.\r\n\r\n  To help us debug your issue please explain:\r\n-->\r\n\r\n### Environment Details (include every applicable attribute)\r\n  * Operating System+version: Windows 11\r\n  * Compiler+version: N/A\r\n  * Conan version: 1.48\r\n  * Python version: 3.10.4\r\n\r\n### Steps to reproduce (Include if Applicable)\r\nPowershell in which `USERNAME` is not set as a variable\r\n\r\n```powershell\r\ngit clone https://github.com/ultimaker/libarcus.git\r\ncd libarcus\r\ngit checkout CURA-9177_fix_CI_CT\r\nconan create . arcus/5.0.0-PullRequest0137.67@ultimaker/testing -pr:b cura_build.jinja -pr:h cura_release.jinja --build=missing\r\n```\r\n\r\n### Logs (Executed commands with output) (Include/Attach if Applicable)\r\n\r\nTraceback\r\n```shell\r\nTraceback (most recent call last):\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\command.py\", line 2238, in run\r\n    method(args[0][1:])\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\command.py\", line 382, in create\r\n    info = self._conan.create(args.path, name=name, version=version, user=user,\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\conan_api.py\", line 93, in wrapper\r\n    return f(api, *args, **kwargs)\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\conan_api.py\", line 388, in create\r\n    deps_install(app=app,\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\manager.py\", line 58, in deps_install\r\n    deps_graph = graph_manager.load_graph(ref_or_path, create_reference, graph_info, build_modes,\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_manager.py\", line 127, in load_graph\r\n    deps_graph = self._resolve_graph(root_node, profile_host, profile_build, graph_lock,\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_manager.py\", line 289, in _resolve_graph\r\n    deps_graph = self._load_graph(root_node, check_updates, update,\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_manager.py\", line 410, in _load_graph\r\n    self._recurse_build_requires(graph, builder, check_updates, update, build_mode,\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_manager.py\", line 336, in _recurse_build_requires\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_manager.py\", line 410, in _load_graph\r\n    self._recurse_build_requires(graph, builder, check_updates, update, build_mode,\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_manager.py\", line 336, in _recurse_build_requires\r\n    self._binary_analyzer.evaluate_graph(graph, build_mode, update, remotes, nodes_subset, root)\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_binaries.py\", line 431, in evaluate_graph\r\n    self._evaluate_node(node, build_mode, update, remotes)\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_binaries.py\", line 202, in _evaluate_node\r\n    self._process_node(node, pref, build_mode, update, remotes)\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\client\\graph\\graph_binaries.py\", line 275, in _process_node\r\n    if package_layout.package_id_exists(pref.id) and pref.id in metadata.packages:\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\paths\\package_layouts\\package_cache_layout.py\", line 133, in package_id_exists\r\n    pkg_folder = self.package(PackageReference(self._ref, package_id))\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\paths\\package_layouts\\package_cache_layout.py\", line 32, in wrap\r\n    return path_shortener(p, self._short_paths)\r\n  File \"C:\\Users\\********\\AppData\\Roaming\\Python\\Python310\\site-packages\\conans\\util\\windows.py\", line 88, in path_shortener\r\n    userdomain, username = os.getenv(\"USERDOMAIN\"), os.environ[\"USERNAME\"]\r\n  File \"C:\\Program Files\\Python310\\lib\\os.py\", line 679, in __getitem__\r\n    raise KeyError(key) from None\r\nKeyError: 'USERNAME'\r\n\r\nERROR: 'USERNAME'\r\n```\r\n\r\nEnvironmental variables\r\n```powershell\r\nPS C:\\dev\\libarcus> gci env:* | sort-object name\r\n\r\nName                           Value\r\n----                           -----                                                                                                                                                                                                                                                                                                                                                                                                 \r\n__INTELLIJ_COMMAND_HISTFILE__  C:\\Users\\********\\AppData\\Local\\JetBrains\\CLion2022.1\\terminal\\history\\libarcus-history                                                                                                                                                                                                                                                                                                              \r\nALLUSERSPROFILE                C:\\ProgramData                                                                                                                                                                                                                                                                                                                                                                                        \r\nAPPDATA                        C:\\Users\\********\\AppData\\Roaming                                                                                                                                                                                                                                                                                                                                                                    \r\nCommonProgramFiles             C:\\Program Files\\Common Files                                                                                                                                                                                                                                                                                                                                                                         \r\nCommonProgramFiles(x86)        C:\\Program Files (x86)\\Common Files                                                                                                                                                                                                                                                                                                                                                                   \r\nCommonProgramW6432             C:\\Program Files\\Common Files                                                                                                                                                                                                                                                                                                                                                                         \r\nCOMPUTERNAME                   ********                                                                                                                                                                                                                                                                                                                                                                                              \r\nComSpec                        C:\\windows\\system32\\cmd.exe                                                                                                                                                                                                                                                                                                                                                                           \r\nDriverData                     C:\\Windows\\System32\\Drivers\\DriverData                                                                                                                                                                                                                                                                                                                                                                \r\nFPS_BROWSER_APP_PROFILE_STRING Internet Explorer                                                                                                                                                                                                                                                                                                                                                                                     \r\nFPS_BROWSER_USER_PROFILE_ST... Default                                                                                                                                                                                                                                                                                                                                                                                               \r\nHOMEDRIVE                      C:                                                                                                                                                                                                                                                                                                                                                                                                    \r\nHOMEPATH                       \\Users\\********\r\nIDEA_INITIAL_DIRECTORY         C:\\\r\nJAVA_HOME                      C:\\Program Files\\Amazon Corretto\\jre8\r\nLOCALAPPDATA                   C:\\Users\\********\\AppData\\Local\r\nLOGONSERVER                    \\\\********\r\nNUMBER_OF_PROCESSORS           12\r\nOneDrive                       C:\\Users\\********\\OneDrive - ***********\r\nOneDriveCommercial             C:\\Users\\********\\OneDrive - ***********\r\nOS                             Windows_NT\r\nPath                           C:\\Program Files\\Python310\\Scripts\\;C:\\Program Files\\Python310\\;C:\\windows\\system32;C:\\windows;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\windows\\System32\\OpenSSH\\;C:\\windows\\system32\\config\\systemprofile\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\Amazon Corretto\\jre8\\bin;C:\\Program Files\\Git\\cmd;C:\\Program Files\\dotnet\\;C:\\Users\\********\\AppDat... \r\nPATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW;.CPL\r\nPROCESSOR_ARCHITECTURE         AMD64\r\nPROCESSOR_IDENTIFIER           Intel64 Family 6 Model 165 Stepping 2, GenuineIntel\r\nPROCESSOR_LEVEL                6\r\nPROCESSOR_REVISION             a502\r\nProgramData                    C:\\ProgramData\r\nProgramFiles                   C:\\Program Files\r\nProgramFiles(x86)              C:\\Program Files (x86)\r\nProgramW6432                   C:\\Program Files\r\nPSModulePath                   C:\\Users\\********\\OneDrive - ***********\\Documents\\WindowsPowerShell\\Modules;C:\\Program Files\\WindowsPowerShell\\Modules;C:\\windows\\system32\\WindowsPow\r\nSESSIONNAME                    Console\r\nSystemDrive                    C:\r\nSystemRoot                     C:\\windows\r\nTEMP                           C:\\Users\\JC9C9~1.SPI\\AppData\\Local\\Temp\r\nTERM_SESSION_ID                d1e664b1-b85c-49eb-85d8-be45055fdd9c\r\nTERMINAL_EMULATOR              JetBrains-JediTerm\r\nTMP                            C:\\Users\\JC9C9~1.SPI\\AppData\\Local\\Temp\r\nUSERDOMAIN_ROAMINGPROFILE      ********\r\nUSERPROFILE                    C:\\Users\\********\r\nwindir                         C:\\windows\r\n\r\n```\n", "before_files": [{"content": "import os\nimport subprocess\nimport tempfile\n\nfrom conans.client.tools.oss import OSInfo\nfrom conans.errors import ConanException\nfrom conans.util.env_reader import get_env\nfrom conans.util.files import decode_text\nfrom conans.util.files import load, mkdir, rmdir, save\nfrom conans.util.log import logger\nfrom conans.util.sha import sha256\n\nCONAN_LINK = \".conan_link\"\nCONAN_REAL_PATH = \"real_path.txt\"\n\n\ndef conan_expand_user(path):\n    \"\"\" wrapper to the original expanduser function, to workaround python returning\n    verbatim %USERPROFILE% when some other app (git for windows) sets HOME envvar\n    \"\"\"\n    if path[:1] != '~':\n        return path\n    # In win these variables should exist and point to user directory, which\n    # must exist. Using context to avoid permanent modification of os.environ\n    old_env = dict(os.environ)\n    try:\n        home = os.environ.get(\"HOME\")\n        # Problematic cases of wrong HOME variable\n        # - HOME = %USERPROFILE% verbatim, as messed by some other tools\n        # - MSYS console, that defines a different user home in /c/mingw/msys/users/xxx\n        # In these cases, it is safe to remove it and rely on USERPROFILE directly\n        if home and (not os.path.exists(home) or\n                     (os.getenv(\"MSYSTEM\") and os.getenv(\"USERPROFILE\"))):\n            del os.environ[\"HOME\"]\n        result = os.path.expanduser(path)\n    finally:\n        os.environ.clear()\n        os.environ.update(old_env)\n    return result\n\n\ndef path_shortener(path, short_paths):\n    \"\"\" short_paths is 4-state:\n    False: Never shorten the path\n    True: Always shorten the path, create link if not existing\n    None: Use shorten path only if already exists, not create\n    \"\"\"\n    use_always_short_paths = get_env(\"CONAN_USE_ALWAYS_SHORT_PATHS\", False)\n    short_paths = use_always_short_paths or short_paths\n\n    if short_paths is False or os.getenv(\"CONAN_USER_HOME_SHORT\") == \"None\":\n        return path\n    link = os.path.join(path, CONAN_LINK)\n    if os.path.exists(link):\n        return load(link)\n    elif short_paths is None:\n        return path\n\n    if os.path.exists(path):\n        rmdir(path)\n\n    short_home = os.getenv(\"CONAN_USER_HOME_SHORT\")\n    if not short_home:\n        if OSInfo().is_cygwin:\n            try:\n                cmd = ['cygpath', path, '--unix']\n                out, _ = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False).communicate()\n                out = decode_text(out)\n                if out.startswith('/cygdrive/'):  # It was a Windows 'path'\n                    _, _, drive, _ = out.split('/', 3)\n                    short_home = os.path.join('/cygdrive', drive, '.conan')\n                else:  # It was a cygwin path, use a path inside the user home\n                    short_home = os.path.join(os.path.expanduser(\"~\"), '.conan_short')\n            except Exception:\n                raise ConanException(\"Conan failed to create the short_paths home for path '{}'\"\n                                     \" in Cygwin. Please report this issue. You can use environment\"\n                                     \" variable 'CONAN_USER_HOME_SHORT' to set the short_paths\"\n                                     \" home.\".format(path))\n        else:\n            drive = os.path.splitdrive(path)[0]\n            short_home = os.path.join(drive, os.sep, \".conan\")\n    mkdir(short_home)\n\n    # Workaround for short_home living in NTFS file systems. Give full control permission\n    # to current user to avoid\n    # access problems in cygwin/msys2 windows subsystems when using short_home folder\n    try:\n        userdomain, username = os.getenv(\"USERDOMAIN\"), os.environ[\"USERNAME\"]\n        domainname = \"%s\\%s\" % (userdomain, username) if userdomain else username\n        cmd = r'cacls %s /E /G \"%s\":F' % (short_home, domainname)\n        subprocess.check_output(cmd, stderr=subprocess.STDOUT)  # Ignoring any returned output, quiet\n    except (subprocess.CalledProcessError, EnvironmentError):\n        # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.\n        pass\n\n    redirect = hashed_redirect(short_home, path)\n    if not redirect:\n        logger.warning(\"Failed to create a deterministic short path in %s\", short_home)\n        redirect = tempfile.mkdtemp(dir=short_home, prefix=\"\")\n\n    # Save the full path of the local cache directory where the redirect is from.\n    # This file is for debugging purposes and not used by Conan.\n    save(os.path.join(redirect, CONAN_REAL_PATH), path)\n\n    # This \"1\" is the way to have a non-existing directory, so commands like\n    # shutil.copytree() to it, works. It can be removed without compromising the\n    # temp folder generator and conan-links consistency\n    redirect = os.path.join(redirect, \"1\")\n    save(link, redirect)\n    return redirect\n\n\ndef rm_conandir(path):\n    \"\"\"removal of a directory that might contain a link to a short path\"\"\"\n    link = os.path.join(path, CONAN_LINK)\n    if os.path.exists(link):\n        short_path = load(link)\n        rmdir(os.path.dirname(short_path))\n    rmdir(path)\n\n\ndef hashed_redirect(base, path, min_length=6, attempts=10):\n    max_length = min_length + attempts\n\n    full_hash = sha256(path.encode())\n    assert len(full_hash) > max_length\n\n    for length in range(min_length, max_length):\n        redirect = os.path.join(base, full_hash[:length])\n        if not os.path.exists(redirect):\n            return redirect\n    else:\n        return None\n", "path": "conans/util/windows.py"}], "after_files": [{"content": "import os\nimport subprocess\nimport tempfile\n\nfrom conans.client.tools.oss import OSInfo\nfrom conans.errors import ConanException\nfrom conans.util.env_reader import get_env\nfrom conans.util.files import decode_text\nfrom conans.util.files import load, mkdir, rmdir, save\nfrom conans.util.log import logger\nfrom conans.util.sha import sha256\n\nCONAN_LINK = \".conan_link\"\nCONAN_REAL_PATH = \"real_path.txt\"\n\n\ndef conan_expand_user(path):\n    \"\"\" wrapper to the original expanduser function, to workaround python returning\n    verbatim %USERPROFILE% when some other app (git for windows) sets HOME envvar\n    \"\"\"\n    if path[:1] != '~':\n        return path\n    # In win these variables should exist and point to user directory, which\n    # must exist. Using context to avoid permanent modification of os.environ\n    old_env = dict(os.environ)\n    try:\n        home = os.environ.get(\"HOME\")\n        # Problematic cases of wrong HOME variable\n        # - HOME = %USERPROFILE% verbatim, as messed by some other tools\n        # - MSYS console, that defines a different user home in /c/mingw/msys/users/xxx\n        # In these cases, it is safe to remove it and rely on USERPROFILE directly\n        if home and (not os.path.exists(home) or\n                     (os.getenv(\"MSYSTEM\") and os.getenv(\"USERPROFILE\"))):\n            del os.environ[\"HOME\"]\n        result = os.path.expanduser(path)\n    finally:\n        os.environ.clear()\n        os.environ.update(old_env)\n    return result\n\n\ndef path_shortener(path, short_paths):\n    \"\"\" short_paths is 4-state:\n    False: Never shorten the path\n    True: Always shorten the path, create link if not existing\n    None: Use shorten path only if already exists, not create\n    \"\"\"\n    use_always_short_paths = get_env(\"CONAN_USE_ALWAYS_SHORT_PATHS\", False)\n    short_paths = use_always_short_paths or short_paths\n\n    if short_paths is False or os.getenv(\"CONAN_USER_HOME_SHORT\") == \"None\":\n        return path\n    link = os.path.join(path, CONAN_LINK)\n    if os.path.exists(link):\n        return load(link)\n    elif short_paths is None:\n        return path\n\n    if os.path.exists(path):\n        rmdir(path)\n\n    short_home = os.getenv(\"CONAN_USER_HOME_SHORT\")\n    if not short_home:\n        if OSInfo().is_cygwin:\n            try:\n                cmd = ['cygpath', path, '--unix']\n                out, _ = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False).communicate()\n                out = decode_text(out)\n                if out.startswith('/cygdrive/'):  # It was a Windows 'path'\n                    _, _, drive, _ = out.split('/', 3)\n                    short_home = os.path.join('/cygdrive', drive, '.conan')\n                else:  # It was a cygwin path, use a path inside the user home\n                    short_home = os.path.join(os.path.expanduser(\"~\"), '.conan_short')\n            except Exception:\n                raise ConanException(\"Conan failed to create the short_paths home for path '{}'\"\n                                     \" in Cygwin. Please report this issue. You can use environment\"\n                                     \" variable 'CONAN_USER_HOME_SHORT' to set the short_paths\"\n                                     \" home.\".format(path))\n        else:\n            drive = os.path.splitdrive(path)[0]\n            short_home = os.path.join(drive, os.sep, \".conan\")\n    mkdir(short_home)\n\n    # Workaround for short_home living in NTFS file systems. Give full control permission\n    # to current user to avoid\n    # access problems in cygwin/msys2 windows subsystems when using short_home folder\n    try:\n        userdomain, username = os.getenv(\"USERDOMAIN\"), os.environ[\"USERNAME\"]\n        domainname = \"%s\\%s\" % (userdomain, username) if userdomain else username\n        cmd = r'cacls %s /E /G \"%s\":F' % (short_home, domainname)\n        subprocess.check_output(cmd, stderr=subprocess.STDOUT)  # Ignoring any returned output, quiet\n    except (subprocess.CalledProcessError, EnvironmentError, KeyError):\n        # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.\n        pass\n\n    redirect = hashed_redirect(short_home, path)\n    if not redirect:\n        logger.warning(\"Failed to create a deterministic short path in %s\", short_home)\n        redirect = tempfile.mkdtemp(dir=short_home, prefix=\"\")\n\n    # Save the full path of the local cache directory where the redirect is from.\n    # This file is for debugging purposes and not used by Conan.\n    save(os.path.join(redirect, CONAN_REAL_PATH), path)\n\n    # This \"1\" is the way to have a non-existing directory, so commands like\n    # shutil.copytree() to it, works. It can be removed without compromising the\n    # temp folder generator and conan-links consistency\n    redirect = os.path.join(redirect, \"1\")\n    save(link, redirect)\n    return redirect\n\n\ndef rm_conandir(path):\n    \"\"\"removal of a directory that might contain a link to a short path\"\"\"\n    link = os.path.join(path, CONAN_LINK)\n    if os.path.exists(link):\n        short_path = load(link)\n        rmdir(os.path.dirname(short_path))\n    rmdir(path)\n\n\ndef hashed_redirect(base, path, min_length=6, attempts=10):\n    max_length = min_length + attempts\n\n    full_hash = sha256(path.encode())\n    assert len(full_hash) > max_length\n\n    for length in range(min_length, max_length):\n        redirect = os.path.join(base, full_hash[:length])\n        if not os.path.exists(redirect):\n            return redirect\n    else:\n        return None\n", "path": "conans/util/windows.py"}]}