mirror of
https://github.com/nodejs/node.git
synced 2025-05-18 11:29:35 +00:00

When running the tests if `NODE_TEST_DIR` is set to a device different than the location of the test files (where this repo is checked out), then the parallel/test-fs-link.js test will fail with `EXDEV: cross-device link not permitted`. The code works fine (and is in fact throwing an error as desired) but the test fails. This commit first creates the "source" file in the same directory as the "destination" (where the hardlink will be created). PR-URL: https://github.com/nodejs/node/pull/4861 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com>
37 lines
748 B
JavaScript
37 lines
748 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
common.refreshTmpDir();
|
|
|
|
// test creating and reading hard link
|
|
const srcPath = path.join(common.tmpDir, 'hardlink-target.txt');
|
|
const dstPath = path.join(common.tmpDir, 'link1.js');
|
|
fs.writeFileSync(srcPath, 'hello world');
|
|
|
|
const callback = function(err) {
|
|
if (err) throw err;
|
|
const dstContent = fs.readFileSync(dstPath, 'utf8');
|
|
assert.strictEqual('hello world', dstContent);
|
|
};
|
|
|
|
fs.link(srcPath, dstPath, common.mustCall(callback));
|
|
|
|
// test error outputs
|
|
|
|
assert.throws(
|
|
function() {
|
|
fs.link();
|
|
},
|
|
/src path/
|
|
);
|
|
|
|
assert.throws(
|
|
function() {
|
|
fs.link('abc');
|
|
},
|
|
/dest path/
|
|
);
|