| 1 |
"use strict"; |
| 2 |
|
| 3 |
const { resolve } = require("path") |
| 4 |
, lstat = require("../lstat") |
| 5 |
, mkdir = require("../mkdir") |
| 6 |
, writeFile = require("../write-file") |
| 7 |
, pg = resolve(__dirname, "__playground") |
| 8 |
, rootPath = resolve(pg, "rmdir") |
| 9 |
, nested = resolve(rootPath, "one/two/three/dir") |
| 10 |
, nested2 = resolve(rootPath, "one/four/five/six"); |
| 11 |
|
| 12 |
module.exports = function (t, a, d) { |
| 13 |
// Setup |
| 14 |
mkdir(nested, { intermediate: true })(mkdir(nested2, { intermediate: true }))(() => |
| 15 |
writeFile(resolve(nested, "../foo"), "bar") |
| 16 |
) |
| 17 |
// Do not remove non empty (with default options) |
| 18 |
.then(() => |
| 19 |
t(rootPath)(a.never, err => { a(err.code, "ENOTEMPTY", "Default on not empty"); }) |
| 20 |
) |
| 21 |
// Do not remove non empty (with recursive option) |
| 22 |
.then(() => |
| 23 |
t(rootPath, { recursive: true })(a.never, err => { |
| 24 |
a(err.code, "ENOTEMPTY", "Recursive not empty"); |
| 25 |
}) |
| 26 |
) |
| 27 |
// Remove recrsively empty directories |
| 28 |
.then(() => { |
| 29 |
const path = resolve(rootPath, "one/four"); |
| 30 |
return t(path, { recursive: true })(() => |
| 31 |
lstat(path)(a.never, err => { a(err.code, "ENOENT", "Recursive on empty"); }) |
| 32 |
); |
| 33 |
}) |
| 34 |
// Remove empty directory (with default options) |
| 35 |
.then(() => |
| 36 |
t(nested)(() => lstat(nested)(a.never, err => { a(err.code, "ENOENT", "Plain"); })) |
| 37 |
) |
| 38 |
// Ignore not existing directory (with loose option) |
| 39 |
.then(() => t(nested, { loose: true })(res => { a(res, null, "Loose option"); }, a.never)) |
| 40 |
// Remove non empty directory without directories (with force option) |
| 41 |
.then(() => |
| 42 |
t(resolve(nested, "../"), { force: true })(() => |
| 43 |
lstat(resolve(nested, "../"))(a.never, err => { a(err.code, "ENOENT", "Forced"); }) |
| 44 |
) |
| 45 |
) |
| 46 |
|
| 47 |
// Remove non empty deep directory (with force and recursive option) |
| 48 |
.then(() => |
| 49 |
t(rootPath, { recursive: true, force: true })(() => |
| 50 |
lstat(rootPath)(a.never, err => { a(err.code, "ENOENT", "Recursive and forced"); }) |
| 51 |
) |
| 52 |
) |
| 53 |
|
| 54 |
.done(d, d); |
| 55 |
}; |