Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition in symlink creation in the update script #48

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions update
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ const swarmhash = require('swarmhash')
// This script updates the index files list.js and list.txt in the directories containing binaries,
// as well as the 'latest' and 'nightly' symlinks/files.

function updateSymlink (linkPathRelativeToRoot, targetRelativeToLink) {
function updateSymlinkSync (linkPathRelativeToRoot, targetRelativeToLink) {
const absoluteLinkPath = path.join(__dirname, linkPathRelativeToRoot)
let linkString

fs.readlink(absoluteLinkPath, (err, linkString) => {
if (err && err.code !== 'ENOENT') {
throw err
}
try {
linkString = fs.readlinkSync(absoluteLinkPath)

if (!err && targetRelativeToLink !== linkString) {
if (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)
} catch (err) {
if (err.code !== 'ENOENT') {
throw err
}
})
}

if (targetRelativeToLink !== linkString) {
fs.symlinkSync(targetRelativeToLink, absoluteLinkPath, 'file')
console.log('Created link ' + linkPathRelativeToRoot + ' -> ' + targetRelativeToLink)
}
}

function updateCopy (srcRelativeToRoot, destRelativeToRoot) {
Expand Down Expand Up @@ -192,12 +195,12 @@ function processDir (dir, listCallback) {
if (dir === '/bin') {
updateCopy(path.join(dir, latestReleaseFile), path.join(dir, binaryPrefix + '-latest' + binaryExtension))
} else if (dir !== '/wasm') {
updateSymlink(path.join(dir, binaryPrefix + '-latest' + binaryExtension), latestReleaseFile)
updateSymlinkSync(path.join(dir, binaryPrefix + '-latest' + binaryExtension), latestReleaseFile)
}

// Update 'nightly' symlink in bin/ (we don't have nightlies for other platforms)
if (dir === '/bin') {
updateSymlink(path.join(dir, binaryPrefix + '-nightly' + binaryExtension), latestBuildFile)
updateSymlinkSync(path.join(dir, binaryPrefix + '-nightly' + binaryExtension), latestBuildFile)
}
})
}
Expand All @@ -221,7 +224,7 @@ DIRS.forEach(function (dir) {
// We don't need to do this for emscripten-asmjs/ because we don't build asm.js releases any more.
parsedList.forEach(function (release) {
if (release.prerelease === undefined) {
updateSymlink(
updateSymlinkSync(
path.join('/emscripten-wasm32', 'solc-emscripten-wasm32-v' + release.longVersion + '.js'),
path.join('..', 'wasm', release.path)
)
Expand Down