From a604456d0821ce83094a00cd03ee99f55bb77a40 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 16 Dec 2010 12:46:19 +0100
Subject: [PATCH] Text.hs: change to use sepSplit

The new sepSplit function can split based on empty lines, so we remove
the hackish text splitting from before and simply use sepSplit. This
is needed as the addition of extra sections would have increased the
code linearly, which we don't want :)

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Balazs Lecz <leczb@google.com>
---
 Ganeti/HTools/Text.hs | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/Ganeti/HTools/Text.hs b/Ganeti/HTools/Text.hs
index 11c2770db..bc3e83f54 100644
--- a/Ganeti/HTools/Text.hs
+++ b/Ganeti/HTools/Text.hs
@@ -168,20 +168,17 @@ parseData :: String -- ^ Text data
           -> Result (Group.List, Node.List, Instance.List, [String])
 parseData fdata = do
   let flines = lines fdata
-      (glines, nilines) = break null flines
-      (nlines, ilines) = break null (tail nilines)
-  nfixed <- case nlines of
-    [] -> Bad "Invalid format of the input file (no node data)"
-    xs -> Ok xs
-  ifixed <- case ilines of
-    [] -> Bad "Invalid format of the input file (no instance data)"
-    _:xs -> Ok xs
+  (glines, nlines, ilines) <-
+      case sepSplit "" flines of
+        [a, b, c] -> Ok (a, b, c)
+        xs -> Bad $ printf "Invalid format of the input file: %d sections\
+                           \ instead of 3" (length xs)
   {- group file: name uuid -}
   (ktg, gl) <- loadTabular glines loadGroup
   {- node file: name t_mem n_mem f_mem t_disk f_disk -}
-  (ktn, nl) <- loadTabular nfixed (loadNode ktg)
+  (ktn, nl) <- loadTabular nlines (loadNode ktg)
   {- instance file: name mem disk status pnode snode -}
-  (_, il) <- loadTabular ifixed (loadInst ktn)
+  (_, il) <- loadTabular ilines (loadInst ktn)
   return (gl, nl, il, [])
 
 -- | Top level function for data loading
-- 
GitLab