Revision be0cb2d7 src/Ganeti/JQueue.hs

b/src/Ganeti/JQueue.hs
231 231
  return $ rootdir:other
232 232

  
233 233
-- | Computes the list of all jobs in the given directories.
234
getJobIDs :: [FilePath] -> IO [JobId]
235
getJobIDs = liftM concat . mapM getDirJobIDs
234
getJobIDs :: [FilePath] -> IO (Either IOError [JobId])
235
getJobIDs paths = liftM (fmap concat . sequence) (mapM getDirJobIDs paths)
236 236

  
237 237
-- | Sorts the a list of job IDs.
238 238
sortJobIDs :: [JobId] -> [JobId]
239 239
sortJobIDs = sortBy (comparing fromJobId)
240 240

  
241 241
-- | Computes the list of jobs in a given directory.
242
getDirJobIDs :: FilePath -> IO [JobId]
242
getDirJobIDs :: FilePath -> IO (Either IOError [JobId])
243 243
getDirJobIDs path = do
244
  contents <- getDirectoryContents path `Control.Exception.catch`
245
                ignoreIOError [] False
246
                  ("Failed to list job directory " ++ path)
247
  let jids = foldl (\ids file ->
248
                      case parseJobFileId file of
249
                        Nothing -> ids
250
                        Just new_id -> new_id:ids) [] contents
251
  return $ reverse jids
244
  either_contents <-
245
    try (getDirectoryContents path) :: IO (Either IOError [FilePath])
246
  case either_contents of
247
    Left e -> do
248
      logWarning $ "Failed to list job directory " ++ path ++ ": " ++ show e
249
      return $ Left e
250
    Right contents -> do
251
      let jids = foldl (\ids file ->
252
                         case parseJobFileId file of
253
                           Nothing -> ids
254
                           Just new_id -> new_id:ids) [] contents
255
      return . Right $ reverse jids
252 256

  
253 257
-- | Reads the job data from disk.
254 258
readJobDataFromDisk :: FilePath -> Bool -> JobId -> IO (Maybe (String, Bool))

Also available in: Unified diff