From 8f8aa095966e7b887f5d2b5f25c12e1819f3eec2 Mon Sep 17 00:00:00 2001 From: Thomas Maul Date: Wed, 24 Aug 2022 15:20:47 +0200 Subject: [PATCH] fix error in rclone download. Add tests to run in compiled mode --- .../Sources/Classes/FileTransfer_rclone.4dm | 10 +-- Project/Sources/Methods/test.4dm | 64 +++++++++++++++++++ Project/Sources/Methods/test_curl.4dm | 2 +- Project/Sources/Methods/test_curl_http.4dm | 2 +- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/Project/Sources/Classes/FileTransfer_rclone.4dm b/Project/Sources/Classes/FileTransfer_rclone.4dm index 953e564..c62c075 100644 --- a/Project/Sources/Classes/FileTransfer_rclone.4dm +++ b/Project/Sources/Classes/FileTransfer_rclone.4dm @@ -38,7 +38,7 @@ Function upload($sourcepath : Text; $targetpath : Text)->$success : Object ASSERT:C1129($targetpath#""; "target path must not be empty") $url:="copyto "+This:C1470._wrapLocal($sourcepath)+" "+This:C1470._wrapRemote($targetpath) $success:=This:C1470._runWorker($url) - If (($success.data#"") & ($success.data#"Transferred@")) + If (($success.data#"") & ($success.data="@error@")) $success.success:=False:C215 $success.error:=$success.data End if @@ -46,9 +46,9 @@ Function upload($sourcepath : Text; $targetpath : Text)->$success : Object Function download($sourcepath : Text; $targetpath : Text)->$success : Object ASSERT:C1129($sourcepath#""; "source path must not be empty") ASSERT:C1129($targetpath#""; "target path must not be empty") - $url:="copyto "+This:C1470._wrapRemote($targetpath)+" "+This:C1470._wrapLocal($targetpath) + $url:="copyto "+This:C1470._wrapRemote($sourcepath)+" "+This:C1470._wrapLocal($targetpath) $success:=This:C1470._runWorker($url) - If (($success.data#"") & ($success.data#"Transferred@")) + If (($success.data#"") & ($success.data="@error@")) $success.success:=False:C215 $success.error:=$success.data End if @@ -58,7 +58,7 @@ Function syncUp($sourcepath : Text; $targetpath : Text)->$success : Object ASSERT:C1129($targetpath#""; "target path must not be empty") $url:="sync "+This:C1470._wrapLocal($sourcepath)+" "+This:C1470._wrapRemote($targetpath) $success:=This:C1470._runWorker($url) - If (($success.data#"") & ($success.data#"Transferred@")) + If (($success.data#"") & ($success.data="@error@")) $success.success:=False:C215 $success.error:=$success.data End if @@ -68,7 +68,7 @@ Function syncDown($sourcepath : Text; $targetpath : Text)->$success : Object ASSERT:C1129($targetpath#""; "target path must not be empty") $url:="sync "+This:C1470._wrapRemote($sourcepath)+" "+This:C1470._wrapLocal($targetpath) $success:=This:C1470._runWorker($url) - If (($success.data#"") & ($success.data#"Transferred@")) + If (($success.data#"") & ($success.data="@error@")) $success.success:=False:C215 $success.error:=$success.data End if diff --git a/Project/Sources/Methods/test.4dm b/Project/Sources/Methods/test.4dm index 64fe454..32ac767 100644 --- a/Project/Sources/Methods/test.4dm +++ b/Project/Sources/Methods/test.4dm @@ -1 +1,65 @@ //%attributes = {} +var $ftp : cs:C1710.FileTransfer_curl +$ftp:=cs:C1710.FileTransfer_curl.new("download.4d.com"; ""; ""; "https") + +$progressid:="Download 4D.dmg" +$checkstop:=New shared object:C1526("stop"; False:C215) +$ftp.enableStopButton($checkstop) +$ftp.useCallback(Formula:C1597(ProgressCallback); $progressid) + +$source:="/Products/4D_v19R5/Installers/4D_v19_R5_Mac.dmg" +$target:=System folder:C487(Desktop:K41:16)+"4d.dmg" +$target:=Convert path system to POSIX:C1106($target) +$ftp.setCurlPrefix("--location") // follow 301 or 302 +$result:=$ftp.download($source; $target) + +// did user canceled? +If ($checkstop.stop=True:C214) + // user canceled!! +Else + If ($result.success) + $answer:=$result.data + ALERT:C41("HTTP Download: "+$answer) + End if +End if + + +$ftp:=cs:C1710.FileTransfer_rclone.new("gdrive") +$path:="/users/thomas/Desktop/rclone-v1.59.1-osx-arm64/rclone" +$ftp.setPath($path) +$result:=$ftp.getDirectoryListing("/") +If ($result.success) + $list:=$result.list + $text:=JSON Stringify:C1217($list) + ALERT:C41("drive directory "+$text) + SET TEXT TO PASTEBOARD:C523($text) +Else + ALERT:C41("error") +End if + + +$ftp:=cs:C1710.FileTransfer_rclone.new("gdrive") +$path:="/users/thomas/Desktop/rclone-v1.59.1-osx-arm64/rclone" +$ftp.setPath($path) +$progressid:="Download zipg" +$checkstop:=New shared object:C1526("stop"; False:C215) +$ftp.enableStopButton($checkstop) +$ftp.useCallback(Formula:C1597(ProgressCallback); $progressid) + +$source:="/16-10_CookieBaseWebAuth.zip" +$target:=System folder:C487(Desktop:K41:16)+"test.zip" +$target:=Convert path system to POSIX:C1106($target) +$result:=$ftp.download($source; $target) + +// did user canceled? +If ($checkstop.stop=True:C214) + // user canceled!! +Else + If ($result.success) + $answer:=$result.data + ALERT:C41("gdrive Download: "+$answer) + Else + ALERT:C41("error") + End if + +End if diff --git a/Project/Sources/Methods/test_curl.4dm b/Project/Sources/Methods/test_curl.4dm index 8321093..cbc2745 100644 --- a/Project/Sources/Methods/test_curl.4dm +++ b/Project/Sources/Methods/test_curl.4dm @@ -7,7 +7,7 @@ $credentialspath:=Get 4D folder:C485(Database folder:K5:14) $folder:=Folder:C1567($credentialspath; fk platform path:K87:2) $credentialsfile:=$folder.parent.file("credentials.txt").getText() $credentials:=JSON Parse:C1218($credentialsfile) -If (True:C214) +If (False:C215) $credentials.url:="192.168.10.54:3421" // $credentials.user:="myself" // $credentials.password:="notmypass" diff --git a/Project/Sources/Methods/test_curl_http.4dm b/Project/Sources/Methods/test_curl_http.4dm index a16fc72..b761eec 100644 --- a/Project/Sources/Methods/test_curl_http.4dm +++ b/Project/Sources/Methods/test_curl_http.4dm @@ -54,7 +54,7 @@ If (True:C214) // download with progress, stop button $ftp.enableStopButton($checkstop) $ftp.useCallback(Formula:C1597(ProgressCallback); $progressid) - $source:="/Products/4D_v19R3/Installers/4D_v19_R3_Mac.dmg" + $source:="/Products/4D_v19R5/Installers/4D_v19_R5_Mac.dmg" $target:=System folder:C487(Desktop:K41:16)+"4d.dmg" $target:=Convert path system to POSIX:C1106($target) $ftp.setCurlPrefix("--location") // follow 301 or 302