aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-03-12 15:33:04 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-03-12 15:33:04 -0700
commit83c33e903fd28a5441a5dc494f48167c5fea1a8c (patch)
tree20dd6156ac4e72b0d4035b03c8dae4e71671f5c3
parent74818cabff85d368761ee1f5a5ea55f3174eafc6 (diff)
downloadsscan-83c33e903fd28a5441a5dc494f48167c5fea1a8c.tar.gz
delete the log file if nothing gets written to it
-rw-r--r--Main.hs7
1 files 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