From 83c33e903fd28a5441a5dc494f48167c5fea1a8c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 12 Mar 2017 15:33:04 -0700 Subject: delete the log file if nothing gets written to it --- Main.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index cdc7c4b..bcab3da 100644 --- a/Main.hs +++ b/Main.hs @@ -29,8 +29,8 @@ import Data.Time.Clock.POSIX (getPOSIXTime, posixSecondsToUTCTime) import Data.Time.Format (defaultTimeLocale, formatTime, iso8601DateFormat) import Lens.Micro ((^.)) -import System.Directory (getHomeDirectory, renamePath, - withCurrentDirectory) +import System.Directory (getHomeDirectory, removeFile, + renamePath, withCurrentDirectory) import System.Exit (ExitCode (..)) import System.FilePath ((<.>), ()) import System.IO (IOMode (WriteMode), hClose, openFile, @@ -89,6 +89,9 @@ processScanSessDir st dir = withCurrentDirectory dir $ do } hClose outH hClose logH + -- clean up the log file if it's empty + finalLog <- readFile (logFile stamp) + when (null finalLog) $ removeFile (logFile stamp) where logFile stamp = (st^.stOutdir) stamp <.> "log" outFile stamp = (st^.stOutdir) stamp <.> outExt -- cgit v1.2.3