From 873e87fc389487691370197c85fc53853ce87f81 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Fri, 9 Aug 2019 19:26:27 +0530 Subject: [PATCH] rc: WebGUI should check for new update only when rc-web-gui-update is specified or not already downloaded. rc: WebGUI should check for new update only when rc-web-gui-update is specified or not already downloaded. rc: change permission to 0755 instead of 755 to prevent unexpected behaviour. --- cmd/rcd/rcd.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/cmd/rcd/rcd.go b/cmd/rcd/rcd.go index a3213a772..38094cf8a 100644 --- a/cmd/rcd/rcd.go +++ b/cmd/rcd/rcd.go @@ -70,29 +70,34 @@ See the [rc documentation](/rc/) for more info on the rc flags. //checkRelease is a helper function to download and setup latest release of rclone-webui-react func checkRelease(shouldUpdate bool) (err error) { - // Get the latest release details - WebUIURL, tag, size, err := getLatestReleaseURL() - if err != nil { - return err - } - - zipName := tag + ".zip" cachePath := filepath.Join(config.CacheDir, "webgui") - zipPath := filepath.Join(cachePath, zipName) extractPath := filepath.Join(cachePath, "current") + oldUpdateExists := exists(extractPath) - if !exists(cachePath) { - if err := os.MkdirAll(cachePath, 0755); err != nil { - fs.Logf(nil, "Error creating cache directory: %s", cachePath) + // if the old file exists does not exist or forced update is enforced. + // TODO: Add hashing to check integrity of the previous update. + if !oldUpdateExists || shouldUpdate { + // Get the latest release details + WebUIURL, tag, size, err := getLatestReleaseURL() + if err != nil { + return err } - } - // Load the file - exists := exists(zipPath) - // if the zipFile does not exist or forced update is enforced. - if !exists || shouldUpdate { + + zipName := tag + ".zip" + zipPath := filepath.Join(cachePath, zipName) + + if !exists(cachePath) { + if err := os.MkdirAll(cachePath, 0755); err != nil { + fs.Logf(nil, "Error creating cache directory: %s", cachePath) + return err + } + } + fs.Logf(nil, "A new release for gui is present at "+WebUIURL) fs.Logf(nil, "Downloading webgui binary. Please wait. [Size: %s, Path : %s]\n", strconv.Itoa(size), zipPath) - err := downloadFile(zipPath, WebUIURL) + + // download the zip from latest url + err = downloadFile(zipPath, WebUIURL) if err != nil { return err }