3508 zone install should utilize/populate global zone d/l cache
authorDan Price <dp@eng.sun.com>
Mon, 29 Sep 2008 19:09:08 -0700
changeset 554 fe196874250d
parent 553 c01d93bb1659
child 555 87c86da72fd9
3508 zone install should utilize/populate global zone d/l cache 2279 client output oddities since caching changes
src/brand/clone
src/brand/pkgcreatezone
src/brand/poststate
src/brand/prestate
src/brand/query
src/brand/uninstall
src/modules/client/filelist.py
src/modules/client/image.py
src/modules/client/progress.py
--- a/src/brand/pkgcreatezone	Mon Sep 29 14:57:23 2008 -0700
+++ b/src/brand/pkgcreatezone	Mon Sep 29 19:09:08 2008 -0700
@@ -31,6 +31,7 @@
 f_interrupted=$(gettext "Installation cancelled due to interrupt.")
 
 m_authority=$(gettext   "  Authority: Using %s.")
+m_cache=$(gettext   "      Cache: Using %s.")
 m_image=$(gettext     "      Image: Preparing at %s ...")
 m_core=$(gettext      " Installing: (output follows)\n")
 m_smf=$(gettext	      "Postinstall: Copying SMF seed repository ...")
@@ -125,6 +126,11 @@
 
 PKG_IMAGE="$zoneroot"
 export PKG_IMAGE
+if [ -d /var/pkg/download ]; then
+	PKG_CACHEDIR=/var/pkg/download
+	export PKG_CACHEDIR
+	printf "$m_cache\n" $PKG_CACHEDIR
+fi
 
 printf "$m_core\n"
 pkg install -q $entire_fmri || fail_incomplete "$f_pkg"
--- a/src/modules/client/filelist.py	Mon Sep 29 14:57:23 2008 -0700
+++ b/src/modules/client/filelist.py	Mon Sep 29 19:09:08 2008 -0700
@@ -128,9 +128,7 @@
                                 bytes = get_pkg_otw_size(action)
 
                                 self._verify_content(action, cache_path)
-
-                                self.progtrack.download_adjust_goal(0, -1,
-                                    -bytes)
+                                self.progtrack.download_add_progress(1, bytes)
 
                                 return
                 except InvalidContentException:
--- a/src/modules/client/image.py	Mon Sep 29 14:57:23 2008 -0700
+++ b/src/modules/client/image.py	Mon Sep 29 19:09:08 2008 -0700
@@ -189,6 +189,9 @@
                 self.catalogs = {}
                 self._catalog = {}
                 self.pkg_states = None
+                self.dl_cache_dir = None
+                self.dl_cache_incoming = None
+                self.is_user_cache_dir = False
 
                 self.attrs = {}
 
@@ -222,11 +225,7 @@
                             check_subdirs(d, img_user_prefix):
                                 # XXX Look at image file to determine filter
                                 # tags and repo URIs.
-                                self.type = IMG_USER
-                                self.root = d
-                                self.img_prefix = img_user_prefix
-                                self.imgdir = os.path.join(d, self.img_prefix)
-                                self.history.root_dir = self.imgdir
+                                self.__set_dirs(imgtype=IMG_USER, root=d)
                                 self.attrs["Build-Release"] = "5.11"
                                 return
                         elif os.path.isdir(os.path.join(d, img_root_prefix)) \
@@ -237,11 +236,7 @@
                                 # tags and repo URIs.
                                 # XXX Look at image file to determine if this
                                 # image is a partial image.
-                                self.type = IMG_ENTIRE
-                                self.root = d
-                                self.img_prefix = img_root_prefix
-                                self.imgdir = os.path.join(d, self.img_prefix)
-                                self.history.root_dir = self.imgdir
+                                self.__set_dirs(imgtype=IMG_ENTIRE, root=d)
                                 self.attrs["Build-Release"] = "5.11"
                                 return
 
