From f3eeb9dcc2fa71e130cf2181333a349240dfdfb8 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:59:20 +0400 Subject: [PATCH] core: temp-folder option (#3905) --- apps/simplex-broadcast-bot/src/Broadcast/Options.hs | 1 + apps/simplex-directory-service/src/Directory/Options.hs | 1 + src/Simplex/Chat.hs | 4 ++-- src/Simplex/Chat/Mobile.hs | 1 + src/Simplex/Chat/Options.hs | 9 +++++++++ tests/ChatClient.hs | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/simplex-broadcast-bot/src/Broadcast/Options.hs b/apps/simplex-broadcast-bot/src/Broadcast/Options.hs index bce0f94972..57986874aa 100644 --- a/apps/simplex-broadcast-bot/src/Broadcast/Options.hs +++ b/apps/simplex-broadcast-bot/src/Broadcast/Options.hs @@ -80,6 +80,7 @@ mkChatOpts BroadcastBotOpts {coreOptions} = chatCmdLog = CCLNone, chatServerPort = Nothing, optFilesFolder = Nothing, + optTempDirectory = Nothing, showReactions = False, allowInstantFiles = True, autoAcceptFileSize = 0, diff --git a/apps/simplex-directory-service/src/Directory/Options.hs b/apps/simplex-directory-service/src/Directory/Options.hs index 78157d7e11..0d64064d7d 100644 --- a/apps/simplex-directory-service/src/Directory/Options.hs +++ b/apps/simplex-directory-service/src/Directory/Options.hs @@ -80,6 +80,7 @@ mkChatOpts DirectoryOpts {coreOptions} = chatCmdLog = CCLNone, chatServerPort = Nothing, optFilesFolder = Nothing, + optTempDirectory = Nothing, showReactions = False, allowInstantFiles = True, autoAcceptFileSize = 0, diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 3c74f58517..708f5d4353 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -211,7 +211,7 @@ newChatController ChatDatabase {chatStore, agentStore} user cfg@ChatConfig {agentConfig = aCfg, defaultServers, inlineFiles, deviceNameForRemote} - ChatOpts {coreOptions = CoreChatOpts {smpServers, xftpServers, networkConfig, logLevel, logConnections, logServerHosts, logFile, tbqSize, highlyAvailable}, deviceName, optFilesFolder, showReactions, allowInstantFiles, autoAcceptFileSize} + ChatOpts {coreOptions = CoreChatOpts {smpServers, xftpServers, networkConfig, logLevel, logConnections, logServerHosts, logFile, tbqSize, highlyAvailable}, deviceName, optFilesFolder, optTempDirectory, showReactions, allowInstantFiles, autoAcceptFileSize} backgroundMode = do let inlineFiles' = if allowInstantFiles || autoAcceptFileSize > 0 then inlineFiles else inlineFiles {sendChunks = 0, receiveInstant = False} config = cfg {logLevel, showReactions, tbqSize, subscriptionEvents = logConnections, hostEvents = logServerHosts, defaultServers = configServers, inlineFiles = inlineFiles', autoAcceptFileSize, highlyAvailable} @@ -245,7 +245,7 @@ newChatController chatActivated <- newTVarIO True showLiveItems <- newTVarIO False encryptLocalFiles <- newTVarIO False - tempDirectory <- newTVarIO Nothing + tempDirectory <- newTVarIO optTempDirectory contactMergeEnabled <- newTVarIO True pqExperimentalEnabled <- newTVarIO PQSupportOff pure diff --git a/src/Simplex/Chat/Mobile.hs b/src/Simplex/Chat/Mobile.hs index 105dedb32c..5883c6042c 100644 --- a/src/Simplex/Chat/Mobile.hs +++ b/src/Simplex/Chat/Mobile.hs @@ -207,6 +207,7 @@ mobileChatOpts dbFilePrefix = chatCmdLog = CCLNone, chatServerPort = Nothing, optFilesFolder = Nothing, + optTempDirectory = Nothing, showReactions = False, allowInstantFiles = True, autoAcceptFileSize = 0, diff --git a/src/Simplex/Chat/Options.hs b/src/Simplex/Chat/Options.hs index a222e2e77b..871e3358ec 100644 --- a/src/Simplex/Chat/Options.hs +++ b/src/Simplex/Chat/Options.hs @@ -41,6 +41,7 @@ data ChatOpts = ChatOpts chatCmdLog :: ChatCmdLog, chatServerPort :: Maybe String, optFilesFolder :: Maybe FilePath, + optTempDirectory :: Maybe FilePath, showReactions :: Bool, allowInstantFiles :: Bool, autoAcceptFileSize :: Integer, @@ -258,6 +259,13 @@ chatOptsP appDir defaultDbFileName = do <> metavar "FOLDER" <> help "Folder to use for sent and received files" ) + optTempDirectory <- + optional $ + strOption + ( long "temp-folder" + <> metavar "FOLDER" + <> help "Folder for temporary encrypted files (default: system temp directory)" + ) showReactions <- switch ( long "reactions" @@ -304,6 +312,7 @@ chatOptsP appDir defaultDbFileName = do chatCmdLog, chatServerPort, optFilesFolder, + optTempDirectory, showReactions, allowInstantFiles, autoAcceptFileSize, diff --git a/tests/ChatClient.hs b/tests/ChatClient.hs index 792f9642d3..1abf59952a 100644 --- a/tests/ChatClient.hs +++ b/tests/ChatClient.hs @@ -74,6 +74,7 @@ testOpts = chatCmdLog = CCLNone, chatServerPort = Nothing, optFilesFolder = Nothing, + optTempDirectory = Nothing, showReactions = True, allowInstantFiles = True, autoAcceptFileSize = 0,