2015-08-28 03:31:11 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const d = path.join(common.tmpDir, 'dir');
|
|
|
|
|
|
|
|
common.refreshTmpDir();
|
|
|
|
|
|
|
|
// Make sure the directory does not exist
|
|
|
|
assert(!common.fileExists(d));
|
|
|
|
// Create the directory now
|
|
|
|
fs.mkdirSync(d);
|
|
|
|
// Make sure the directory exists
|
|
|
|
assert(common.fileExists(d));
|
|
|
|
// Try creating again, it should fail with EEXIST
|
|
|
|
assert.throws(function() {
|
|
|
|
fs.mkdirSync(d);
|
|
|
|
}, /EEXIST: file already exists, mkdir/);
|
|
|
|
// Remove the directory now
|
|
|
|
fs.rmdirSync(d);
|
|
|
|
// Make sure the directory does not exist
|
|
|
|
assert(!common.fileExists(d));
|
|
|
|
|
|
|
|
// Similarly test the Async version
|
2017-06-14 16:42:39 +02:00
|
|
|
fs.mkdir(d, 0o666, common.mustCall(function(err) {
|
2015-08-28 03:31:11 +02:00
|
|
|
assert.ifError(err);
|
|
|
|
|
2017-06-14 16:42:39 +02:00
|
|
|
fs.mkdir(d, 0o666, common.mustCall(function(err) {
|
|
|
|
assert.ok(err, 'got no error');
|
|
|
|
assert.ok(/^EEXIST/.test(err.message), 'got no EEXIST message');
|
|
|
|
assert.strictEqual(err.code, 'EEXIST', 'got no EEXIST code');
|
|
|
|
assert.strictEqual(err.path, d, 'got no proper path for EEXIST');
|
2015-08-28 03:31:11 +02:00
|
|
|
|
|
|
|
fs.rmdir(d, assert.ifError);
|
2017-06-14 16:42:39 +02:00
|
|
|
}));
|
|
|
|
}));
|