mirror of
https://github.com/clearlinux/WALinuxAgent.git
synced 2026-08-24 08:07:18 +00:00
check for existence before chmod/chown/chcon (#206)
code review feedback
This commit is contained in:
@@ -194,7 +194,7 @@ class DefaultOSUtil(object):
|
||||
"""
|
||||
path, thumbprint, value = pubkey
|
||||
if path is None:
|
||||
raise OSUtilError("Publich key path is None")
|
||||
raise OSUtilError("Public key path is None")
|
||||
|
||||
crytputil = CryptUtil(conf.get_openssl_cmd())
|
||||
|
||||
@@ -261,6 +261,9 @@ class DefaultOSUtil(object):
|
||||
Returns exit result.
|
||||
"""
|
||||
if self.is_selinux_system():
|
||||
if not os.path.exists(path):
|
||||
logger.error("Path does not exist: {0}".format(path))
|
||||
return 1
|
||||
return shellutil.run('chcon ' + con + ' ' + path)
|
||||
|
||||
def conf_sshd(self, disable_password):
|
||||
|
||||
@@ -91,11 +91,17 @@ def mkdir(dirpath, mode=None, owner=None):
|
||||
chowner(dirpath, owner)
|
||||
|
||||
def chowner(path, owner):
|
||||
owner_info = pwd.getpwnam(owner)
|
||||
os.chown(path, owner_info[2], owner_info[3])
|
||||
if not os.path.exists(path):
|
||||
logger.error("Path does not exist: {0}".format(path))
|
||||
else:
|
||||
owner_info = pwd.getpwnam(owner)
|
||||
os.chown(path, owner_info[2], owner_info[3])
|
||||
|
||||
def chmod(path, mode):
|
||||
os.chmod(path, mode)
|
||||
if not os.path.exists(path):
|
||||
logger.error("Path does not exist: {0}".format(path))
|
||||
else:
|
||||
os.chmod(path, mode)
|
||||
|
||||
def rm_files(*args):
|
||||
for path in args:
|
||||
|
||||
+7
-1
@@ -228,6 +228,9 @@ class AbstractDistro(object):
|
||||
Returns exit result.
|
||||
"""
|
||||
if self.isSelinuxSystem():
|
||||
if not os.path.exists(path):
|
||||
Error("Path does not exist: {0}".format(path))
|
||||
return 1
|
||||
return Run('chcon ' + cn + ' ' + path)
|
||||
|
||||
def setHostname(self,name):
|
||||
@@ -2336,7 +2339,10 @@ def ChangeOwner(filepath, user):
|
||||
except:
|
||||
pass
|
||||
if p != None:
|
||||
os.chown(filepath, p[2], p[3])
|
||||
if not os.path.exists(filepath):
|
||||
Error("Path does not exist: {0}".format(filepath))
|
||||
else:
|
||||
os.chown(filepath, p[2], p[3])
|
||||
|
||||
def CreateDir(dirpath, user, mode):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user