cleanup zypp credential file to fix conflicts during installing
authorGui Chen <gui.chen@intel.com>
Mon, 21 Jan 2013 07:50:39 +0000 (15:50 +0800)
committerGui Chen <gui.chen@intel.com>
Mon, 21 Jan 2013 17:38:02 +0000 (01:38 +0800)
the issue is zypp will create credential file $instroot/$home/.zypp/*.cat,
and this file only influence rpm downloading, but it cause some conflicts
issue during rpm installing for it is not owned by any package.
in this patch, it will locate the credential file to $instroot/.zypp,
then clean it up before rpm installing.

Change-Id: Ib1409b5aa57547ec8ff96ca39be07bf53894b1bf
Signed-off-by: Gui Chen <gui.chen@intel.com>
plugins/backend/zypppkgmgr.py

index 2aa48e193143282ebbf99b7ec0bdb88f800a9736..28573d7cec0c9352ec407fb3dfa26d4015656ca2 100755 (executable)
@@ -115,6 +115,12 @@ class Zypp(BackendPlugin):
         for f in glob.glob(installroot + "/var/lib/rpm/__db*"):
             os.unlink(f)
 
+    def _cleanupZyppJunk(self, installroot):
+        try:
+            shutil.rmtree(os.path.join(installroot, '.zypp'))
+        except:
+            pass
+
     def setup(self):
         self._cleanupRpmdbLocks(self.instroot)
 
@@ -380,8 +386,18 @@ class Zypp(BackendPlugin):
             if repo.priority:
                 repo_info.setPriority(repo.priority)
 
+            # this hack is used to change zypp credential file location
+            # the default one is $HOME/.zypp, which cause conflicts when
+            # installing some basic packages, and the location doesn't
+            # have any interface actually, so use a tricky way anyway
+            homedir = os.environ['HOME']
+            os.environ['HOME'] = '/'
+
             self.repo_manager.addRepository(repo_info)
 
+            # save back the $HOME env
+            os.environ['HOME'] = homedir
+
             self.__build_repo_cache(name)
 
         except RuntimeError, e:
@@ -732,6 +748,7 @@ class Zypp(BackendPlugin):
 
         # clean rpm lock
         self._cleanupRpmdbLocks(self.instroot)
+        self._cleanupZyppJunk(self.instroot)
         # Set filters
         probfilter = 0
         for flag in self.probFilterFlags: