From 814162f1e1f96802072264c42f59036a2a57b8e5 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Sat, 21 Jul 2018 05:22:28 -0400 Subject: [PATCH] Revert "check if daemon is already installed before installing again" --- .gitignore | 5 +- build/downloadDaemon.js | 104 ++++++++++++++++------------------------ 2 files changed, 42 insertions(+), 67 deletions(-) diff --git a/.gitignore b/.gitignore index 420cf5a97..661998b1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ /node_modules /dist -/static/daemon/lbrynet-daemon* +/static/daemon/lbrynet* /static/locales yarn-error.log package-lock.json -.idea/ -/build/daemon.ver +.idea/ \ No newline at end of file diff --git a/build/downloadDaemon.js b/build/downloadDaemon.js index 691a536aa..11b0b5ba2 100644 --- a/build/downloadDaemon.js +++ b/build/downloadDaemon.js @@ -1,6 +1,6 @@ /* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */ const path = require('path'); -const fs = require('fs'); +const fs = require('fs-path'); const packageJSON = require('../package.json'); const axios = require('axios'); const decompress = require('decompress'); @@ -11,80 +11,56 @@ const downloadDaemon = targetPlatform => new Promise((resolve, reject) => { const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate; const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion; - const daemonDir = path.join(__dirname,'..',packageJSON.lbrySettings.lbrynetDaemonDir); - let daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName; + const daemonDir = packageJSON.lbrySettings.lbrynetDaemonDir; + const daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName; let currentPlatform = os.platform(); if (currentPlatform === 'darwin') currentPlatform = 'macos'; - if (currentPlatform === 'win32') { - currentPlatform = 'windows'; - daemonFileName = daemonFileName + '.exe'; - } + if (currentPlatform === 'win32') currentPlatform = 'windows'; - const daemonFilePath = path.join(daemonDir, daemonFileName); - const daemonVersionPath = path.join(__dirname, 'daemon.ver'); const daemonPlatform = targetPlatform || currentPlatform; - const tmpZipPath = path.join(__dirname, '../','dist','daemon.zip'); + const daemonURL = daemonURLTemplate .replace(/DAEMONVER/g, daemonVersion) .replace(/OSNAME/g, daemonPlatform); + const tmpZipPath = 'dist/daemon.zip'; - - // If a daemon and daemon.ver exists, check to see if it matches the current daemon version - const hasDaemonDownloaded = fs.existsSync(daemonFilePath); - const hasDaemonVersion = fs.existsSync(daemonVersionPath); - let downloadedDaemonVersion; - if (hasDaemonVersion) { - downloadedDaemonVersion = fs.readFileSync(daemonVersionPath, "utf8"); - } - - if (hasDaemonDownloaded && hasDaemonVersion && downloadedDaemonVersion === daemonVersion) { - console.log('\x1b[34minfo\x1b[0m Daemon already downloaded'); - resolve('Done'); - return; - } else { - console.log('\x1b[34minfo\x1b[0m Downloading daemon...'); - axios - .request({ - responseType: 'arraybuffer', - url: daemonURL, - method: 'get', - headers: { - 'Content-Type': 'application/zip', - }, - }) - .then( - result => - new Promise((newResolve, newReject) => { - fs.writeFile(tmpZipPath, result.data, error => { - - if (error) return newReject(error); - return newResolve(); - }); - }) - ) - .then(() => del(`${daemonFilePath}*`)) - .then(() => decompress(tmpZipPath, daemonDir, { + console.log('\x1b[34minfo\x1b[0m Downloading daemon...'); + axios + .request({ + responseType: 'arraybuffer', + url: daemonURL, + method: 'get', + headers: { + 'Content-Type': 'application/zip', + }, + }) + .then( + result => + new Promise((newResolve, newReject) => { + fs.writeFile(tmpZipPath, result.data, error => { + if (error) return newReject(error); + return newResolve(); + }); + }) + ) + .then(() => del(`${daemonDir}/${daemonFileName}*`)) + .then(() => + decompress(tmpZipPath, daemonDir, { filter: file => - path.basename(file.path) === daemonFileName, - })) - .then(() => del(`${tmpZipPath }*`)) - .then(() => { - console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!'); - if (hasDaemonVersion) { - del(daemonVersionPath); - } - - fs.writeFileSync(daemonVersionPath, daemonVersion, "utf8") - resolve('Done'); + path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName, }) - .catch(error => { - console.error( - `\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m` - ); - reject(error); - }); - } + ) + .then(() => { + console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!'); + resolve(true); + }) + .catch(error => { + console.error( + `\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m` + ); + reject(error); + }); }); module.exports = downloadDaemon;