>From 6b6f23c6e8c29dc3b8952d3f429838302b488c63 Mon Sep 17 00:00:00 2001
From: Konrad Scherer <Konrad.Scherer@windriver.com>
Date: Thu, 20 Jan 2011 15:06:38 -0500
Subject: [PATCH] Fix move of path_tail function to utils


Signed-off-by: Konrad Scherer <Konrad.Scherer@windriver.com>
---
 cobbler/action_import.py                       |   19 ++-----------------
 cobbler/modules/manage_import_debian_ubuntu.py |    6 +++---
 cobbler/modules/manage_import_redhat.py        |    6 +++---
 cobbler/modules/manage_import_vmware.py        |    6 +++---
 cobbler/utils.py                               |    4 ++--
 5 files changed, 13 insertions(+), 28 deletions(-)

diff --git a/cobbler/action_import.py b/cobbler/action_import.py
index 0c552c1..81733a0 100644
--- a/cobbler/action_import.py
+++ b/cobbler/action_import.py
@@ -345,25 +345,10 @@ class Importer:
             # and the input start directory in the crawl.  We find the path segments
             # between and tack them on the network source path to find the explicit
             # network path to the distro that Anaconda can digest.
-            tail = self.path_tail(self.path, base)
+            tail = utils.path_tail(self.path, base, self.mirror)
             tree = self.network_root[:-1] + tail
             importer.set_install_tree( distro, tree)
 
-    # ============================================================================
-
-    def path_tail(self, apath, bpath):
-        """
-        Given two paths (B is longer than A), find the part in B not in A
-        """
-        position = bpath.find(apath)
-        if position != 0:
-            utils.die(self.logger, "- warning: possible symlink traversal?: %s")
-        rposition = position + len(self.mirror)
-        result = bpath[rposition:]
-        if not result.startswith("/"):
-            result = "/" + result
-        return result
-
     # ======================================================================
 
     def repo_finder(self,distros_added):
@@ -717,7 +702,7 @@ class Importer:
         """
 
         if self.network_root is not None:
-            name = self.mirror_name + "-".join(self.path_tail(os.path.dirname(self.path),dirname).split("/"))
+            name = self.mirror_name + "-".join(utils.path_tail(os.path.dirname(self.path),dirname,self.mirror).split("/"))
         else:
             # remove the part that says /var/www/cobbler/ks_mirror/name
             name = "-".join(dirname.split("/")[5:])
diff --git a/cobbler/modules/manage_import_debian_ubuntu.py b/cobbler/modules/manage_import_debian_ubuntu.py
index d085a08..dab8d8a 100644
--- a/cobbler/modules/manage_import_debian_ubuntu.py
+++ b/cobbler/modules/manage_import_debian_ubuntu.py
@@ -315,7 +315,7 @@ class ImportDebianUbuntuManager:
             # and the input start directory in the crawl.  We find the path segments
             # between and tack them on the network source path to find the explicit
             # network path to the distro that Anaconda can digest.
-            tail = self.path_tail(self.path, base)
+            tail = utils.path_tail(self.path, base, self.mirror)
             tree = self.network_root[:-1] + tail
             self.set_install_tree(distro, tree)
 
@@ -478,7 +478,7 @@ class ImportDebianUbuntuManager:
         """
 
         if self.network_root is not None:
-            name = self.mirror_name + "-".join(self.path_tail(os.path.dirname(self.path),dirname).split("/"))
+            name = self.mirror_name + "-".join(utils.path_tail(os.path.dirname(self.path),dirname,self.mirror).split("/"))
         else:
             # remove the part that says /var/www/cobbler/ks_mirror/name
             name = "-".join(dirname.split("/")[5:])
@@ -621,7 +621,7 @@ class ImportDebianUbuntuManager:
             # and the input start directory in the crawl.  We find the path segments
             # between and tack them on the network source path to find the explicit
             # network path to the distro that Anaconda can digest.
-            tail = utils.path_tail(self.path, base)
+            tail = utils.path_tail(self.path, base, self.mirror)
             tree = self.network_root[:-1] + tail
             self.set_install_tree(distro, tree)
 
