From 68074988352a31caa0ccc09fe9106c1a3f7f674f Mon Sep 17 00:00:00 2001 From: David Boucha Date: Thu, 9 Jan 2014 19:18:41 +0000 Subject: [PATCH 1/4] don't test umask on windows --- salt/modules/file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/file.py b/salt/modules/file.py index 0ff83861eb9a..964ce9fe5af7 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -2676,7 +2676,7 @@ def manage_file(name, # This is a new file, if no mode specified, use the umask to figure # out what mode to use for the new file. - if mode is None: + if mode is None and not salt.utils.is_windows(): # Get current umask mask = os.umask(0) os.umask(mask) From 17efaafa54889f4c9564b9c32a6b7c9010b0e9fe Mon Sep 17 00:00:00 2001 From: David Boucha Date: Thu, 9 Jan 2014 19:19:26 +0000 Subject: [PATCH 2/4] Don't chown on windows --- salt/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/utils/__init__.py b/salt/utils/__init__.py index 885afbc598f5..141c49ccb531 100644 --- a/salt/utils/__init__.py +++ b/salt/utils/__init__.py @@ -647,7 +647,7 @@ def copyfile(source, dest, backup_mode='', cachedir=''): except OSError: fstat = None shutil.move(tgt, dest) - if fstat is not None: + if fstat is not None and not salt.utils.is_windows(): os.chown(dest, fstat.st_uid, fstat.st_gid) os.chmod(dest, fstat.st_mode) # If SELINUX is available run a restorecon on the file From aff3a2883261811ed5034a0eae9bbe92dc1b23f0 Mon Sep 17 00:00:00 2001 From: David Boucha Date: Thu, 9 Jan 2014 19:22:44 +0000 Subject: [PATCH 3/4] add noop set_mode for Windows --- salt/modules/win_file.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/salt/modules/win_file.py b/salt/modules/win_file.py index 6c0f8c115919..1c9377a8f889 100644 --- a/salt/modules/win_file.py +++ b/salt/modules/win_file.py @@ -200,7 +200,7 @@ def get_mode(path): ''' Return the mode of a file - Right now we're just returning 777 + Right now we're just returning None because Windows' doesn't have a mode like Linux @@ -212,8 +212,7 @@ def get_mode(path): ''' if not os.path.exists(path): return -1 - mode = 777 - return mode + return None def get_user(path): @@ -460,3 +459,19 @@ def set_attributes(path, archive=None, hidden=None, normal=None, else: intAttributes &= 0xFEFF return win32file.SetFileAttributes(path, intAttributes) + + +def set_mode(path, mode): + ''' + Set the mode of a file + + This just calls get_mode, which returns None because we don't use mode on + Windows + + CLI Example: + + .. code-block:: bash + + salt '*' file.set_mode /etc/passwd 0644 + ''' + return get_mode(path) From bf517b234ac00251c32c015d3e5756ddcac4141e Mon Sep 17 00:00:00 2001 From: David Boucha Date: Thu, 9 Jan 2014 20:14:21 +0000 Subject: [PATCH 4/4] Don't try fstat if on Windows --- salt/utils/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/salt/utils/__init__.py b/salt/utils/__init__.py index 141c49ccb531..7bebf597548e 100644 --- a/salt/utils/__init__.py +++ b/salt/utils/__init__.py @@ -642,12 +642,14 @@ def copyfile(source, dest, backup_mode='', cachedir=''): pass # Get current file stats to they can be replicated after the new file is # moved to the destination path. - try: - fstat = os.stat(dest) - except OSError: - fstat = None + fstat = None + if not salt.utils.is_windows(): + try: + fstat = os.stat(dest) + except OSError: + pass shutil.move(tgt, dest) - if fstat is not None and not salt.utils.is_windows(): + if fstat is not None: os.chown(dest, fstat.st_uid, fstat.st_gid) os.chmod(dest, fstat.st_mode) # If SELINUX is available run a restorecon on the file