diff options
Diffstat (limited to 'lib/spack/llnl/util/filesystem.py')
-rw-r--r-- | lib/spack/llnl/util/filesystem.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index be24f9e53f..9ce56d91fa 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -6,6 +6,7 @@ import collections import errno import glob import grp +import ctypes import hashlib import itertools import numbers @@ -44,6 +45,7 @@ __all__ = [ 'fix_darwin_install_name', 'force_remove', 'force_symlink', + 'getuid', 'chgrp', 'chmod_x', 'copy', @@ -60,6 +62,7 @@ __all__ = [ 'remove_directory_contents', 'remove_if_dead_link', 'remove_linked_tree', + 'rename', 'set_executable', 'set_install_permissions', 'touch', @@ -71,6 +74,23 @@ __all__ = [ ] +def getuid(): + if _platform == "win32": + if ctypes.windll.shell32.IsUserAnAdmin() == 0: + return 1 + return 0 + else: + return os.getuid() + + +def rename(src, dst): + # On Windows, os.rename will fail if the destination file already exists + if is_windows: + if os.path.exists(dst): + os.remove(dst) + os.rename(src, dst) + + def path_contains_subdirectory(path, root): norm_root = os.path.abspath(root).rstrip(os.path.sep) + os.path.sep norm_path = os.path.abspath(path).rstrip(os.path.sep) + os.path.sep @@ -293,7 +313,7 @@ def group_ids(uid=None): (list of int): gids of groups the user is a member of """ if uid is None: - uid = os.getuid() + uid = getuid() user = pwd.getpwuid(uid).pw_name return [g.gr_gid for g in grp.getgrall() if user in g.gr_mem] |