2016-10-09 19:37:59 +05:30
|
|
|
'use strict';
|
2017-06-28 21:22:35 -07:00
|
|
|
const common = require('../common');
|
2016-10-09 19:37:59 +05:30
|
|
|
|
2020-10-03 13:01:57 -07:00
|
|
|
// These tests make sure that the `options` object passed to these functions are
|
|
|
|
// never altered.
|
|
|
|
//
|
|
|
|
// Refer: https://github.com/nodejs/node/issues/7655
|
2016-10-09 19:37:59 +05:30
|
|
|
|
|
|
|
const fs = require('fs');
|
2017-06-28 21:22:35 -07:00
|
|
|
|
2022-07-13 01:57:37 +08:00
|
|
|
const options = common.mustNotMutateObjectDeep({});
|
2017-12-24 22:38:11 -08:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
2016-10-09 19:37:59 +05:30
|
|
|
|
2022-05-24 08:29:43 +09:00
|
|
|
fs.readFile(__filename, options, common.mustSucceed());
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.readFileSync(__filename, options);
|
2016-10-09 19:37:59 +05:30
|
|
|
|
2022-05-24 08:29:43 +09:00
|
|
|
fs.readdir(__dirname, options, common.mustSucceed());
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.readdirSync(__dirname, options);
|
2016-10-09 19:37:59 +05:30
|
|
|
|
2016-12-27 15:18:41 -08:00
|
|
|
if (common.canCreateSymLink()) {
|
2023-08-15 22:45:24 +09:00
|
|
|
const sourceFile = tmpdir.resolve('test-readlink');
|
|
|
|
const linkFile = tmpdir.resolve('test-readlink-link');
|
2016-10-09 19:37:59 +05:30
|
|
|
|
|
|
|
fs.writeFileSync(sourceFile, '');
|
|
|
|
fs.symlinkSync(sourceFile, linkFile);
|
|
|
|
|
2022-05-24 08:29:43 +09:00
|
|
|
fs.readlink(linkFile, options, common.mustSucceed());
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.readlinkSync(linkFile, options);
|
2016-10-09 19:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-08-15 22:45:24 +09:00
|
|
|
const fileName = tmpdir.resolve('writeFile');
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.writeFileSync(fileName, 'ABCD', options);
|
2022-05-24 08:29:43 +09:00
|
|
|
fs.writeFile(fileName, 'ABCD', options, common.mustSucceed());
|
2016-10-09 19:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-08-15 22:45:24 +09:00
|
|
|
const fileName = tmpdir.resolve('appendFile');
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.appendFileSync(fileName, 'ABCD', options);
|
2022-05-24 08:29:43 +09:00
|
|
|
fs.appendFile(fileName, 'ABCD', options, common.mustSucceed());
|
2016-10-09 19:37:59 +05:30
|
|
|
}
|
|
|
|
|
2020-11-29 16:47:08 +09:00
|
|
|
if (!common.isIBMi) { // IBMi does not support fs.watch()
|
2018-02-09 02:32:04 +01:00
|
|
|
const watch = fs.watch(__filename, options, common.mustNotCall());
|
2017-04-27 07:36:49 +05:30
|
|
|
watch.close();
|
|
|
|
}
|
2016-10-09 19:37:59 +05:30
|
|
|
|
2017-04-27 07:36:49 +05:30
|
|
|
{
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.watchFile(__filename, options, common.mustNotCall());
|
2017-04-27 07:36:49 +05:30
|
|
|
fs.unwatchFile(__filename);
|
2016-10-09 19:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.realpathSync(__filename, options);
|
2022-05-24 08:29:43 +09:00
|
|
|
fs.realpath(__filename, options, common.mustSucceed());
|
2016-10-09 19:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-08-15 22:45:24 +09:00
|
|
|
const tempFileName = tmpdir.resolve('mkdtemp-');
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.mkdtempSync(tempFileName, options);
|
2022-05-24 08:29:43 +09:00
|
|
|
fs.mkdtemp(tempFileName, options, common.mustSucceed());
|
2016-10-09 19:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-08-15 22:45:24 +09:00
|
|
|
const fileName = tmpdir.resolve('streams');
|
2018-02-09 02:32:04 +01:00
|
|
|
fs.WriteStream(fileName, options).once('open', common.mustCall(() => {
|
2019-07-30 07:50:21 +01:00
|
|
|
fs.ReadStream(fileName, options).destroy();
|
|
|
|
})).end();
|
2016-10-09 19:37:59 +05:30
|
|
|
}
|