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.
This commit is contained in:
Chaitanya 2019-08-09 19:26:27 +05:30 committed by Nick Craig-Wood
parent 33677ff367
commit 873e87fc38

View file

@ -70,6 +70,13 @@ 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 //checkRelease is a helper function to download and setup latest release of rclone-webui-react
func checkRelease(shouldUpdate bool) (err error) { func checkRelease(shouldUpdate bool) (err error) {
cachePath := filepath.Join(config.CacheDir, "webgui")
extractPath := filepath.Join(cachePath, "current")
oldUpdateExists := exists(extractPath)
// 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 // Get the latest release details
WebUIURL, tag, size, err := getLatestReleaseURL() WebUIURL, tag, size, err := getLatestReleaseURL()
if err != nil { if err != nil {
@ -77,22 +84,20 @@ func checkRelease(shouldUpdate bool) (err error) {
} }
zipName := tag + ".zip" zipName := tag + ".zip"
cachePath := filepath.Join(config.CacheDir, "webgui")
zipPath := filepath.Join(cachePath, zipName) zipPath := filepath.Join(cachePath, zipName)
extractPath := filepath.Join(cachePath, "current")
if !exists(cachePath) { if !exists(cachePath) {
if err := os.MkdirAll(cachePath, 0755); err != nil { if err := os.MkdirAll(cachePath, 0755); err != nil {
fs.Logf(nil, "Error creating cache directory: %s", cachePath) fs.Logf(nil, "Error creating cache directory: %s", cachePath)
return err
} }
} }
// Load the file
exists := exists(zipPath)
// if the zipFile does not exist or forced update is enforced.
if !exists || shouldUpdate {
fs.Logf(nil, "A new release for gui is present at "+WebUIURL) 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) 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 { if err != nil {
return err return err
} }