11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst { spawn } = require('child_process'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst path = require('path'); 71cb0ef41Sopenharmony_ciconst fs = require('fs'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 101cb0ef41Sopenharmony_citmpdir.refresh(); 111cb0ef41Sopenharmony_ciconst tmpDir = tmpdir.path; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst entry = path.join(tmpDir, 'entry.js'); 141cb0ef41Sopenharmony_ciconst real = path.join(tmpDir, 'real.js'); 151cb0ef41Sopenharmony_ciconst link_absolute_path = path.join(tmpDir, 'link.js'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cifs.writeFileSync(entry, ` 181cb0ef41Sopenharmony_ciconst assert = require('assert'); 191cb0ef41Sopenharmony_ciglobal.x = 0; 201cb0ef41Sopenharmony_cirequire('./real.js'); 211cb0ef41Sopenharmony_ciassert.strictEqual(x, 1); 221cb0ef41Sopenharmony_cirequire('./link.js'); 231cb0ef41Sopenharmony_ciassert.strictEqual(x, 2); 241cb0ef41Sopenharmony_ci`); 251cb0ef41Sopenharmony_cifs.writeFileSync(real, 'x++;'); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_citry { 281cb0ef41Sopenharmony_ci fs.symlinkSync(real, link_absolute_path); 291cb0ef41Sopenharmony_ci} catch (err) { 301cb0ef41Sopenharmony_ci if (err.code !== 'EPERM') throw err; 311cb0ef41Sopenharmony_ci common.skip('insufficient privileges for symlinks'); 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cispawn(process.execPath, 351cb0ef41Sopenharmony_ci ['--preserve-symlinks', entry], 361cb0ef41Sopenharmony_ci { stdio: 'inherit' }).on('exit', (code) => { 371cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 381cb0ef41Sopenharmony_ci}); 39