diff --git a/src/Simplex/Messaging/Notifications/Server/Main.hs b/src/Simplex/Messaging/Notifications/Server/Main.hs index 0e1b7136c1..bd3eb6580b 100644 --- a/src/Simplex/Messaging/Notifications/Server/Main.hs +++ b/src/Simplex/Messaging/Notifications/Server/Main.hs @@ -50,8 +50,8 @@ ntfServerCLI cfgPath logPath = executableName = "ntf-server" storeLogFilePath = combine logPath "ntf-server-store.log" initializeServer InitOptions {enableStoreLog, signAlgorithm, ip, fqdn} = do - deleteDirIfExists cfgPath - deleteDirIfExists logPath + clearDirIfExists cfgPath + clearDirIfExists logPath createDirectoryIfMissing True cfgPath createDirectoryIfMissing True logPath let x509cfg = defaultX509Config {commonName = fromMaybe ip fqdn, signAlgorithm} diff --git a/src/Simplex/Messaging/Server/CLI.hs b/src/Simplex/Messaging/Server/CLI.hs index 4789c0d8e1..3e597a84d4 100644 --- a/src/Simplex/Messaging/Server/CLI.hs +++ b/src/Simplex/Messaging/Server/CLI.hs @@ -25,7 +25,7 @@ import Simplex.Messaging.Transport (ATransport (..), TLS, Transport (..)) import Simplex.Messaging.Transport.Server (loadFingerprint) import Simplex.Messaging.Transport.WebSockets (WS) import Simplex.Messaging.Util (whenM) -import System.Directory (doesDirectoryExist, removeDirectoryRecursive) +import System.Directory (doesDirectoryExist, listDirectory, removeDirectoryRecursive, removePathForcibly) import System.Exit (exitFailure) import System.FilePath (combine) import System.IO (IOMode (..), hFlush, hGetLine, stdout, withFile) @@ -229,3 +229,6 @@ printServiceInfo serverVersion srv@(ProtoServerWithAuth ProtocolServer {keyHash} putStrLn serverVersion B.putStrLn $ "Fingerprint: " <> strEncode keyHash B.putStrLn $ "Server address: " <> strEncode srv + +clearDirIfExists :: FilePath -> IO () +clearDirIfExists path = whenM (doesDirectoryExist path) $ listDirectory path >>= mapM_ (removePathForcibly . combine path) diff --git a/src/Simplex/Messaging/Server/Main.hs b/src/Simplex/Messaging/Server/Main.hs index 9d791c725e..7697904908 100644 --- a/src/Simplex/Messaging/Server/Main.hs +++ b/src/Simplex/Messaging/Server/Main.hs @@ -79,8 +79,8 @@ smpServerCLI cfgPath logPath = Right auth -> pure . Just $ ServerPassword auth _ -> putStrLn "Invalid password. Only latin letters, digits and symbols other than '@' and ':' are allowed" >> serverPassword initialize InitOptions {enableStoreLog, logStats, signAlgorithm, ip, fqdn, password} = do - deleteDirIfExists cfgPath - deleteDirIfExists logPath + clearDirIfExists cfgPath + clearDirIfExists logPath createDirectoryIfMissing True cfgPath createDirectoryIfMissing True logPath let x509cfg = defaultX509Config {commonName = fromMaybe ip fqdn, signAlgorithm} diff --git a/tests/Test.hs b/tests/Test.hs index 1fb6af7f8b..fbf8a4af6f 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -35,5 +35,5 @@ main = do describe "SMP server via WebSockets" $ serverTests (transport @WS) describe "Notifications server" $ ntfServerTests (transport @TLS) describe "SMP client agent" $ agentTests (transport @TLS) - fdescribe "Server CLIs" cliTests + describe "Server CLIs" cliTests removeDirectoryRecursive "tests/tmp"