diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2017-03-12 15:33:04 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2017-03-12 15:33:04 -0700 |
commit | 83c33e903fd28a5441a5dc494f48167c5fea1a8c (patch) | |
tree | 20dd6156ac4e72b0d4035b03c8dae4e71671f5c3 | |
parent | 74818cabff85d368761ee1f5a5ea55f3174eafc6 (diff) | |
download | sscan-83c33e903fd28a5441a5dc494f48167c5fea1a8c.tar.gz |
delete the log file if nothing gets written to it
-rw-r--r-- | Main.hs | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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 |