File fix-salt.utils.stringutils.to_str-calls-to-make-it-w.patch of Package salt

From 2ffc8d790afe1a7b7875ab0d21995ac04f704cf6 Mon Sep 17 00:00:00 2001
From: Victor Zhestkov <vzhestkov@suse.com>
Date: Wed, 25 Nov 2020 14:47:35 +0300
Subject: [PATCH] Fix salt.utils.stringutils.to_str calls to make it
 working with int

---
 salt/modules/file.py | 14 ++++++++++----
 salt/states/file.py  |  9 +++++++--
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/salt/modules/file.py b/salt/modules/file.py
index 0b516aff05..c834adfcde 100644
--- a/salt/modules/file.py
+++ b/salt/modules/file.py
@@ -4567,6 +4567,12 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
     is_dir = os.path.isdir(name)
     is_link = os.path.islink(name)
 
+    def __safe_to_str(s):
+        try:
+            return salt.utils.stringutils.to_str(s)
+        except:
+            return salt.utils.stringutils.to_str(str(s))
+
     # user/group changes if needed, then check if it worked
     if user:
         if isinstance(user, int):
@@ -4574,7 +4580,7 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
         if (salt.utils.platform.is_windows() and
                 user_to_uid(user) != user_to_uid(perms['luser'])
             ) or (
-            not salt.utils.platform.is_windows() and salt.utils.stringutils.to_str(user) != perms['luser']
+            not salt.utils.platform.is_windows() and __safe_to_str(user) != perms['luser']
         ):
             perms['cuser'] = user
 
@@ -4584,7 +4590,7 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
         if (salt.utils.platform.is_windows() and
                 group_to_gid(group) != group_to_gid(perms['lgroup'])
             ) or (
-                not salt.utils.platform.is_windows() and salt.utils.stringutils.to_str(group) != perms['lgroup']
+                not salt.utils.platform.is_windows() and __safe_to_str(group) != perms['lgroup']
         ):
             perms['cgroup'] = group
 
@@ -4615,7 +4621,7 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
                 user != ''
             ) or (
             not salt.utils.platform.is_windows() and
-                salt.utils.stringutils.to_str(user) != get_user(name, follow_symlinks=follow_symlinks) and
+                __safe_to_str(user) != get_user(name, follow_symlinks=follow_symlinks) and
                 user != ''
         ):
             if __opts__['test'] is True:
@@ -4635,7 +4641,7 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
                     get_group(name, follow_symlinks=follow_symlinks)) and
                 group != '') or (
             not salt.utils.platform.is_windows() and
-                salt.utils.stringutils.to_str(group) != get_group(name, follow_symlinks=follow_symlinks) and
+                __safe_to_str(group) != get_group(name, follow_symlinks=follow_symlinks) and
                 group != ''
         ):
             if __opts__['test'] is True:
diff --git a/salt/states/file.py b/salt/states/file.py
index f21e0d12fc..847cbace51 100644
--- a/salt/states/file.py
+++ b/salt/states/file.py
@@ -959,12 +959,17 @@ def _check_dir_meta(name,
     if not stats:
         changes['directory'] = 'new'
         return changes
+    def __safe_to_str(s):
+        try:
+            return salt.utils.stringutils.to_str(s)
+        except:
+            return salt.utils.stringutils.to_str(str(s))
     if (user is not None
-            and salt.utils.stringutils.to_str(user) != stats['user']
+            and __safe_to_str(user) != stats['user']
             and user != stats.get('uid')):
         changes['user'] = user
     if (group is not None
-            and salt.utils.stringutils.to_str(group) != stats['group']
+            and __safe_to_str(group) != stats['group']
             and group != stats.get('gid')):
         changes['group'] = group
     # Normalize the dir mode
-- 
2.29.1
openSUSE Build Service is sponsored by