[anaconda][PATCH 2/2] Use a temporary directory for verifying ISO media

Vratislav Podzimek vpodzime at redhat.com
Tue Sep 24 13:48:00 UTC 2013


On Tue, 2013-09-24 at 09:37 -0400, David Shea wrote:
> None of the callers of opticalInstallMedia use the mountpoint parameter,
> so removed it. Changed to using a temporary directory instead of
> /run/install/source to mount and verify potential optical media, since
> /run/install/source may already be in use by media specified in
> inst.repo.
> ---
>  pyanaconda/image.py | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/pyanaconda/image.py b/pyanaconda/image.py
> index 9049be9..82f3e4f 100644
> --- a/pyanaconda/image.py
> +++ b/pyanaconda/image.py
> @@ -18,8 +18,8 @@
>  #
>  
>  import isys
> -import os, os.path, stat
> -from constants import INSTALL_TREE, ISO_DIR
> +import os, os.path, stat, tempfile
> +from constants import ISO_DIR
>  
>  from errors import errorHandler, ERROR_RAISE, InvalidImageSizeError, MediaMountError, MediaUnmountError, MissingImageError
>  
> @@ -185,7 +185,7 @@ def mountImage(isodir, tree):
>  
>  # Return the first Device instance containing valid optical install media
>  # for this product.
> -def opticalInstallMedia(devicetree, mountpoint=INSTALL_TREE):
> +def opticalInstallMedia(devicetree):
>      retval = None
>  
>      # Search for devices identified as cdrom along with any other
> @@ -201,16 +201,21 @@ def opticalInstallMedia(devicetree, mountpoint=INSTALL_TREE):
>              # no mountable media
>              continue
>  
> +        mountpoint = tempfile.mkdtemp()
>          try:
> -            dev.format.mount(mountpoint=mountpoint)
> -        except FSError:
> -            continue
> +            try:
> +                dev.format.mount(mountpoint=mountpoint)
> +            except FSError:
> +                continue
> +
> +            if not verifyMedia(mountpoint):
> +                dev.format.unmount()
> +                continue
>  
> -        if not verifyMedia(mountpoint):
>              dev.format.unmount()
> -            continue
> +        finally:
> +            os.rmdir(mountpoint)
>  
> -        dev.format.unmount()
If verifyMedia returns True, the format won't get umounted and the
finally block will try to remove its contents. Or am I missing
something?

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list