From cf3d8d0d202caa517fa374582417c6cc015f5aba Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 7 Jan 2021 20:00:12 +1300 Subject: [PATCH] Allow packagers to configure default bookmarks. --- src/Links.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Links.hs b/src/Links.hs index 7914c51..6dd2535 100644 --- a/src/Links.hs +++ b/src/Links.hs @@ -136,7 +136,20 @@ readBookmarks = do dir <- getXdgDirectory XdgData "rhapsode" let file = dir "links.xml" exists <- doesFileExist file - if exists then Text.XML.readFile def file `catch` handleInvalid else nodoc + + if exists then return () else do + -- Copy defaults into userdir + dirs <- getXdgDirectoryList XdgDataDirs + files' <- forM dirs $ \dir' -> do + let file' = dir' "rhapsode" "links.xml" + exists' <- doesFileExist file' + return $ if exists' then Just file' else Nothing + case catMaybes files' of + [] -> return () + (file':_) -> copyFileWithMetadata file' file + + exists' <- doesFileExist file + if exists' then Text.XML.readFile def file `catch` handleInvalid else nodoc where handleInvalid err@(InvalidXMLFile _ _) = hPrint stderr err >> nodoc nodoc = return $ Document (Prologue [] Nothing []) (Element "empty" M.empty []) [] -- 2.30.2