Backwards compatibility fix for Lucid
authorMichele Tartara <mtartara@google.com>
Mon, 8 Apr 2013 09:15:30 +0000 (09:15 +0000)
committerMichele Tartara <mtartara@google.com>
Mon, 8 Apr 2013 09:25:19 +0000 (11:25 +0200)
The code introduced by the previous commit triggered a possible library
conflict in Ubuntu Lucid.

This patch introduces an equivalent but more widely acceptable version of
the same code.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

src/Ganeti/JQueue.hs

index e439aa2..828e662 100644 (file)
@@ -230,9 +230,24 @@ determineJobDirectories rootdir archived = do
              else return []
   return $ rootdir:other
 
+-- Function equivalent to the \'sequence\' function, that cannot be used because
+-- of library version conflict on Lucid.
+-- FIXME: delete this and just use \'sequence\' instead when Lucid compatibility
+-- will not be required anymore.
+sequencer :: [Either IOError [JobId]] -> Either IOError [[JobId]]
+sequencer l = fmap reverse $ foldl seqFolder (Right []) l
+
+-- | Folding function for joining multiple [JobIds] into one list.
+seqFolder :: Either IOError [[JobId]]
+          -> Either IOError [JobId]
+          -> Either IOError [[JobId]]
+seqFolder (Left e) _ = Left e
+seqFolder (Right _) (Left e) = Left e
+seqFolder (Right l) (Right el) = Right $ el:l
+
 -- | Computes the list of all jobs in the given directories.
 getJobIDs :: [FilePath] -> IO (Either IOError [JobId])
-getJobIDs paths = liftM (fmap concat . sequence) (mapM getDirJobIDs paths)
+getJobIDs paths = liftM (fmap concat . sequencer) (mapM getDirJobIDs paths)
 
 -- | Sorts the a list of job IDs.
 sortJobIDs :: [JobId] -> [JobId]