File: rmdir.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 (110 lines) | stat: -rw-r--r-- 2,726 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*---
includes: [compareArray.js, compatFs.js]
flags: [async]
---*/

var root = test_dir;
var dname = 'fs_promises_αβγ_09/';
var lname = 'fs_promises_αβγ_09_lnk';
var path = 'one/two/three/αβγ';

var setContent = (root, path) => {
    fs.mkdirSync(root + path, { recursive: true });
    path
        .split('/')
        .forEach((x, i, a) => {
            for (var j = 1; j < 10; ++j) {
                var path = root + a.slice(0, i + 1).join('/') + '_file' + j;
                fs.writeFileSync(path, path);
            }
        });
};


var isNode = () => process.argv[0].includes('node');

let stages = [];

var testSync = () => new Promise((resolve, reject) => {
    try {
        fs.unlinkSync(root + lname);
    } catch (e) {
    }
    try {
        fs.rmdirSync(root + dname, { recursive: true });
    } catch (e) {
    }

    try {

        fs.mkdirSync(root + dname);
        fs.symlinkSync(dname, root + lname);
        try {
            fs.rmdirSync(root + lname);
            throw new Error('fs.rmdirSync() - error 0');
        } catch (e) {
            if (e.code != "ENOTDIR") {
                throw e;
            }
        }
        fs.rmdirSync(root + dname);
        fs.unlinkSync(root + lname);

        if (!isNode()) {
            fs.mkdirSync(root + dname);
            fs.symlinkSync(dname, root + lname);
            try {
                fs.rmdirSync(root + lname, { recursive: true });
                throw new Error('fs.rmdirSync() - error 1');
            } catch (e) {
                if (e.code != "ENOTDIR") {
                    throw e;
                }
            }
            fs.rmdirSync(root + dname);
            fs.unlinkSync(root + lname);
        }

        fs.mkdirSync(root + dname, { mode: 0 });
        fs.rmdirSync(root + dname, { recursive: true });

        setContent(root + dname, path);
        fs.rmdirSync(root + dname, { recursive: true });

        try {
            fs.accessSync(root + dname);
            throw new Error('fs.rmdirSync() - error 2');
        } catch (e) {
            if (e.code != "ENOENT") {
                throw e;
            }
        }

        if (!isNode()) {
            try {
                fs.rmdirSync(root + dname, { recursive: true });
                throw new Error('fs.rmdirSync() - error 3');
            } catch (e) {
                if (e.code != "ENOENT") {
                    throw e;
                }
            }
        }

        stages.push("rmdirSync");

        resolve();

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

let p = Promise.resolve()
if (has_fs_symbolic_link()) {
    p = p
        .then(testSync)
        .then(() => assert.compareArray(stages, ['rmdirSync']))
}

p.then($DONE, $DONE);