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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*---
includes: [compareArray.js, compatFs.js]
flags: [async]
---*/
var fname = `${test_dir}/fs_promises_04`;
var fname_utf8 = `${test_dir}/fs_promises_αβγ_04`;
var lname = `${test_dir}/fs_promises_lnk_04`;
let stages = [];
var testSync = () => new Promise((resolve, reject) => {
try {
try { fs.unlinkSync(fname); } catch (e) {}
try { fs.unlinkSync(lname); } catch (e) {}
try {
fs.realpathSync(fname);
throw new Error('fs.realpathSync error 1');
} catch (e) {
if (e.code != 'ENOENT') {
throw new Error('fs.realpathSync error 2');
}
}
fs.writeFileSync(fname, fname);
fs.writeFileSync(fname_utf8, fname_utf8);
var rname = fs.realpathSync(fname);
fs.symlinkSync(rname, lname);
if (fs.realpathSync(lname) != rname) {
throw new Error('fs.symlinkSync error 2');
}
if (fs.readFileSync(lname) != fname) {
throw new Error('fs.symlinkSync error 3');
}
var rname_utf8 = fs.realpathSync(fname_utf8);
if (rname_utf8.slice(-6,-3) != 'αβγ') {
throw new Error('fs.realpathSync error 3');
}
fs.unlinkSync(lname);
fs.accessSync(fname);
fs.unlinkSync(fname);
fs.unlinkSync(fname_utf8);
stages.push("symlinkSync");
resolve();
} catch (e) {
reject(e);
}
});
var testCallback = () => new Promise((resolve, reject) => {
try {
try {
fs.unlinkSync(fname);
} catch (e) {
void e;
}
try {
fs.unlinkSync(lname);
} catch (e) {
void e;
}
fs.realpath(fname, (err) => {
if (!err) {
reject(new Error('fs.realpath error 1'));
return;
}
if (err.code != 'ENOENT') {
reject(err);
return;
}
try {
fs.writeFileSync(fname, fname);
} catch (e) {
reject(e);
return;
}
fs.realpath(fname, (err, rname) => {
if (err) {
reject(err);
return;
}
fs.symlink(rname, lname, (err) => {
if (err) {
reject(err);
return;
}
fs.realpath(lname, undefined, (err, xname) => {
if (err) {
reject(err);
return;
}
if (rname != xname) {
reject(new Error('fs.symlink error 1'));
return;
}
try {
if (fs.readFileSync(lname) != fname) {
reject(new Error('fs.symlink error 2'));
return;
}
fs.unlinkSync(lname);
fs.accessSync(fname);
fs.unlinkSync(fname);
} catch (e) {
reject(e);
return;
}
stages.push("symlink");
resolve();
});
});
});
});
} catch (e) {
reject(e);
}
});
let testFsp = () => Promise.resolve()
.then(() => fsp.unlink(fname)
.catch(() => {}))
.then(() => fsp.unlink(lname)
.catch(() => {}))
.then(() => fsp.realpath(fname)
.then(() => { throw new Error('fsp.realpath error 1') }))
.catch((e) => {
if (e.syscall != 'realpath' || e.code != 'ENOENT') {
throw e;
}
})
.then(() => {
fs.writeFileSync(fname, fname);
return fsp.realpath(fname);
})
.then((rname) => fsp.symlink(rname, lname)
.then(() => rname))
.then((rname) => fsp.realpath(lname)
.then((xname) => {
if (rname != xname) {
throw new Error(`fsp.symlink error 2`);
}
}))
.then(() => {
if (fs.readFileSync(lname) != fname) {
throw new Error('fsp.symlink error 3');
}
fs.unlinkSync(lname);
fs.accessSync(fname);
fs.unlinkSync(fname);
stages.push("fsp.symlink");
})
let p = Promise.resolve()
if (has_fs_symbolic_link()) {
p = p
.then(testSync)
.then(testCallback)
.then(testFsp)
.then(() => assert.compareArray(stages, ['symlinkSync', 'symlink', 'fsp.symlink']))
}
p.then($DONE, $DONE);
|