mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #44995 from twangboy/win_fix_atomicfile
Fix `unit.modules.test_file` for Windows
This commit is contained in:
commit
698b04779e
1 changed files with 9 additions and 2 deletions
|
@ -15,6 +15,9 @@ import random
|
|||
import shutil
|
||||
import salt.ext.six as six
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.win_dacl
|
||||
|
||||
|
||||
CAN_RENAME_OPEN_FILE = False
|
||||
if os.name == 'nt': # pragma: no cover
|
||||
|
@ -120,8 +123,12 @@ class _AtomicWFile(object):
|
|||
self._fh.close()
|
||||
if os.path.isfile(self._filename):
|
||||
shutil.copymode(self._filename, self._tmp_filename)
|
||||
st = os.stat(self._filename)
|
||||
os.chown(self._tmp_filename, st.st_uid, st.st_gid)
|
||||
if salt.utils.win_dacl.HAS_WIN32:
|
||||
owner = salt.utils.win_dacl.get_owner(self._filename)
|
||||
salt.utils.win_dacl.set_owner(self._tmp_filename, owner)
|
||||
else:
|
||||
st = os.stat(self._filename)
|
||||
os.chown(self._tmp_filename, st.st_uid, st.st_gid)
|
||||
atomic_rename(self._tmp_filename, self._filename)
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
|
|
Loading…
Add table
Reference in a new issue