minirotate 0.1.2.1 → 0.1.2.2
raw patch · 3 files changed
+24/−8 lines, 3 filesdep +process
Dependencies added: process
Files
- minirotate.cabal +3/−2
- src/Main.hs +13/−6
- src/Options.hs +8/−0
minirotate.cabal view
@@ -1,5 +1,5 @@ name: minirotate-version: 0.1.2.1+version: 0.1.2.2 synopsis: Minimalistic file rotation utility description: minirotate is minimalistic file rotation utility designed for calling from cron or similar tool.@@ -32,4 +32,5 @@ old-locale, safe == 0.2, split == 0.1.2,- mtl >= 1.1.0+ mtl >= 1.1.0,+ process > 1
src/Main.hs view
@@ -6,6 +6,7 @@ import System.Environment import System.IO ( hPutStrLn, stderr ) import System.Exit ( exitFailure )+import System.Process ( runProcess, waitForProcess ) import Data.Accessor import Data.Accessor.Tuple@@ -47,11 +48,13 @@ -copyOpDry :: Bool -> CopyMode -> (FilePath -> FilePath -> IO ())-copyOpDry True Copy = \from to -> logErr (printf "COPY: %s -> %s" from to)-copyOpDry True Move = \from to -> logErr (printf "MOVE: %s -> %s" from to)-copyOpDry False Copy = copyFile-copyOpDry False Move = renameFile+copyOpDry :: (Bool,Bool,Bool) -> CopyMode -> (FilePath -> FilePath -> IO ())+copyOpDry (True,_,_) Copy = \from to -> logErr (printf "COPY: %s -> %s" from to)+copyOpDry (True,_,_) Move = \from to -> logErr (printf "MOVE: %s -> %s" from to)+copyOpDry (False,False,_) Copy = copyFile+copyOpDry (False,True,_) Copy = \from to -> (runProcess "cp" [from,to] Nothing Nothing Nothing Nothing Nothing >>= waitForProcess >> return ())+copyOpDry (False,_,False) Move = renameFile+copyOpDry (False,_,True) Move = \from to -> (runProcess "mv" [from,to] Nothing Nothing Nothing Nothing Nothing >>= waitForProcess >> return ()) removeFileDry True fn = logErr (printf "REMOVE: %s" fn) removeFileDry False fn = removeFile fn@@ -72,7 +75,11 @@ -- | oneLocation firstLevel? (element type, element name) oneLocation _ (File,fp) = do modTime <- getModificationTime fp- (copyOpDry (get dryRun $ opts) (get copyMode $ opts)) fp (locTo </> (runPattern modTime fp))+ let copyOpts = ((get dryRun $ opts)+ ,(get externalCopy $ opts)+ ,(get externalMove $ opts))++ (copyOpDry copyOpts (get copyMode $ opts)) fp (locTo </> (runPattern modTime fp)) oneLocation True (Dir,fp) = do logErr (printf "Directory %s is a subdirectory at source site. Recursive operation is not supported. Skipping." (show fp))
src/Options.hs view
@@ -20,6 +20,8 @@ , maximumFiles_ :: Int -- ^ maximum # of files , maximumAge_ :: Int -- ^ oldest age allowed (in seconds) , dryRun_ :: Bool -- ^ should we really commit our operations?+ , externalMove_ :: Bool -- ^ use 'mv' command instead of renameFile+ , externalCopy_ :: Bool -- ^ use 'cp' command instead of copyFile } deriving (Read,Show,Eq,Ord) @@ -46,6 +48,8 @@ -- set maximum age to 3 months , maximumAge_ = 3600 {- hour -} * 24 {- day -} * 30 {- month -} * 3 , dryRun_ = False+ , externalMove_ = False+ , externalCopy_ = False } instance Default EnvOptions where@@ -98,6 +102,10 @@ "maximum age of files to keep" , Option [] ["dry-run"] (NoArg (second .> dryRun ^= True)) "don't remove or copy any files"+ , Option [] ["external-move"] (NoArg (second .> externalMove ^= True))+ "use external move impelmentation ('mv' command) instead of System.Directory.renameFile"+ , Option [] ["external-copy"] (NoArg (second .> externalCopy ^= True))+ "use external move impelmentation ('cp' command) instead of System.Directory.copyFile" -- TODO: logger, verbose ]