Skip to content
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

Fix improper usage of "mode" on windows. ignore mode, plz #9656

Merged
merged 4 commits into from
Jan 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion salt/modules/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 18 additions & 3 deletions salt/modules/win_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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)
10 changes: 6 additions & 4 deletions salt/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down