Skip to content

Commit 2ad1ed2

Browse files
author
unknown
committed
fix: fix error on windows
1 parent bb9a16b commit 2ad1ed2

5 files changed

Lines changed: 36 additions & 30 deletions

File tree

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const _0777 = parseInt('0777', 8);
44

55
module.exports = mkdirP;
66

7+
const errCode = process.platform === 'win32' ? 3 : 2;
8+
79
function mkdirP(p, opts, made) {
810
if (!opts || typeof opts !== 'object') {
911
opts = {
@@ -26,7 +28,7 @@ function mkdirP(p, opts, made) {
2628
made = made || p;
2729
} catch (err0) {
2830
switch (err0.number) {
29-
case 2:
31+
case errCode:
3032
made = mkdirP(path.dirname(p), opts, made);
3133
mkdirP(p, opts, made);
3234
break;

test/chmod.test.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@ for (let i = 0; i < 25; i++) {
1919
let file = ps.join('/');
2020
file = path.join(__dirname, file.slice(1));
2121

22-
describe('chmod', () => {
23-
it("chmod-pre", () => {
24-
const mode = _0744;
25-
mkdirp(file, mode);
26-
const stat = fs.stat(file);
27-
assert.ok(stat && stat.isDirectory(), 'should be directory');
28-
assert.equal(stat && stat.mode & _0777, mode);
29-
});
22+
if (process.platform !== 'win32') {
23+
describe('chmod', () => {
24+
it("chmod-pre", () => {
25+
const mode = _0744;
26+
mkdirp(file, mode);
27+
const stat = fs.stat(file);
28+
assert.ok(stat && stat.isDirectory(), 'should be directory');
29+
assert.equal(stat && stat.mode & _0777, mode);
30+
});
31+
32+
it("chmod", () => {
33+
mkdirp(file, _0755);
34+
const stat = fs.stat(file);
35+
assert.ok(stat && stat.isDirectory(), 'should be directory');
36+
});
3037

31-
it("chmod", () => {
32-
mkdirp(file, _0755);
33-
const stat = fs.stat(file);
34-
assert.ok(stat && stat.isDirectory(), 'should be directory');
3538
});
36-
37-
});
39+
}
3840

3941
// test.run(console.DEBUG);

test/clobber.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ describe('clobber', () => {
3333
try {
3434
mkdirp(file, _0755);
3535
} catch (e) {
36-
if (e.number === 20) {
36+
const errCode = process.platform === 'win32' ? 183 : 20;
37+
if (e.number === errCode) {
3738
return;
3839
}
3940
}

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ filelist.map(file => {
99
}
1010
});
1111

12-
process.exit(-test.run());
12+
process.exit(-test.run(console.DEBUG));

test/umask.test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ const _0777 = parseInt('0777', 8);
77

88
test.setup();
99

10-
describe('umask', () => {
11-
it("implicit mode from umask", () => {
12-
const x = Math.floor(Math.random() * Math.pow(16, 4)).toString(16);
13-
const y = Math.floor(Math.random() * Math.pow(16, 4)).toString(16);
14-
const z = Math.floor(Math.random() * Math.pow(16, 4)).toString(16);
10+
if (process.platform !== 'win32') {
11+
describe('umask', () => {
12+
it("implicit mode from umask", () => {
13+
const x = Math.floor(Math.random() * Math.pow(16, 4)).toString(16);
14+
const y = Math.floor(Math.random() * Math.pow(16, 4)).toString(16);
15+
const z = Math.floor(Math.random() * Math.pow(16, 4)).toString(16);
1516

16-
const file = path.join(__dirname, 'tmp/' + [x, y, z].join('/'));
17+
const file = path.join(__dirname, 'tmp/' + [x, y, z].join('/'));
1718

18-
mkdirp(file);
19-
assert.ok(fs.exists(file), 'file created');
20-
const stat = fs.stat(file);
21-
assert.equal(stat.mode & _0777, _0777 & (~process.umask()));
22-
assert.ok(stat.isDirectory(), 'target is a directory');
19+
mkdirp(file);
20+
assert.ok(fs.exists(file), 'file created');
21+
const stat = fs.stat(file);
22+
assert.equal(stat.mode & _0777, _0777 & (~process.umask()));
23+
assert.ok(stat.isDirectory(), 'target is a directory');
24+
});
2325
});
24-
});
25-
26+
}
2627
//test.run(console.DEBUG);

0 commit comments

Comments
 (0)