pwd-fs 3.1.3 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/bitmask.d.ts +1 -0
- package/lib/src/bitmask.js +18 -0
- package/lib/src/index.d.ts +3 -5
- package/lib/src/index.js +21 -0
- package/lib/src/powered-file-system.d.ts +21 -3
- package/lib/{powered-file-system.js → src/powered-file-system.js} +69 -67
- package/lib/src/recurse-io-sync.d.ts +5 -13
- package/lib/src/recurse-io-sync.js +93 -0
- package/lib/src/recurse-io.d.ts +6 -16
- package/lib/{recurse-io.js → src/recurse-io.js} +44 -41
- package/lib/test/__fmock.js +40 -0
- package/lib/test/append.spec.js +58 -0
- package/lib/test/bitmask.spec.js +26 -0
- package/lib/test/chmod.spec.js +62 -0
- package/lib/test/chown.spec.js +74 -0
- package/lib/test/constructor.spec.js +17 -0
- package/lib/test/copy.spec.js +80 -0
- package/lib/test/mkdir.spec.js +90 -0
- package/lib/test/read.spec.js +73 -0
- package/lib/test/readdir.spec.js +70 -0
- package/lib/test/remove.spec.js +63 -0
- package/lib/test/rename.spec.js +66 -0
- package/lib/test/stat.spec.js +76 -0
- package/lib/test/symlink.spec.js +74 -0
- package/lib/test/test.spec.js +60 -0
- package/lib/test/write.spec.js +82 -0
- package/package.json +8 -15
- package/readme.md +14 -12
- package/src/bitmask.ts +20 -0
- package/src/index.ts +4 -26
- package/src/powered-file-system.ts +50 -52
- package/src/recurse-io-sync.ts +24 -24
- package/src/recurse-io.ts +18 -19
- package/{__tests__ → test}/append.spec.ts +2 -3
- package/{__tests__ → test}/chmod.spec.ts +2 -3
- package/{__tests__ → test}/chown.spec.ts +18 -14
- package/{__tests__ → test}/constructor.spec.ts +1 -1
- package/{__tests__ → test}/copy.spec.ts +2 -3
- package/{__tests__ → test}/mkdir.spec.ts +2 -1
- package/{__tests__ → test}/read.spec.ts +2 -3
- package/{__tests__ → test}/readdir.spec.ts +3 -4
- package/{__tests__ → test}/remove.spec.ts +3 -3
- package/{__tests__ → test}/rename.spec.ts +2 -2
- package/{__tests__ → test}/stat.spec.ts +2 -3
- package/{__tests__ → test}/symlink.spec.ts +3 -3
- package/{__tests__ → test}/test.spec.ts +1 -3
- package/{__tests__ → test}/write.spec.ts +2 -2
- package/tsconfig.json +5 -5
- package/jest.config.ts +0 -14
- package/lib/index.js +0 -24
- package/lib/recurse-io-sync.js +0 -90
- package/rollup.config.js +0 -16
- /package/lib/{__tests__ → test}/__fmock.d.ts +0 -0
- /package/lib/{__tests__ → test}/append.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/bitmask.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/chmod.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/chown.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/constructor.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/copy.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/mkdir.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/read.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/readdir.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/remove.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/rename.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/stat.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/symlink.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/test.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/write.spec.d.ts +0 -0
- /package/{__tests__ → test}/__fmock.ts +0 -0
- /package/{__tests__ → test}/bitmask.spec.ts +0 -0
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mkdir = exports.remove = exports.copy = exports.chown = exports.chmod = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const { sep } = node_path_1.default;
|
|
9
10
|
function chmod(src, mode, callback) {
|
|
10
11
|
let reduce = 0;
|
|
11
|
-
|
|
12
|
+
node_fs_1.default.stat(src, (err, stats) => {
|
|
12
13
|
if (err) {
|
|
13
14
|
return callback(err);
|
|
14
15
|
}
|
|
15
|
-
if (
|
|
16
|
-
|
|
16
|
+
if (stats.isDirectory()) {
|
|
17
|
+
node_fs_1.default.readdir(src, (err, list) => {
|
|
17
18
|
if (err) {
|
|
18
19
|
return callback(err);
|
|
19
20
|
}
|
|
20
21
|
if (list.length === 0) {
|
|
21
|
-
return
|
|
22
|
+
return node_fs_1.default.chmod(src, mode, callback);
|
|
22
23
|
}
|
|
23
24
|
reduce += list.length;
|
|
24
25
|
for (const loc of list) {
|
|
@@ -27,30 +28,37 @@ function chmod(src, mode, callback) {
|
|
|
27
28
|
return callback(err);
|
|
28
29
|
}
|
|
29
30
|
if (--reduce === 0) {
|
|
30
|
-
|
|
31
|
+
node_fs_1.default.chmod(src, mode, callback);
|
|
31
32
|
}
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
else {
|
|
37
|
-
|
|
38
|
+
node_fs_1.default.chmod(src, mode, callback);
|
|
38
39
|
}
|
|
39
40
|
});
|
|
40
41
|
}
|
|
42
|
+
exports.chmod = chmod;
|
|
41
43
|
function chown(src, uid, gid, callback) {
|
|
42
44
|
let reduce = 0;
|
|
43
|
-
|
|
45
|
+
node_fs_1.default.stat(src, (err, stats) => {
|
|
44
46
|
if (err) {
|
|
45
47
|
return callback(err);
|
|
46
48
|
}
|
|
49
|
+
if (uid === 0) {
|
|
50
|
+
uid = stats.uid;
|
|
51
|
+
}
|
|
52
|
+
if (gid === 0) {
|
|
53
|
+
gid = stats.gid;
|
|
54
|
+
}
|
|
47
55
|
if (stats.isDirectory()) {
|
|
48
|
-
|
|
56
|
+
node_fs_1.default.readdir(src, (err, list) => {
|
|
49
57
|
if (err) {
|
|
50
58
|
return callback(err);
|
|
51
59
|
}
|
|
52
60
|
if (list.length === 0) {
|
|
53
|
-
return
|
|
61
|
+
return node_fs_1.default.chown(src, uid, gid, callback);
|
|
54
62
|
}
|
|
55
63
|
reduce += list.length;
|
|
56
64
|
for (const loc of list) {
|
|
@@ -59,25 +67,26 @@ function chown(src, uid, gid, callback) {
|
|
|
59
67
|
return callback(err);
|
|
60
68
|
}
|
|
61
69
|
if (--reduce === 0) {
|
|
62
|
-
|
|
70
|
+
node_fs_1.default.chown(src, uid, gid, callback);
|
|
63
71
|
}
|
|
64
72
|
});
|
|
65
73
|
}
|
|
66
74
|
});
|
|
67
75
|
}
|
|
68
76
|
else {
|
|
69
|
-
|
|
77
|
+
node_fs_1.default.chown(src, uid, gid, callback);
|
|
70
78
|
}
|
|
71
79
|
});
|
|
72
80
|
}
|
|
81
|
+
exports.chown = chown;
|
|
73
82
|
function copy(src, dir, umask, callback) {
|
|
74
83
|
let reduce = 0;
|
|
75
|
-
|
|
84
|
+
node_fs_1.default.stat(src, (err, stat) => {
|
|
76
85
|
if (err) {
|
|
77
86
|
return callback(err);
|
|
78
87
|
}
|
|
79
88
|
if (stat.isDirectory()) {
|
|
80
|
-
|
|
89
|
+
node_fs_1.default.readdir(src, (err, list) => {
|
|
81
90
|
if (err) {
|
|
82
91
|
return callback(err);
|
|
83
92
|
}
|
|
@@ -86,7 +95,7 @@ function copy(src, dir, umask, callback) {
|
|
|
86
95
|
const loc = paths[paths.length - 1];
|
|
87
96
|
const mode = 0o777 - umask;
|
|
88
97
|
dir = `${dir}${sep}${loc}`;
|
|
89
|
-
|
|
98
|
+
node_fs_1.default.mkdir(dir, { mode }, (err) => {
|
|
90
99
|
if (err) {
|
|
91
100
|
return callback(err);
|
|
92
101
|
}
|
|
@@ -108,9 +117,9 @@ function copy(src, dir, umask, callback) {
|
|
|
108
117
|
}
|
|
109
118
|
else {
|
|
110
119
|
const mode = 0o666 - umask;
|
|
111
|
-
const loc =
|
|
112
|
-
const readStream =
|
|
113
|
-
const writeStream =
|
|
120
|
+
const loc = node_path_1.default.basename(src);
|
|
121
|
+
const readStream = node_fs_1.default.createReadStream(src);
|
|
122
|
+
const writeStream = node_fs_1.default.createWriteStream(`${dir}${sep}${loc}`, {
|
|
114
123
|
mode
|
|
115
124
|
});
|
|
116
125
|
readStream.on('error', callback);
|
|
@@ -122,19 +131,20 @@ function copy(src, dir, umask, callback) {
|
|
|
122
131
|
}
|
|
123
132
|
});
|
|
124
133
|
}
|
|
134
|
+
exports.copy = copy;
|
|
125
135
|
function remove(src, callback) {
|
|
126
|
-
|
|
136
|
+
node_fs_1.default.stat(src, (err, stat) => {
|
|
127
137
|
if (err) {
|
|
128
138
|
return callback(err);
|
|
129
139
|
}
|
|
130
140
|
if (stat.isDirectory()) {
|
|
131
|
-
|
|
141
|
+
node_fs_1.default.readdir(src, (err, list) => {
|
|
132
142
|
if (err) {
|
|
133
143
|
return callback(err);
|
|
134
144
|
}
|
|
135
145
|
let reduce = list.length;
|
|
136
146
|
if (reduce === 0) {
|
|
137
|
-
return
|
|
147
|
+
return node_fs_1.default.rmdir(src, callback);
|
|
138
148
|
}
|
|
139
149
|
for (const loc of list) {
|
|
140
150
|
remove(`${src}${sep}${loc}`, (err) => {
|
|
@@ -142,17 +152,18 @@ function remove(src, callback) {
|
|
|
142
152
|
return callback(err);
|
|
143
153
|
}
|
|
144
154
|
if (--reduce === 0) {
|
|
145
|
-
|
|
155
|
+
node_fs_1.default.rmdir(src, callback);
|
|
146
156
|
}
|
|
147
157
|
});
|
|
148
158
|
}
|
|
149
159
|
});
|
|
150
160
|
}
|
|
151
161
|
else {
|
|
152
|
-
|
|
162
|
+
node_fs_1.default.unlink(src, callback);
|
|
153
163
|
}
|
|
154
164
|
});
|
|
155
165
|
}
|
|
166
|
+
exports.remove = remove;
|
|
156
167
|
function mkdir(dir, umask, callback) {
|
|
157
168
|
const cwd = process.cwd();
|
|
158
169
|
if (dir === cwd) {
|
|
@@ -162,7 +173,7 @@ function mkdir(dir, umask, callback) {
|
|
|
162
173
|
const iter = yield;
|
|
163
174
|
for (const item of files) {
|
|
164
175
|
dir += `${sep}${item}`;
|
|
165
|
-
|
|
176
|
+
node_fs_1.default.mkdir(dir, { mode }, (err) => {
|
|
166
177
|
if (err && err.errno !== -17) {
|
|
167
178
|
return callback(err);
|
|
168
179
|
}
|
|
@@ -175,7 +186,7 @@ function mkdir(dir, umask, callback) {
|
|
|
175
186
|
let use = '';
|
|
176
187
|
if (dir.indexOf(cwd) === 0) {
|
|
177
188
|
use = cwd;
|
|
178
|
-
dir = dir.
|
|
189
|
+
dir = dir.substring(cwd.length);
|
|
179
190
|
}
|
|
180
191
|
const files = dir.split(sep);
|
|
181
192
|
const mode = 0o777 - umask;
|
|
@@ -183,12 +194,4 @@ function mkdir(dir, umask, callback) {
|
|
|
183
194
|
iter.next();
|
|
184
195
|
iter.next(iter);
|
|
185
196
|
}
|
|
186
|
-
|
|
187
|
-
chmod,
|
|
188
|
-
chown,
|
|
189
|
-
copy,
|
|
190
|
-
remove,
|
|
191
|
-
mkdir
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
exports.default = recurse;
|
|
197
|
+
exports.mkdir = mkdir;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.restore = exports.fmock = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
function fmock(frame) {
|
|
10
|
+
for (const src of Object.keys(frame)) {
|
|
11
|
+
const { dir } = node_path_1.default.parse(src);
|
|
12
|
+
const value = frame[src];
|
|
13
|
+
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
14
|
+
if (value.type === 'directory') {
|
|
15
|
+
node_fs_1.default.mkdirSync(src);
|
|
16
|
+
}
|
|
17
|
+
if (value.type === 'file') {
|
|
18
|
+
node_fs_1.default.writeFileSync(src, value.data);
|
|
19
|
+
}
|
|
20
|
+
if (value.type === 'symlink') {
|
|
21
|
+
node_fs_1.default.symlinkSync(value.target, src);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.fmock = fmock;
|
|
26
|
+
function restore(tmpDir) {
|
|
27
|
+
const removeRecursive = (src) => {
|
|
28
|
+
if (node_fs_1.default.existsSync(src)) {
|
|
29
|
+
node_fs_1.default.readdirSync(src).forEach((item) => {
|
|
30
|
+
const curl = `${src}/${item}`;
|
|
31
|
+
node_fs_1.default.lstatSync(curl).isDirectory()
|
|
32
|
+
? removeRecursive(curl)
|
|
33
|
+
: node_fs_1.default.unlinkSync(curl);
|
|
34
|
+
});
|
|
35
|
+
node_fs_1.default.rmdirSync(src);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
removeRecursive(tmpDir);
|
|
39
|
+
}
|
|
40
|
+
exports.restore = restore;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chance_1 = __importDefault(require("chance"));
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
12
|
+
describe('append(src, data [, options])', () => {
|
|
13
|
+
const chance = new chance_1.default();
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
(0, __fmock_1.fmock)({
|
|
16
|
+
'./tmpdir/tings.txt': {
|
|
17
|
+
type: 'file',
|
|
18
|
+
data: 'hoodie'
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
24
|
+
});
|
|
25
|
+
it('Positive: Must append content to file', async () => {
|
|
26
|
+
const payload = chance.paragraph();
|
|
27
|
+
await src_1.pfs.append('./tmpdir/tings.txt', payload);
|
|
28
|
+
const { size } = node_fs_1.default.statSync('./tmpdir/tings.txt');
|
|
29
|
+
(0, node_assert_1.default)(payload.length + 6 === size);
|
|
30
|
+
});
|
|
31
|
+
it(`Negative: Unexpected option 'flag' returns Error`, async () => {
|
|
32
|
+
const payload = chance.paragraph();
|
|
33
|
+
await (0, expect_1.expect)(async () => {
|
|
34
|
+
await src_1.pfs.append('./tmpdir/tings.txt', payload, {
|
|
35
|
+
flag: 'r'
|
|
36
|
+
});
|
|
37
|
+
})
|
|
38
|
+
.rejects
|
|
39
|
+
.toThrow();
|
|
40
|
+
});
|
|
41
|
+
it(`[sync] Positive: Must append content to file`, () => {
|
|
42
|
+
const payload = chance.paragraph();
|
|
43
|
+
src_1.pfs.append('./tmpdir/tings.txt', payload, {
|
|
44
|
+
sync: true
|
|
45
|
+
});
|
|
46
|
+
const { size } = node_fs_1.default.statSync('./tmpdir/tings.txt');
|
|
47
|
+
(0, node_assert_1.default)(payload.length + 6 === size);
|
|
48
|
+
});
|
|
49
|
+
it(`[sync] Negative: Unexpected option 'flag' returns Error`, () => {
|
|
50
|
+
const payload = chance.paragraph();
|
|
51
|
+
node_assert_1.default.throws(() => {
|
|
52
|
+
src_1.pfs.append('./tmpdir/tings.txt', payload, {
|
|
53
|
+
sync: true,
|
|
54
|
+
flag: 'r'
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const src_1 = require("../src");
|
|
8
|
+
describe('static bitmask(mode: number)', () => {
|
|
9
|
+
it('Positive: Calculate bitmask', () => {
|
|
10
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(33024) === 0o400); // (r--------)
|
|
11
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(33152) === 0o600); // (rw-------)
|
|
12
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(33216) === 0o700); // (rwx------)
|
|
13
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(32800) === 0o040); // (---r-----)
|
|
14
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(32816) === 0o060); // (---rw----)
|
|
15
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(32824) === 0o070); // (---rwx---)
|
|
16
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(32772) === 0o004); // (------r--)
|
|
17
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(32774) === 0o006); // (------rw-)
|
|
18
|
+
(0, node_assert_1.default)((0, src_1.bitmask)(32775) === 0o007); // (------rwx)
|
|
19
|
+
});
|
|
20
|
+
it(`Negative: Throw an exception if the argument is 'null' type`, () => {
|
|
21
|
+
node_assert_1.default.throws(() => {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
(0, src_1.bitmask)(null);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chance_1 = __importDefault(require("chance"));
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
12
|
+
describe('chmod(src, mode [, options])', () => {
|
|
13
|
+
const chance = new chance_1.default();
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
(0, __fmock_1.fmock)({
|
|
16
|
+
'./tmpdir/tings.txt': {
|
|
17
|
+
type: 'file',
|
|
18
|
+
data: chance.string()
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
24
|
+
});
|
|
25
|
+
it('Positive: Changes directory and file permissions', async () => {
|
|
26
|
+
await src_1.pfs.chmod('./tmpdir', 0o744);
|
|
27
|
+
const { mode } = node_fs_1.default.lstatSync('./tmpdir/tings.txt');
|
|
28
|
+
const umask = (0, src_1.bitmask)(mode);
|
|
29
|
+
(0, node_assert_1.default)(umask === 0o744);
|
|
30
|
+
});
|
|
31
|
+
it('Negative: Throw if not exists resource', async () => {
|
|
32
|
+
await (0, expect_1.expect)(async () => {
|
|
33
|
+
await src_1.pfs.chmod('./non-existent-source', 0o744);
|
|
34
|
+
})
|
|
35
|
+
.rejects
|
|
36
|
+
.toThrow();
|
|
37
|
+
});
|
|
38
|
+
it(`[sync] Positive: Changes permissions of directory`, () => {
|
|
39
|
+
src_1.pfs.chmod('./tmpdir', 0o744, {
|
|
40
|
+
sync: true
|
|
41
|
+
});
|
|
42
|
+
const { mode } = node_fs_1.default.lstatSync('./tmpdir');
|
|
43
|
+
const umask = (0, src_1.bitmask)(mode);
|
|
44
|
+
(0, node_assert_1.default)(umask === 0o744);
|
|
45
|
+
});
|
|
46
|
+
it(`[sync] Positive: Changes file permissions`, () => {
|
|
47
|
+
src_1.pfs.chmod('./tmpdir', 0o744, {
|
|
48
|
+
sync: true
|
|
49
|
+
});
|
|
50
|
+
const { mode } = node_fs_1.default.lstatSync('./tmpdir/tings.txt');
|
|
51
|
+
const umask = (0, src_1.bitmask)(mode);
|
|
52
|
+
(0, node_assert_1.default)(umask === 0o744);
|
|
53
|
+
});
|
|
54
|
+
it('[sync] Negative: Throw if not exists resource', () => {
|
|
55
|
+
const guid = chance.guid();
|
|
56
|
+
node_assert_1.default.throws(() => {
|
|
57
|
+
src_1.pfs.chmod(`./${guid}`, 0o744, {
|
|
58
|
+
sync: true
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chance_1 = __importDefault(require("chance"));
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
12
|
+
describe('chown(src, [, options])', () => {
|
|
13
|
+
const chance = new chance_1.default();
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
(0, __fmock_1.fmock)({
|
|
16
|
+
'./tmpdir/tings.txt': {
|
|
17
|
+
type: 'file',
|
|
18
|
+
data: chance.string()
|
|
19
|
+
},
|
|
20
|
+
'./tmpdir/digest/': { type: 'directory' }
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
25
|
+
});
|
|
26
|
+
it('Positive: Changes the permissions of a file', async () => {
|
|
27
|
+
const { uid, gid } = node_fs_1.default.statSync('./tmpdir/tings.txt');
|
|
28
|
+
await src_1.pfs.chown('./tmpdir/tings.txt', { uid, gid });
|
|
29
|
+
(0, node_assert_1.default)(uid && gid);
|
|
30
|
+
});
|
|
31
|
+
it('Positive: Changes the permissions of a directory', async () => {
|
|
32
|
+
const { uid, gid } = node_fs_1.default.statSync('./tmpdir/digest');
|
|
33
|
+
await src_1.pfs.chown('./tmpdir/digest', { uid, gid });
|
|
34
|
+
(0, node_assert_1.default)(uid && gid);
|
|
35
|
+
});
|
|
36
|
+
it('Negative: To a non-existent resource to return an Error', async () => {
|
|
37
|
+
const guid = chance.guid();
|
|
38
|
+
const { uid, gid } = node_fs_1.default.statSync('./tmpdir/tings.txt');
|
|
39
|
+
await (0, expect_1.expect)(async () => {
|
|
40
|
+
await src_1.pfs.chown(`./tmpdir/${guid}`, { uid, gid });
|
|
41
|
+
})
|
|
42
|
+
.rejects
|
|
43
|
+
.toThrow();
|
|
44
|
+
});
|
|
45
|
+
it('[sync] Positive: Changes the permissions of a file', () => {
|
|
46
|
+
const { uid, gid } = node_fs_1.default.statSync('./tmpdir/tings.txt');
|
|
47
|
+
src_1.pfs.chown('./tmpdir/tings.txt', {
|
|
48
|
+
sync: true,
|
|
49
|
+
uid,
|
|
50
|
+
gid
|
|
51
|
+
});
|
|
52
|
+
(0, node_assert_1.default)(uid && gid);
|
|
53
|
+
});
|
|
54
|
+
it('[sync] Positive: Changes the permissions of a directory', () => {
|
|
55
|
+
const { uid, gid } = node_fs_1.default.statSync('./tmpdir/digest');
|
|
56
|
+
src_1.pfs.chown('./tmpdir/digest', {
|
|
57
|
+
sync: true,
|
|
58
|
+
uid,
|
|
59
|
+
gid
|
|
60
|
+
});
|
|
61
|
+
(0, node_assert_1.default)(uid && gid);
|
|
62
|
+
});
|
|
63
|
+
it('[sync] Negative: To a non-existent resource to return an Error', () => {
|
|
64
|
+
const guid = chance.guid();
|
|
65
|
+
const { uid, gid } = node_fs_1.default.statSync('./tmpdir/tings.txt');
|
|
66
|
+
node_assert_1.default.throws(() => {
|
|
67
|
+
src_1.pfs.chown(`./tmpdir/${guid}`, {
|
|
68
|
+
sync: true,
|
|
69
|
+
uid,
|
|
70
|
+
gid
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const src_1 = require("../src");
|
|
8
|
+
describe('#constructor: new PoweredFileSystem(pwd?)', () => {
|
|
9
|
+
it('Positive: An empty path must match the context of the cwd', () => {
|
|
10
|
+
const { pwd } = new src_1.PoweredFileSystem();
|
|
11
|
+
(0, node_assert_1.default)(pwd === process.cwd());
|
|
12
|
+
});
|
|
13
|
+
it('Positive: Absolute path must match the context of the pwd', () => {
|
|
14
|
+
const { pwd } = new src_1.PoweredFileSystem(__dirname);
|
|
15
|
+
(0, node_assert_1.default)(pwd === __dirname);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chance_1 = __importDefault(require("chance"));
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
12
|
+
describe('copy(src, dir [, options])', () => {
|
|
13
|
+
const chance = new chance_1.default();
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
(0, __fmock_1.fmock)({
|
|
16
|
+
'./tmpdir/tings.txt': {
|
|
17
|
+
type: 'file',
|
|
18
|
+
data: chance.string()
|
|
19
|
+
},
|
|
20
|
+
'./tmpdir/digest/': { type: 'directory' }
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
25
|
+
});
|
|
26
|
+
it('Positive: Copying a item file', async () => {
|
|
27
|
+
await src_1.pfs.copy('./tmpdir/tings.txt', './tmpdir/digest');
|
|
28
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/digest/tings.txt`);
|
|
29
|
+
(0, node_assert_1.default)(exist);
|
|
30
|
+
});
|
|
31
|
+
it('Positive: Recursive copying a directory', async () => {
|
|
32
|
+
await src_1.pfs.copy('./src', './tmpdir');
|
|
33
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/src`);
|
|
34
|
+
(0, node_assert_1.default)(exist);
|
|
35
|
+
});
|
|
36
|
+
it('Negative: Throw if not exists resource', async () => {
|
|
37
|
+
const guid = chance.guid();
|
|
38
|
+
await (0, expect_1.expect)(async () => {
|
|
39
|
+
await src_1.pfs.copy(`./${guid}`, '.');
|
|
40
|
+
})
|
|
41
|
+
.rejects
|
|
42
|
+
.toThrow();
|
|
43
|
+
});
|
|
44
|
+
it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
|
|
45
|
+
await (0, expect_1.expect)(async () => {
|
|
46
|
+
await src_1.pfs.copy('./tmpdir', '.');
|
|
47
|
+
})
|
|
48
|
+
.rejects
|
|
49
|
+
.toThrow();
|
|
50
|
+
});
|
|
51
|
+
it('[sync] Positive: Copying a file', () => {
|
|
52
|
+
src_1.pfs.copy('./tmpdir/tings.txt', './tmpdir/digest', {
|
|
53
|
+
sync: true
|
|
54
|
+
});
|
|
55
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/digest/tings.txt`);
|
|
56
|
+
(0, node_assert_1.default)(exist);
|
|
57
|
+
});
|
|
58
|
+
it('[sync] Positive: Recursive copying a directory', () => {
|
|
59
|
+
src_1.pfs.copy('./src', './tmpdir', {
|
|
60
|
+
sync: true
|
|
61
|
+
});
|
|
62
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/src`);
|
|
63
|
+
(0, node_assert_1.default)(exist);
|
|
64
|
+
});
|
|
65
|
+
it('[sync] Negative: Throw if not exists resource', () => {
|
|
66
|
+
const guid = chance.guid();
|
|
67
|
+
node_assert_1.default.throws(() => {
|
|
68
|
+
src_1.pfs.copy(`./${guid}`, '.', {
|
|
69
|
+
sync: true
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it('[sync] Negative: An attempt to copy to an existing resource should return an Error', () => {
|
|
74
|
+
node_assert_1.default.throws(() => {
|
|
75
|
+
src_1.pfs.copy('./tmpdir', '.', {
|
|
76
|
+
sync: true
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chance_1 = __importDefault(require("chance"));
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
12
|
+
describe('mkdir(src [, options])', () => {
|
|
13
|
+
const pfs = new src_1.PoweredFileSystem();
|
|
14
|
+
const chance = new chance_1.default();
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
(0, __fmock_1.fmock)({
|
|
17
|
+
'./tmpdir/tings.txt': {
|
|
18
|
+
type: 'file',
|
|
19
|
+
data: chance.string()
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
25
|
+
});
|
|
26
|
+
it('Positive: Create directories in the working directory', async () => {
|
|
27
|
+
const guid = chance.guid();
|
|
28
|
+
await pfs.mkdir(`./tmpdir/${guid}`);
|
|
29
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
30
|
+
(0, node_assert_1.default)(exist);
|
|
31
|
+
});
|
|
32
|
+
it(`Positive: Make current directory`, async () => {
|
|
33
|
+
const guid = chance.guid();
|
|
34
|
+
const pfs = new src_1.PoweredFileSystem(`./tmpdir/${guid}`);
|
|
35
|
+
await pfs.mkdir('.');
|
|
36
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
37
|
+
(0, node_assert_1.default)(exist);
|
|
38
|
+
});
|
|
39
|
+
it('Positive: Should work fine with the existing directory', async () => {
|
|
40
|
+
const guid = chance.guid();
|
|
41
|
+
for (let i = 2; i; i--) {
|
|
42
|
+
await pfs.mkdir(`./tmpdir/${guid}`);
|
|
43
|
+
}
|
|
44
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
45
|
+
(0, node_assert_1.default)(exist);
|
|
46
|
+
});
|
|
47
|
+
it('Negative: Throw an exception if trying to create a directory in file', async () => {
|
|
48
|
+
const guid = chance.guid();
|
|
49
|
+
await (0, expect_1.expect)(async () => {
|
|
50
|
+
await pfs.mkdir(`./tmpdir/tings.txt/${guid}`);
|
|
51
|
+
})
|
|
52
|
+
.rejects
|
|
53
|
+
.toThrow();
|
|
54
|
+
});
|
|
55
|
+
it('Positive: Create directories in the working directory', () => {
|
|
56
|
+
const guid = chance.guid();
|
|
57
|
+
pfs.mkdir(`./tmpdir/${guid}`, {
|
|
58
|
+
sync: true
|
|
59
|
+
});
|
|
60
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
61
|
+
(0, node_assert_1.default)(exist);
|
|
62
|
+
});
|
|
63
|
+
it('[sync] Positive: Make current directory', () => {
|
|
64
|
+
const guid = chance.guid();
|
|
65
|
+
const pfs = new src_1.PoweredFileSystem(`./tmpdir/${guid}`);
|
|
66
|
+
pfs.mkdir('.', {
|
|
67
|
+
sync: true
|
|
68
|
+
});
|
|
69
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
70
|
+
(0, node_assert_1.default)(exist);
|
|
71
|
+
});
|
|
72
|
+
it('[sync] Positive: Should work fine with the existing directory', () => {
|
|
73
|
+
const guid = chance.guid();
|
|
74
|
+
for (let i = 2; i; i--) {
|
|
75
|
+
pfs.mkdir(`./tmpdir/${guid}`, {
|
|
76
|
+
sync: true
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
80
|
+
(0, node_assert_1.default)(exist);
|
|
81
|
+
});
|
|
82
|
+
it('[sync] Negative: Throw an exception if trying to create a directory in file', () => {
|
|
83
|
+
const guid = chance.guid();
|
|
84
|
+
node_assert_1.default.throws(() => {
|
|
85
|
+
pfs.mkdir(`./tmpdir/tings.txt/${guid}`, {
|
|
86
|
+
sync: true
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|