From 2d4517c34285e5052e4668b21b4f54c46b9e2f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 16 Jul 2020 18:37:39 +0200 Subject: [PATCH] update script: Use symlinks rather than copies for 'latest' and 'nightly' --- update | 56 +++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/update b/update index a2c054d8b..2a4d0b636 100755 --- a/update +++ b/update @@ -8,8 +8,28 @@ const semver = require('semver') const ethUtil = require('ethereumjs-util') const swarmhash = require('swarmhash') -// This script updates the index files list.js and list.txt in the bin directory, -// as well as the soljson-latest.js files. +// This script updates the index files list.js and list.txt in the directories containing binaries, +// as well as the 'latest' and 'nightly' symlinks. + +function updateSymlink (linkPathRelativeToRoot, targetRelativeToLink) { + const absoluteLinkPath = path.join(__dirname, linkPathRelativeToRoot) + + fs.readlink(absoluteLinkPath, (err, linkString) => { + if (err && err.code !== 'ENOENT') { + throw err + } + + if (!err && targetRelativeToLink !== linkString) { + fs.unlinkSync(absoluteLinkPath) + console.log('Removed link ' + linkPathRelativeToRoot + ' -> ' + linkString) + } + + if (err || targetRelativeToLink !== linkString) { + fs.symlinkSync(targetRelativeToLink, absoluteLinkPath, 'file') + console.log('Created link ' + linkPathRelativeToRoot + ' -> ' + targetRelativeToLink) + } + }) +} var dirs = ['/bin', '/wasm'] dirs.forEach(function (dir) { @@ -117,36 +137,10 @@ dirs.forEach(function (dir) { console.log('Updated ' + dir + '/list.js') }) + // Update symlinks if (dir === '/bin') { - // Read latest release file - fs.readFile(path.join(__dirname, dir, latestReleaseFile), function (err, data) { - if (err) { - throw err - } - - // Copy to bin/soljson-latest.js - fs.writeFile(path.join(__dirname, dir, '/soljson-latest.js'), data, function (err) { - if (err) { - throw err - } - console.log('Updated ' + dir + '/soljson-latest.js') - }) - }) - - // Read latest build file - fs.readFile(path.join(__dirname, dir, latestBuildFile), function (err, data) { - if (err) { - throw err - } - - // Copy to bin/soljson-nightly.js - fs.writeFile(path.join(__dirname, dir, '/soljson-nightly.js'), data, function (err) { - if (err) { - throw err - } - console.log('Updated ' + dir + '/soljson-nightly.js') - }) - }) + updateSymlink(path.join(dir, 'soljson-latest.js'), latestReleaseFile) + updateSymlink(path.join(dir, 'soljson-nightly.js'), latestBuildFile) } }) })