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) 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) diff --git a/salt/utils/__init__.py b/salt/utils/__init__.py index 885afbc598f5..7bebf597548e 100644 --- a/salt/utils/__init__.py +++ b/salt/utils/__init__.py @@ -642,10 +642,12 @@ 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: os.chown(dest, fstat.st_uid, fstat.st_gid)