2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2017-12-28 23:59:53 +08:00
|
|
|
const common = require('../common');
|
2017-10-06 10:23:44 -07:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-01-13 21:42:45 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
2017-10-06 10:23:44 -07:00
|
|
|
const fn = fixtures.path('non-existent');
|
|
|
|
const existingFile = fixtures.path('exit.js');
|
|
|
|
const existingFile2 = fixtures.path('create-file.js');
|
|
|
|
const existingDir = fixtures.path('empty');
|
|
|
|
const existingDir2 = fixtures.path('keys');
|
2017-12-28 23:59:53 +08:00
|
|
|
const uv = process.binding('uv');
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
// ASYNC_CALL
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.stat(fn, common.mustCall((err) => {
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(fn, err.path);
|
2017-12-28 23:59:53 +08:00
|
|
|
assert.strictEqual(
|
|
|
|
err.message,
|
|
|
|
`ENOENT: no such file or directory, stat '${fn}'`);
|
|
|
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
|
|
|
assert.strictEqual(err.code, 'ENOENT');
|
|
|
|
assert.strictEqual(err.syscall, 'stat');
|
|
|
|
}));
|
|
|
|
|
|
|
|
fs.lstat(fn, common.mustCall((err) => {
|
|
|
|
assert.strictEqual(fn, err.path);
|
|
|
|
assert.strictEqual(
|
|
|
|
err.message,
|
|
|
|
`ENOENT: no such file or directory, lstat '${fn}'`);
|
|
|
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
|
|
|
assert.strictEqual(err.code, 'ENOENT');
|
|
|
|
assert.strictEqual(err.syscall, 'lstat');
|
|
|
|
}));
|
|
|
|
|
|
|
|
{
|
|
|
|
const fd = fs.openSync(existingFile, 'r');
|
|
|
|
fs.closeSync(fd);
|
|
|
|
fs.fstat(fd, common.mustCall((err) => {
|
|
|
|
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fstat');
|
|
|
|
assert.strictEqual(err.errno, uv.UV_EBADF);
|
|
|
|
assert.strictEqual(err.code, 'EBADF');
|
|
|
|
assert.strictEqual(err.syscall, 'fstat');
|
|
|
|
}));
|
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.readlink(fn, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.link(fn, 'foo', common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2013-11-16 20:46:54 +04:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.link(existingFile, existingFile2, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingFile));
|
|
|
|
assert.ok(err.message.includes(existingFile2));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2014-11-01 13:07:03 +03:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.symlink(existingFile, existingFile2, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingFile));
|
|
|
|
assert.ok(err.message.includes(existingFile2));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.unlink(fn, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.rename(fn, 'foo', common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2013-11-16 20:46:54 +04:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.rename(existingDir, existingDir2, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingDir));
|
|
|
|
assert.ok(err.message.includes(existingDir2));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.rmdir(fn, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.mkdir(existingFile, 0o666, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingFile));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.rmdir(existingFile, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingFile));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.chmod(fn, 0o666, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.open(fn, 'r', 0o666, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
fs.readFile(fn, common.mustCall((err) => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-12-28 23:59:53 +08:00
|
|
|
}));
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
// Sync
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
const errors = [];
|
|
|
|
let expected = 0;
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.statSync(fn);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('stat');
|
2017-12-28 23:59:53 +08:00
|
|
|
assert.strictEqual(fn, err.path);
|
|
|
|
assert.strictEqual(
|
|
|
|
err.message,
|
|
|
|
`ENOENT: no such file or directory, stat '${fn}'`);
|
|
|
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
|
|
|
assert.strictEqual(err.code, 'ENOENT');
|
|
|
|
assert.strictEqual(err.syscall, 'stat');
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.mkdirSync(existingFile, 0o666);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('mkdir');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingFile));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.chmodSync(fn, 0o666);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('chmod');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.lstatSync(fn);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('lstat');
|
2017-12-28 23:59:53 +08:00
|
|
|
assert.strictEqual(fn, err.path);
|
|
|
|
assert.strictEqual(
|
|
|
|
err.message,
|
|
|
|
`ENOENT: no such file or directory, lstat '${fn}'`);
|
|
|
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
|
|
|
assert.strictEqual(err.code, 'ENOENT');
|
|
|
|
assert.strictEqual(err.syscall, 'lstat');
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
const fd = fs.openSync(existingFile, 'r');
|
|
|
|
fs.closeSync(fd);
|
|
|
|
fs.fstatSync(fd);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('fstat');
|
|
|
|
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fstat');
|
|
|
|
assert.strictEqual(err.errno, uv.UV_EBADF);
|
|
|
|
assert.strictEqual(err.code, 'EBADF');
|
|
|
|
assert.strictEqual(err.syscall, 'fstat');
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.readlinkSync(fn);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('readlink');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.linkSync(fn, 'foo');
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('link');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2017-02-01 00:29:27 -05:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
2013-11-16 20:46:54 +04:00
|
|
|
fs.linkSync(existingFile, existingFile2);
|
2017-02-03 15:25:29 -08:00
|
|
|
} catch (err) {
|
|
|
|
errors.push('link');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingFile));
|
|
|
|
assert.ok(err.message.includes(existingFile2));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2013-11-16 20:46:54 +04:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
2014-11-01 13:07:03 +03:00
|
|
|
fs.symlinkSync(existingFile, existingFile2);
|
2017-02-03 15:25:29 -08:00
|
|
|
} catch (err) {
|
|
|
|
errors.push('symlink');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingFile));
|
|
|
|
assert.ok(err.message.includes(existingFile2));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2014-11-01 13:07:03 +03:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.unlinkSync(fn);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('unlink');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.rmdirSync(fn);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('rmdir');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.rmdirSync(existingFile);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('rmdir');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingFile));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.openSync(fn, 'r');
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('opens');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.renameSync(fn, 'foo');
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('rename');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
++expected;
|
2013-11-16 20:46:54 +04:00
|
|
|
fs.renameSync(existingDir, existingDir2);
|
2017-02-03 15:25:29 -08:00
|
|
|
} catch (err) {
|
|
|
|
errors.push('rename');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(existingDir));
|
|
|
|
assert.ok(err.message.includes(existingDir2));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2013-11-16 20:46:54 +04:00
|
|
|
|
2017-02-03 15:25:29 -08:00
|
|
|
try {
|
|
|
|
++expected;
|
|
|
|
fs.readdirSync(fn);
|
|
|
|
} catch (err) {
|
|
|
|
errors.push('readdir');
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(err.message.includes(fn));
|
2017-02-03 15:25:29 -08:00
|
|
|
}
|
2010-05-14 07:52:49 -07:00
|
|
|
|
2017-12-28 23:59:53 +08:00
|
|
|
assert.strictEqual(expected, errors.length);
|