From 26b5d395cf63d880512377524577b75769471732 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sat, 23 May 2009 23:47:56 +0100
Subject: [PATCH] Strip the suffix from the names in the objects

This strips the suffix from the objects themselves, not only from the
ktn/kti vars.
---
 Ganeti/HTools/Loader.hs | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs
index 1346867e1..442dbb3a5 100644
--- a/Ganeti/HTools/Loader.hs
+++ b/Ganeti/HTools/Loader.hs
@@ -79,11 +79,9 @@ longestDomain ((_,x):xs) =
                               else accu)
       "" $ filter (isPrefixOf ".") (tails x)
 
--- | Remove tails from the (Int, String) lists
-stripSuffix :: String -> NameList -> NameList
-stripSuffix suffix lst =
-    let sflen = length suffix in
-    map (\ (key, name) -> (key, take ((length name) - sflen) name)) lst
+-- | Remove tail suffix from a string
+stripSuffix :: Int -> String -> String
+stripSuffix sflen name = take ((length name) - sflen) name
 
 {-| Initializer function that loads the data from a node and list file
     and massages it into the correct format. -}
@@ -101,9 +99,12 @@ mergeData (ktn, nl, kti, il) = do
       xtn = swapPairs ktn
       xti = swapPairs kti
       common_suffix = longestDomain (xti ++ xtn)
-      stn = stripSuffix common_suffix xtn
-      sti = stripSuffix common_suffix xti
-  return (nl3, il3, common_suffix, stn, sti)
+      csl = length common_suffix
+      stn = map (\(x, y) -> (x, stripSuffix csl y)) xtn
+      sti = map (\(x, y) -> (x, stripSuffix csl y)) xti
+      snl = Container.map (\n -> setName n (stripSuffix csl $ name n)) nl3
+      sil = Container.map (\i -> setName i (stripSuffix csl $ name i)) il3
+  return (snl, sil, common_suffix, stn, sti)
 
 -- | Check cluster data for consistency
 checkData :: NodeList -> InstanceList -> NameList -> NameList
-- 
GitLab