packages feed

dropsolve 0.1 → 0.1.1

raw patch · 2 files changed

+22/−14 lines, 2 files

Files

dropsolve.cabal view
@@ -1,5 +1,5 @@ Name:          dropsolve-Version:       0.1+Version:       0.1.1 License:       BSD3 License-file:  LICENSE Author:        Daniel Trstenjak
dropsolve.hs view
@@ -10,7 +10,7 @@ import System.Exit import Data.Time.Clock import Data.Time.Calendar-import Data.List (isInfixOf, isSuffixOf, concat)+import Data.List (isInfixOf, isSuffixOf, isPrefixOf, concat) import Data.Char (intToDigit, digitToInt, isDigit, toUpper) import Text.Regex.Posix ((=~)) import Control.Monad (when, mapM_, filterM)@@ -83,7 +83,7 @@ 	 let confs = filter (isConfFile fn) entries 	 mapM (\e -> return $ d </> e) confs 	 where-	    isConfFile file = \e -> file `isInfixOf` e && hasConflict e+	    isConfFile file = \e -> file `isPrefixOf` e && hasConflict e        resolveConflict confInfo confFiles 	 | length confFiles == 0 = return ()@@ -117,12 +117,13 @@ 		| isDigit c && digitToInt c <= numConfs -> takeFile (digitToInt c) confInfo confFiles 		| otherwise                             -> askAgain 	 where-	    moveToTrash file = do-	       trashDir <- trashDirectory-	       createDirectoryIfMissing True trashDir-               let (dir, fileName) = splitFileName file-	       copyFile file (trashDir </> fileName) -	       removeFile file+	    moveToTrash file =+	       errorsToStderr $ do +		  trashDir <- trashDirectory+		  createDirectoryIfMissing True trashDir+		  let (dir, fileName) = splitFileName file+		  copyFile file (trashDir </> fileName) +		  removeFile file  	    takeFile num confInfo confFiles = do                (year, month, day) <- getCurrentDate@@ -130,10 +131,11 @@                    file       = confFiles !! idx 		   origFile   = dir confInfo </> fileName confInfo 		   origBackup = origFile ++ "_backup_" ++ show year ++ "-" ++ show month ++ "-" ++ show day-	       copyFile origFile origBackup-	       moveToTrash origBackup-	       copyFile file origFile-	       mapM_ (\c -> moveToTrash c) confFiles+	       errorsToStderr $ do+		  copyFile origFile origBackup+	          moveToTrash origBackup+	          copyFile file origFile+	          mapM_ (\c -> moveToTrash c) confFiles  	    showDiff file1 file2 = do 	       putStrLn ""@@ -164,9 +166,14 @@    entries <- getDirectoryContents dir    filterM notDots entries    where-      notDots entry = return . not $ "." `isSuffixOf` entry || ".." `isSuffixOf` entry+      notDots entry = return . not $ "." == entry || ".." == entry  +errorsToStderr :: IO () -> IO ()+errorsToStderr action =+   catch action (\e -> hPutStrLn stderr ("\ndropsolve: " ++ show e))++ appDirectory   = getAppUserDataDirectory "dropsolve" trashDirectory = appDirectory >>= \d -> return $ d </> "trash"  @@ -175,6 +182,7 @@ getCurrentDate :: IO (Integer,Int,Int) -- :: (year,month,day) getCurrentDate = getCurrentTime >>= return . toGregorian . utctDay +getEnvOrDefault :: String -> String -> IO String getEnvOrDefault envVar defaultValue = do    result <- try $ getEnv envVar    case result of