libselinux: selinuxswig_python.i: don't make syscall if it won't change anything

Add a check to restorecon, to not change a context if the context on disk matches

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
Dan Walsh 2011-11-29 09:44:27 -05:00 committed by Eric Paris
parent 79bcfa7286
commit 7e81db0eb8
1 changed files with 4 additions and 1 deletions

View File

@ -22,7 +22,10 @@ def restorecon(path, recursive=False):
status, context = matchpathcon(path, mode)
if status == 0:
lsetfilecon(path, context)
status, oldcontext = lgetfilecon(path)
if context != oldcontext:
lsetfilecon(path, context)
if recursive:
os.path.walk(path, lambda arg, dirname, fnames:
map(restorecon, [os.path.join(dirname, fname)