[rhel6-branch] Copy firmware updates to rootPath (#1043372)
Brian C. Lane
bcl at redhat.com
Tue Dec 17 22:58:42 UTC 2013
From: "Brian C. Lane" <bcl at redhat.com>
This moves copytree from livecd to iutil so that copyFirmware can use it
to copy the whole DD_FIRMWARE tree over to /lib/firmware/
Resolves: rhbz#1043372
---
backend.py | 16 +++++++++-------
iutil.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
livecd.py | 64 +-------------------------------------------------------------
3 files changed, 72 insertions(+), 70 deletions(-)
diff --git a/backend.py b/backend.py
index 55ebff4..7b73c71 100644
--- a/backend.py
+++ b/backend.py
@@ -72,13 +72,15 @@ class AnacondaBackend:
self.initLog(anaconda.id, anaconda.rootPath)
def copyFirmware(self, anaconda):
- # Multiple driver disks may be loaded, so we need to glob for all
- # the firmware files in the common DD firmware directory
- for f in glob.glob(DD_FIRMWARE+"/*"):
- try:
- shutil.copyfile(f, "%s/lib/firmware/" % anaconda.rootPath)
- except IOError, e:
- log.error("Could not copy firmware file %s: %s" % (f, e.strerror))
+ if not os.path.isdir(DD_FIRMWARE):
+ return
+
+ # Multiple driver disks may be loaded, and there may also be
+ # firmware updates, so recursively copy the firmware directory over
+ try:
+ iutil.copytree(DD_FIRMWARE, anaconda.rootPath+"/lib/firmware/")
+ except iutil.Error, e:
+ log.errors("Error copying %s: %s" % (DD_FIRMWARE, e.strerror))
def doPostInstall(self, anaconda):
diff --git a/iutil.py b/iutil.py
index f837f7a..53473df 100644
--- a/iutil.py
+++ b/iutil.py
@@ -32,6 +32,7 @@ from flags import flags
from constants import *
import re
import threading
+import selinux
import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
@@ -991,3 +992,64 @@ def lsmod():
with open("/proc/modules") as f:
lines = f.readlines()
return [l.split()[0] for l in lines]
+
+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)
+ if not os.path.isdir(dst):
+ os.makedirs(dst)
+ errors = []
+ for name in names:
+ srcname = os.path.join(src, name)
+ dstname = os.path.join(dst, name)
+ try:
+ if symlinks and os.path.islink(srcname):
+ linkto = os.readlink(srcname)
+ os.symlink(linkto, dstname)
+ if preserveSelinux:
+ trySetfilecon(srcname, dstname)
+ elif os.path.isdir(srcname):
+ copytree(srcname, dstname, symlinks, preserveOwner, preserveSelinux)
+ else:
+ shutil.copyfile(srcname, dstname)
+ if preserveOwner:
+ tryChown(srcname, dstname)
+
+ if preserveSelinux:
+ trySetfilecon(srcname, dstname)
+
+ shutil.copystat(srcname, dstname)
+ except (IOError, os.error), why:
+ errors.append((srcname, dstname, str(why)))
+ # catch the Error from the recursive copytree so that we can
+ # continue with other files
+ except Error, err:
+ errors.extend(err.args[0])
+ try:
+ if preserveOwner:
+ tryChown(src, dst)
+ if preserveSelinux:
+ trySetfilecon(src, dst)
+
+ shutil.copystat(src, dst)
+ except OSError as e:
+ errors.extend((src, dst, e.strerror))
+ if errors:
+ raise Error, errors
diff --git a/livecd.py b/livecd.py
index fd1ff48..340bcce 100644
--- a/livecd.py
+++ b/livecd.py
@@ -31,8 +31,6 @@ import time
import subprocess
import storage
-import selinux
-
from flags import flags
from constants import *
@@ -48,66 +46,6 @@ import packages
import logging
log = logging.getLogger("anaconda")
-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)
- if not os.path.isdir(dst):
- os.makedirs(dst)
- errors = []
- for name in names:
- srcname = os.path.join(src, name)
- dstname = os.path.join(dst, name)
- try:
- if symlinks and os.path.islink(srcname):
- linkto = os.readlink(srcname)
- os.symlink(linkto, dstname)
- if preserveSelinux:
- trySetfilecon(srcname, dstname)
- elif os.path.isdir(srcname):
- copytree(srcname, dstname, symlinks, preserveOwner, preserveSelinux)
- else:
- shutil.copyfile(srcname, dstname)
- if preserveOwner:
- tryChown(srcname, dstname)
-
- if preserveSelinux:
- trySetfilecon(srcname, dstname)
-
- shutil.copystat(srcname, dstname)
- except (IOError, os.error), why:
- errors.append((srcname, dstname, str(why)))
- # catch the Error from the recursive copytree so that we can
- # continue with other files
- except Error, err:
- errors.extend(err.args[0])
- try:
- if preserveOwner:
- tryChown(src, dst)
- if preserveSelinux:
- trySetfilecon(src, dst)
-
- shutil.copystat(src, dst)
- except OSError as e:
- errors.extend((src, dst, e.strerror))
- if errors:
- raise Error, errors
-
class LiveCDCopyBackend(backend.AnacondaBackend):
def __init__(self, anaconda):
backend.AnacondaBackend.__init__(self, anaconda)
@@ -304,7 +242,7 @@ class LiveCDCopyBackend(backend.AnacondaBackend):
# nothing to move
continue
- copytree("%s/%s" % (anaconda.rootPath, tocopy),
+ iutil.copytree("%s/%s" % (anaconda.rootPath, tocopy),
"%s/mnt/%s" % (anaconda.rootPath, tocopy),
True, True, flags.selinux)
wait.refresh()
--
1.8.3.1
More information about the anaconda-patches
mailing list