diff --git a/.gitignore b/.gitignore index 8ae1c65..5d4ac9f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ *.session.sql tests/tmp dist-newstyle/ + +src/tor diff --git a/src/Simplex/Messaging/Server/CLI.hs b/src/Simplex/Messaging/Server/CLI.hs index bfa0952..8ae5616 100644 --- a/src/Simplex/Messaging/Server/CLI.hs +++ b/src/Simplex/Messaging/Server/CLI.hs @@ -23,7 +23,8 @@ import Simplex.Messaging.Encoding.String import Simplex.Messaging.Transport (ATransport (..), TLS, Transport (..)) import Simplex.Messaging.Transport.Server (loadFingerprint) import Simplex.Messaging.Transport.WebSockets (WS) -import System.Directory (createDirectoryIfMissing, doesDirectoryExist, doesFileExist, removeDirectoryRecursive) +import Simplex.Messaging.Util (whenM) +import System.Directory (createDirectoryIfMissing, doesDirectoryExist, doesFileExist, listDirectory, removeDirectoryRecursive, removePathForcibly) import System.Exit (exitFailure) import System.FilePath (combine) import System.IO (BufferMode (..), IOMode (..), hFlush, hGetLine, hSetBuffering, stderr, stdout, withFile) @@ -147,7 +148,7 @@ cliCommandP ServerCLIConfig {cfgDir, logDir, iniFile} = initializeServer :: ServerCLIConfig cfg -> InitOptions -> IO () initializeServer cliCfg InitOptions {enableStoreLog, signAlgorithm, ip, fqdn} = do - cleanup cliCfg + clearDirs cliCfg createDirectoryIfMissing True cfgDir createDirectoryIfMissing True logDir createX509 @@ -276,7 +277,14 @@ cleanup ServerCLIConfig {cfgDir, logDir} = do deleteDirIfExists cfgDir deleteDirIfExists logDir where - deleteDirIfExists path = doesDirectoryExist path >>= (`when` removeDirectoryRecursive path) + deleteDirIfExists path = whenM (doesDirectoryExist path) $ removeDirectoryRecursive path + +clearDirs :: ServerCLIConfig cfg -> IO () +clearDirs ServerCLIConfig {cfgDir, logDir} = do + clearDirIfExists cfgDir + clearDirIfExists logDir + where + clearDirIfExists path = whenM (doesDirectoryExist path) $ listDirectory path >>= mapM_ (removePathForcibly . combine path) printServiceInfo :: ServerCLIConfig cfg -> ByteString -> IO () printServiceInfo ServerCLIConfig {serverVersion} fpStr = do