summaryrefslogtreecommitdiffstats
path: root/livecd.py
diff options
context:
space:
mode:
authorChris Lumens <clumens@redhat.com>2009-11-18 09:44:28 -0500
committerChris Lumens <clumens@redhat.com>2009-11-18 10:19:58 -0500
commit53e1ecb76d490961702666f97144084716efb385 (patch)
treeec2574f6a69af2054f87a73d9889951746f53506 /livecd.py
parent2d02f9a082845ff9f71414eeca182135dab6327e (diff)
downloadanaconda-53e1ecb76d490961702666f97144084716efb385.tar.gz
anaconda-53e1ecb76d490961702666f97144084716efb385.tar.xz
anaconda-53e1ecb76d490961702666f97144084716efb385.zip
Don't make chown or lsetfilecon errors fatal (#529940).
There's various reasons why these two could fail. For instance, running lsetfilecon on any filesystem that doesn't support it (vfat is the big one, but there are others) would result in a failure. This probably shouldn't take down anaconda.
Diffstat (limited to 'livecd.py')
-rw-r--r--livecd.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/livecd.py b/livecd.py
index 795798c07..aebdd711b 100644
--- a/livecd.py
+++ b/livecd.py
@@ -52,6 +52,18 @@ class Error(EnvironmentError):
pass
def copytree(src, dst, symlinks=False, preserveOwner=False,
preserveSelinux=False):
+ def tryChown(src, dest):
+ try:
+ os.chown(dest, os.stat(src)[stat.ST_UID], os.stat(src)[stat.ST_GID])
+ except OverflowError:
+ log.error("Could not set owner and group on file %s" % dest)
+
+ def trySetfilecon(src, dest):
+ try:
+ selinux.lsetfilecon(dest, selinux.lgetfilecon(src)[1])
+ except:
+ log.error("Could not set selinux context on file %s" % dest)
+
# copy of shutil.copytree which doesn't require dst to not exist
# and which also has options to preserve the owner and selinux contexts
names = os.listdir(src)
@@ -66,19 +78,17 @@ def copytree(src, dst, symlinks=False, preserveOwner=False,
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
if preserveSelinux:
- selinux.lsetfilecon(dstname, selinux.lgetfilecon(srcname)[1])
+ trySetfilecon(srcname, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, symlinks, preserveOwner, preserveSelinux)
else:
shutil.copyfile(srcname, dstname)
if preserveOwner:
- try:
- os.chown(dstname, os.stat(srcname)[stat.ST_UID], os.stat(srcname)[stat.ST_GID])
- except OverflowError:
- log.error("Could not set owner and group on file %s" % dstname)
+ tryChown(srcname, dstname)
if preserveSelinux:
- selinux.lsetfilecon(dstname, selinux.lgetfilecon(srcname)[1])
+ trySetfilecon(srcname, dstname)
+
shutil.copystat(srcname, dstname)
except (IOError, os.error), why:
errors.append((srcname, dstname, str(why)))
@@ -88,9 +98,10 @@ def copytree(src, dst, symlinks=False, preserveOwner=False,
errors.extend(err.args[0])
try:
if preserveOwner:
- os.chown(dst, os.stat(src)[stat.ST_UID], os.stat(src)[stat.ST_GID])
+ tryChown(src, dst)
if preserveSelinux:
- selinux.lsetfilecon(dst, selinux.lgetfilecon(src)[1])
+ trySetfilecon(src, dst)
+
shutil.copystat(src, dst)
except OSError as e:
errors.extend((src, dst, e.strerror))