From d54b453b491140ecbdc340c5315415dd8ac03ff3 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Wed, 21 Feb 2024 23:54:03 +0200 Subject: [PATCH] controller: fix standalone using relative paths (#3831) --- src/Simplex/Chat.hs | 5 +++-- tests/ChatTests/Files.hs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 3b0fe7075..c4431ed92 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -2053,8 +2053,9 @@ processChatCommand' vr = \case StopRemoteCtrl -> withUser_ $ stopRemoteCtrl >> ok_ ListRemoteCtrls -> withUser_ $ CRRemoteCtrlList <$> listRemoteCtrls DeleteRemoteCtrl rc -> withUser_ $ deleteRemoteCtrl rc >> ok_ - APIUploadStandaloneFile userId file -> withUserId userId $ \user -> do - fileSize <- liftIO $ CF.getFileContentsSize file + APIUploadStandaloneFile userId file@CryptoFile {filePath} -> withUserId userId $ \user -> do + fsFilePath <- toFSFilePath filePath + fileSize <- liftIO $ CF.getFileContentsSize file {filePath = fsFilePath} (_, _, fileTransferMeta) <- xftpSndFileTransfer_ user file fileSize 1 Nothing pure CRSndStandaloneFileCreated {user, fileTransferMeta} APIDownloadStandaloneFile userId uri file -> withUserId userId $ \user -> do diff --git a/tests/ChatTests/Files.hs b/tests/ChatTests/Files.hs index 7a3536b1e..755e2eb37 100644 --- a/tests/ChatTests/Files.hs +++ b/tests/ChatTests/Files.hs @@ -81,6 +81,7 @@ chatFileTests = do describe "file transfer over XFTP without chat items" $ do it "send and receive small standalone file" testXFTPStandaloneSmall it "send and receive large standalone file" testXFTPStandaloneLarge + it "send and receive large standalone file using relative paths" testXFTPStandaloneRelativePaths xit "removes sent file from server" testXFTPStandaloneCancelSnd -- no error shown in tests it "removes received temporary files" testXFTPStandaloneCancelRcv @@ -1633,6 +1634,37 @@ testXFTPStandaloneCancelSnd = testChat2 aliceProfile aliceDesktopProfile $ \src dst <## "error receiving file 1 (should.not.extist)" dst <## "INTERNAL {internalErr = \"XFTP {xftpErr = AUTH}\"}" +testXFTPStandaloneRelativePaths :: HasCallStack => FilePath -> IO () +testXFTPStandaloneRelativePaths = testChat2 aliceProfile aliceDesktopProfile $ \src dst -> do + withXFTPServer $ do + logNote "sending" + src #$> ("/_files_folder ./tests/tmp/src_files", id, "ok") + src #$> ("/_temp_folder ./tests/tmp/src_xftp_temp", id, "ok") + + xftpCLI ["rand", "./tests/tmp/src_files/testfile.in", "17mb"] `shouldReturn` ["File created: " <> "./tests/tmp/src_files/testfile.in"] + + src ##> "/_upload 1 testfile.in" + src <## "started standalone uploading file 1 (testfile.in)" + -- silent progress events + threadDelay 250000 + src <## "file 1 (testfile.in) uploaded, preparing redirect file 2" + src <## "file 1 (testfile.in) upload complete. download with:" + uri <- getTermLine src + _uri2 <- getTermLine src + _uri3 <- getTermLine src + _uri4 <- getTermLine src + + logNote "receiving" + dst #$> ("/_files_folder ./tests/tmp/dst_files", id, "ok") + dst #$> ("/_temp_folder ./tests/tmp/dst_xftp_temp", id, "ok") + dst ##> ("/_download 1 " <> uri <> " testfile.out") + dst <## "started standalone receiving file 1 (testfile.out)" + -- silent progress events + threadDelay 250000 + dst <## "completed standalone receiving file 1 (testfile.out)" + srcBody <- B.readFile "./tests/tmp/src_files/testfile.in" + B.readFile "./tests/tmp/dst_files/testfile.out" `shouldReturn` srcBody + testXFTPStandaloneCancelRcv :: HasCallStack => FilePath -> IO () testXFTPStandaloneCancelRcv = testChat2 aliceProfile aliceDesktopProfile $ \src dst -> do withXFTPServer $ do