From 49d85c6def6426a64b2ae516af80609cd17af317 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 30 Aug 2023 09:17:28 +0200 Subject: [PATCH] backup-upload: revert changes, add comment with warning Turned out that using `/file/add ...` introduced a regression. Accessing (reading and writing) file contents is limited to 4095 bytes. This limitation does not exist for `:execute script=... file=...`, so keep the old code. Also add a comment with warning. --- backup-upload.rsc | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/backup-upload.rsc b/backup-upload.rsc index ec76385..7d4b1d1 100644 --- a/backup-upload.rsc +++ b/backup-upload.rsc @@ -100,30 +100,22 @@ $WaitFullyConnected; # global-config-overlay :if ($BackupSendGlobalConfig = true) do={ - :local Config [ /system/script/get global-config-overlay source ]; - :local Size [ :len $Config ]; + # Do *NOT* use '/file/add ...' here, as it is limited to 4095 bytes! + :execute script={ :put [ /system/script/get global-config-overlay source ]; } \ + file=($FilePath . ".conf"); + $WaitForFile ($FilePath . ".conf.txt"); - :if ($Size <= 4095) { - /file/add name=($FilePath . ".conf") contents=$Config; - $WaitForFile ($FilePath . ".conf"); - - :do { - /tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".conf") \ - user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".conf"); - :set ConfigFile ($FileName . ".conf"); - } on-error={ - $LogPrintExit2 error $0 ("Uploading global-config-overlay failed!") false; - :set ConfigFile "failed"; - :set Failed 1; - } - - /file/remove ($FilePath . ".conf"); - } else={ - $LogPrintExit2 warning $0 ("Creating config file not possible. Limit is 4kB, configuration has " . \ - $Size . " bytes.") false; + :do { + /tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".conf") \ + user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".conf.txt"); + :set ConfigFile ($FileName . ".conf"); + } on-error={ + $LogPrintExit2 error $0 ("Uploading global-config-overlay failed!") false; :set ConfigFile "failed"; :set Failed 1; } + + /file/remove ($FilePath . ".conf.txt"); } $SendNotification2 ({ origin=$0; \