diff --git a/cobbler/modules/manage_import_redhat.py b/cobbler/modules/manage_import_redhat.py
index 3af67b1..80dbb10 100644
--- a/cobbler/modules/manage_import_redhat.py
+++ b/cobbler/modules/manage_import_redhat.py
@@ -338,7 +338,7 @@ class ImportRedhatManager:
             # and the input start directory in the crawl.  We find the path segments
             # between and tack them on the network source path to find the explicit
             # network path to the distro that Anaconda can digest.
-            tail = self.path_tail(self.path, base)
+            tail = utils.path_tail(self.path, base, self.mirror)
             tree = self.network_root[:-1] + tail
             self.set_install_tree(distro, tree)
 
@@ -648,7 +648,7 @@ class ImportRedhatManager:
         """
 
         if self.network_root is not None:
-            name = self.mirror_name + "-".join(self.path_tail(os.path.dirname(self.path),dirname).split("/"))
+            name = self.mirror_name + "-".join(utils.path_tail(os.path.dirname(self.path),dirname,self.mirror).split("/"))
         else:
             # remove the part that says /var/www/cobbler/ks_mirror/name
             name = "-".join(dirname.split("/")[5:])
@@ -798,7 +798,7 @@ class ImportRedhatManager:
             # and the input start directory in the crawl.  We find the path segments
             # between and tack them on the network source path to find the explicit
             # network path to the distro that Anaconda can digest.
-            tail = utils.path_tail(self.path, base)
+            tail = utils.path_tail(self.path, base, self.mirror)
             tree = self.network_root[:-1] + tail
             self.set_install_tree( distro, tree)
 
diff --git a/cobbler/modules/manage_import_vmware.py b/cobbler/modules/manage_import_vmware.py
index 6a16983..1f63be2 100644
--- a/cobbler/modules/manage_import_vmware.py
+++ b/cobbler/modules/manage_import_vmware.py
@@ -329,7 +329,7 @@ class ImportVMWareManager:
             # and the input start directory in the crawl.  We find the path segments
             # between and tack them on the network source path to find the explicit
             # network path to the distro that Anaconda can digest.
-            tail = self.path_tail(self.path, base)
+            tail = utils.path_tail(self.path, base, self.mirror)
             tree = self.network_root[:-1] + tail
             self.set_install_tree(distro, tree)
 
@@ -591,7 +591,7 @@ class ImportVMWareManager:
         """
 
         if self.network_root is not None:
-            name = self.mirror_name + "-".join(self.path_tail(os.path.dirname(self.path),dirname).split("/"))
+            name = self.mirror_name + "-".join(utils.path_tail(os.path.dirname(self.path),dirname, self.mirror).split("/"))
         else:
             # remove the part that says /var/www/cobbler/ks_mirror/name
             name = "-".join(dirname.split("/")[5:])
@@ -748,7 +748,7 @@ class ImportVMWareManager:
             # and the input start directory in the crawl.  We find the path segments
             # between and tack them on the network source path to find the explicit
             # network path to the distro that Anaconda can digest.
-            tail = utils.path_tail(self.path, base)
+            tail = utils.path_tail(self.path, base, self.mirror)
             tree = self.network_root[:-1] + tail
             self.set_install_tree( distro, tree)
 
diff --git a/cobbler/utils.py b/cobbler/utils.py
index 2787de2..677f570 100644
--- a/cobbler/utils.py
+++ b/cobbler/utils.py
@@ -1272,14 +1272,14 @@ def mkdir(path,mode=0755,logger=None):
                log_exc(logger)
            raise CX(_("Error creating") % path)
 
-def path_tail(apath, bpath):
+def path_tail(apath, bpath, mirror):
     """
     Given two paths (B is longer than A), find the part in B not in A
     """
     position = bpath.find(apath)
     if position != 0:
         die(self.logger, "- warning: possible symlink traversal?: %s")
-    rposition = position + len(self.mirror)
+    rposition = position + len(mirror)
     result = bpath[rposition:]
     if not result.startswith("/"):
         result = "/" + result
-- 
1.7.1