@@ -283,9 +278,8 @@
                         if not os.path.isdir(os.path.join(self.imgdir, sd)):
                                 os.makedirs(os.path.join(self.imgdir, sd))
 
-        def set_attrs(self, type, root, is_zone, auth_name, auth_url,
-            ssl_key = None, ssl_cert = None):
-                self.type = type
+        def __set_dirs(self, imgtype, root):
+                self.type = imgtype
                 self.root = root
                 if self.type == IMG_USER:
                         self.img_prefix = img_user_prefix
@@ -294,6 +288,20 @@
                 self.imgdir = os.path.join(self.root, self.img_prefix)
                 self.history.root_dir = self.imgdir
 
+                if "PKG_CACHEDIR" in os.environ:
+                        self.dl_cache_dir = os.path.normpath( \
+                            os.environ["PKG_CACHEDIR"])
+                        self.is_user_cache_dir = True
+                else:
+                        self.dl_cache_dir = os.path.normpath( \
+                            os.path.join(self.imgdir, "download"))
+                self.dl_cache_incoming = os.path.normpath(os.path.join(
+                    self.dl_cache_dir, "incoming-%d" % os.getpid()))
+
+        def set_attrs(self, type, root, is_zone, auth_name, auth_url,
+            ssl_key = None, ssl_cert = None):
+                self.__set_dirs(imgtype=type, root=root)
+
                 if not os.path.exists(os.path.join(self.imgdir, "cfg_cache")):
                         self.history.operation_name = "image-create"
                 else:
@@ -1900,29 +1908,30 @@
                 successfully downloaded, it is moved to the cached download
                 directory."""
 
-                return os.path.normpath(os.path.join(self.imgdir, "download",
-                    "incoming-%d" % os.getpid()))
+                return self.dl_cache_incoming
 
         def cached_download_dir(self):
                 """Return the directory path for cached content.
                 Files that have been successfully downloaded live here."""
 
-                return os.path.normpath(os.path.join(self.imgdir, "download"))
+                return self.dl_cache_dir
 
         def cleanup_downloads(self):
                 """Clean up any downloads that were in progress but that
                 did not successfully finish."""
 
-                shutil.rmtree(self.incoming_download_dir(), True)
+                shutil.rmtree(self.dl_cache_incoming, True)
 
         def cleanup_cached_content(self):
                 """Delete the directory that stores all of our cached
                 downloaded content.  This may take a while for a large
-                directory hierarchy."""
+                directory hierarchy.  Don't clean up caches if the
+                user overrode the underlying setting using PKG_CACHEDIR. """
 
-                if self.cfg_cache.get_policy(imageconfig.FLUSH_CONTENT_CACHE):
+                if not self.is_user_cache_dir and \
+                    self.cfg_cache.get_policy(imageconfig.FLUSH_CONTENT_CACHE):
                         msg("Deleting content cache")
-                        shutil.rmtree(self.cached_download_dir(), True)
+                        shutil.rmtree(self.dl_cache_dir, True)
 
         def salvagedir(self, path):
                 """Called when directory contains something and it's not supposed
--- a/src/modules/client/progress.py	Mon Sep 29 14:57:23 2008 -0700
+++ b/src/modules/client/progress.py	Mon Sep 29 19:09:08 2008 -0700
@@ -110,15 +110,6 @@
                 self.dl_goal_nfiles = nfiles
                 self.dl_goal_nbytes = nbytes
 
-        def download_adjust_goal(self, npkgs, nfiles, nbytes):
-                self.dl_goal_npkgs += npkgs
-                self.dl_goal_nfiles += nfiles
-                self.dl_goal_nbytes += nbytes
-
-                assert self.dl_goal_npkgs >= 0
-                assert self.dl_goal_nfiles >= 0
-                assert self.dl_goal_nbytes >= 0
-
         def download_start_pkg(self, pkgname):
                 self.dl_cur_pkg = pkgname
                 if self.dl_goal_nbytes != 0: