-- |Writes text lines to a file enclosed in directory, creating the directory if it does not exist.
-- If there are no lines to be written, no action is performed.
-- Parent of a directory is read from 'Options'.
writePortageSetFile :: FilePath -> FilePath -> [Text] -> ReaderT Options IO ()
writePortageSetFile dir file lns = unless (null lns) $ do
    root <- asks _targetDir
    lift $ createDirectoryIfMissing False (root </> dir)
    lift $ writeLines (root </> dir </> file) lns

-- |Writes a 'PortageSetConfig' with specified index to respective files.
-- @package.use@ file is prefixed with an index, since it is sensitive to order.
writePortageSetFile :: FilePath -> FilePath -> [Text] -> ReaderT Options IO ()
writePortageSetFile dir file lns = unless (null lns) $ do
    root <- asks _targetDir
    lift $ createDirectoryIfMissing False (root </> dir)
    lift $ writeLines (root </> dir </> file) lns

-- |Writes a 'PortageSetConfig' with specified index to respective files.
-- @package.use@ file is prefixed with an index, since it is sensitive to order.
writePortageSetFile dir file lns = unless (null lns) $ do
    root <- asks _targetDir
    lift $ createDirectoryIfMissing False (root </> dir)
    lift $ writeLines (root </> dir </> file) lns

-- |Writes a 'PortageSetConfig' with specified index to respective files.
-- @package.use@ file is prefixed with an index, since it is sensitive to order.