File: mkdir2.t.mjs

package info (click to toggle)
libnginx-mod-js 0.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,808 kB
  • sloc: ansic: 114,096; perl: 8,447; javascript: 2,520; exp: 487; sh: 322; xml: 312; python: 181; makefile: 18
file content (84 lines) | stat: -rw-r--r-- 2,064 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*---
includes: [compareArray.js, compatFs.js]
flags: [async]
---*/

var dname = `${test_dir}/fs_promises_αβγ_08/`;
var path = 'one/two/three/αβγ';

var wipePath = (root, path, nofail) => {
    path
        .split('/')
        .map((x, i, a) => {
            return root + a.slice(0, i + 1).join('/');
        })
        .reverse()
        .map((dir) => {
            try {
                fs.rmdirSync(dir);
            } catch (e) {
                if (!nofail) {
                    throw e;
                }
            }
        });
};

let stages = [];

var testSync = () => new Promise((resolve, reject) => {
    try {
        wipePath(dname, path + '/' + path, true);
        fs.rmdirSync(dname);
    } catch (e) {
    }

    try {
        fs.mkdirSync(dname);

        fs.mkdirSync(dname, { recursive: true });
        fs.mkdirSync(dname + '/', { recursive: true });
        fs.mkdirSync(dname + '////', { recursive: true });

        fs.mkdirSync(dname + path, { recursive: true });
        wipePath(dname, path);

        fs.mkdirSync(dname + '////' + path + '////' + path + '////', { recursive: true });
        wipePath(dname, path + '/' + path);

        try {
            fs.mkdirSync(dname + path, { recursive: true, mode: 0 });
        } catch (e) {
            if (e.code != 'EACCES') {
                reject(e);
            }
        }
        wipePath(dname, path, true);

        try {
            fs.mkdirSync(dname + path, { recursive: true });
            fs.writeFileSync(dname + path + '/one', 'not dir');
            fs.mkdirSync(dname + path + '/' + path, { recursive: true });
        } catch (e) {
            if (e.code != 'ENOTDIR') {
                reject(e);
            }
        }
        fs.unlinkSync(dname + path + '/one');
        wipePath(dname, path);

        fs.rmdirSync(dname);

        stages.push("mkdirSync")

        resolve();
    } catch (e) {
        reject(e);
    }
});

let p = Promise.resolve()
    .then(testSync)
    .then(() => assert.compareArray(stages, ["mkdirSync"]))

p.then($DONE, $DONE);