Revision a39cd547 src/Ganeti/Utils.hs

b/src/Ganeti/Utils.hs
56 56
  , exitIfEmpty
57 57
  , splitEithers
58 58
  , recombineEithers
59
  , setOwnerAndGroupFromNames
59 60
  ) where
60 61

  
61 62
import Data.Char (toUpper, isAlphaNum, isDigit, isSpace)
62 63
import Data.Function (on)
63 64
import Data.List
65
import qualified Data.Map as M
64 66
import Control.Monad (foldM)
65 67

  
66 68
import Debug.Trace
67 69

  
68 70
import Ganeti.BasicTypes
69 71
import qualified Ganeti.Constants as C
72
import Ganeti.Runtime
70 73
import System.IO
71 74
import System.Exit
75
import System.Posix.Files
72 76
import System.Time
73 77

  
74 78
-- * Debug functions
......
431 435
          recombiner (_,  ls, rs) t = Bad $ "Inconsistent trail log: l=" ++
432 436
                                      show ls ++ ", r=" ++ show rs ++ ",t=" ++
433 437
                                      show t
438

  
439
-- | Set the owner and the group of a file (given as names, not numeric id).
440
setOwnerAndGroupFromNames :: FilePath -> GanetiDaemon -> GanetiGroup -> IO ()
441
setOwnerAndGroupFromNames filename daemon dGroup = do
442
  -- TODO: it would be nice to rework this (or getEnts) so that runtimeEnts
443
  -- is read only once per daemon startup, and then cached for further usage.
444
  runtimeEnts <- getEnts
445
  ents <- exitIfBad "Can't find required user/groups" runtimeEnts
446
  -- note: we use directly ! as lookup failures shouldn't happen, due
447
  -- to the map construction
448
  let uid = fst ents M.! daemon
449
  let gid = snd ents M.! dGroup
450
  setOwnerAndGroup filename uid gid

Also available in: Unified diff