Skip to content

Commit d10fac3

Browse files
authored
Merge pull request #48 from ethereum/fix-update-script-symlink-race-condition
Fix race condition in symlink creation in the update script
2 parents a77a3ce + 7b3b60c commit d10fac3

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Diff for: update

+17-14
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,27 @@ const swarmhash = require('swarmhash')
1111
// This script updates the index files list.js and list.txt in the directories containing binaries,
1212
// as well as the 'latest' and 'nightly' symlinks/files.
1313

14-
function updateSymlink (linkPathRelativeToRoot, targetRelativeToLink) {
14+
function updateSymlinkSync (linkPathRelativeToRoot, targetRelativeToLink) {
1515
const absoluteLinkPath = path.join(__dirname, linkPathRelativeToRoot)
16+
let linkString
1617

17-
fs.readlink(absoluteLinkPath, (err, linkString) => {
18-
if (err && err.code !== 'ENOENT') {
19-
throw err
20-
}
18+
try {
19+
linkString = fs.readlinkSync(absoluteLinkPath)
2120

22-
if (!err && targetRelativeToLink !== linkString) {
21+
if (targetRelativeToLink !== linkString) {
2322
fs.unlinkSync(absoluteLinkPath)
2423
console.log('Removed link ' + linkPathRelativeToRoot + ' -> ' + linkString)
2524
}
26-
27-
if (err || targetRelativeToLink !== linkString) {
28-
fs.symlinkSync(targetRelativeToLink, absoluteLinkPath, 'file')
29-
console.log('Created link ' + linkPathRelativeToRoot + ' -> ' + targetRelativeToLink)
25+
} catch (err) {
26+
if (err.code !== 'ENOENT') {
27+
throw err
3028
}
31-
})
29+
}
30+
31+
if (targetRelativeToLink !== linkString) {
32+
fs.symlinkSync(targetRelativeToLink, absoluteLinkPath, 'file')
33+
console.log('Created link ' + linkPathRelativeToRoot + ' -> ' + targetRelativeToLink)
34+
}
3235
}
3336

3437
function updateCopy (srcRelativeToRoot, destRelativeToRoot) {
@@ -192,12 +195,12 @@ function processDir (dir, listCallback) {
192195
if (dir === '/bin') {
193196
updateCopy(path.join(dir, latestReleaseFile), path.join(dir, binaryPrefix + '-latest' + binaryExtension))
194197
} else if (dir !== '/wasm') {
195-
updateSymlink(path.join(dir, binaryPrefix + '-latest' + binaryExtension), latestReleaseFile)
198+
updateSymlinkSync(path.join(dir, binaryPrefix + '-latest' + binaryExtension), latestReleaseFile)
196199
}
197200

198201
// Update 'nightly' symlink in bin/ (we don't have nightlies for other platforms)
199202
if (dir === '/bin') {
200-
updateSymlink(path.join(dir, binaryPrefix + '-nightly' + binaryExtension), latestBuildFile)
203+
updateSymlinkSync(path.join(dir, binaryPrefix + '-nightly' + binaryExtension), latestBuildFile)
201204
}
202205
})
203206
}
@@ -221,7 +224,7 @@ DIRS.forEach(function (dir) {
221224
// We don't need to do this for emscripten-asmjs/ because we don't build asm.js releases any more.
222225
parsedList.forEach(function (release) {
223226
if (release.prerelease === undefined) {
224-
updateSymlink(
227+
updateSymlinkSync(
225228
path.join('/emscripten-wasm32', 'solc-emscripten-wasm32-v' + release.longVersion + '.js'),
226229
path.join('..', 'wasm', release.path)
227230
)

0 commit comments

Comments
 (0)