pwd-fs 3.2.4 → 3.3.2
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/dist/bitmask.d.ts +4 -0
- package/dist/bitmask.js +17 -0
- package/dist/bitmask.test.d.ts +1 -0
- package/dist/bitmask.test.js +29 -0
- package/dist/{src/index.d.ts → index.d.ts} +3 -0
- package/dist/{src/index.js → index.js} +3 -0
- package/dist/powered-file-system/append.d.ts +9 -0
- package/dist/powered-file-system/append.js +10 -0
- package/dist/powered-file-system/append.test.d.ts +1 -0
- package/dist/powered-file-system/append.test.js +47 -0
- package/dist/powered-file-system/chmod.d.ts +7 -0
- package/dist/powered-file-system/chmod.js +28 -0
- package/dist/powered-file-system/chmod.test.d.ts +1 -0
- package/dist/powered-file-system/chmod.test.js +71 -0
- package/dist/powered-file-system/chown.d.ts +9 -0
- package/dist/powered-file-system/chown.js +45 -0
- package/dist/powered-file-system/chown.test.d.ts +1 -0
- package/dist/powered-file-system/chown.test.js +82 -0
- package/dist/powered-file-system/copy.d.ts +8 -0
- package/dist/powered-file-system/copy.js +29 -0
- package/dist/powered-file-system/copy.test.d.ts +1 -0
- package/dist/powered-file-system/copy.test.js +82 -0
- package/dist/powered-file-system/mkdir.d.ts +8 -0
- package/dist/powered-file-system/mkdir.js +28 -0
- package/dist/powered-file-system/mkdir.test.d.ts +1 -0
- package/dist/powered-file-system/mkdir.test.js +116 -0
- package/dist/powered-file-system/read.d.ts +9 -0
- package/dist/powered-file-system/read.js +29 -0
- package/dist/powered-file-system/read.test.d.ts +1 -0
- package/dist/powered-file-system/read.test.js +75 -0
- package/dist/powered-file-system/readdir.d.ts +8 -0
- package/dist/powered-file-system/readdir.js +26 -0
- package/dist/powered-file-system/readdir.test.d.ts +1 -0
- package/dist/powered-file-system/readdir.test.js +72 -0
- package/dist/powered-file-system/remove.d.ts +7 -0
- package/dist/powered-file-system/remove.js +36 -0
- package/dist/powered-file-system/remove.test.d.ts +1 -0
- package/dist/powered-file-system/remove.test.js +78 -0
- package/dist/powered-file-system/rename.d.ts +7 -0
- package/dist/powered-file-system/rename.js +28 -0
- package/dist/powered-file-system/rename.test.d.ts +1 -0
- package/dist/powered-file-system/rename.test.js +70 -0
- package/dist/powered-file-system/stat.d.ts +7 -0
- package/dist/powered-file-system/stat.js +26 -0
- package/dist/powered-file-system/stat.test.d.ts +1 -0
- package/dist/powered-file-system/stat.test.js +79 -0
- package/dist/powered-file-system/symlink.d.ts +4 -0
- package/dist/powered-file-system/symlink.js +52 -0
- package/dist/powered-file-system/symlink.test.d.ts +1 -0
- package/dist/powered-file-system/symlink.test.js +77 -0
- package/dist/powered-file-system/test.d.ts +8 -0
- package/dist/powered-file-system/test.js +30 -0
- package/dist/powered-file-system/test.test.d.ts +1 -0
- package/dist/powered-file-system/test.test.js +76 -0
- package/dist/powered-file-system/write.d.ts +10 -0
- package/dist/powered-file-system/write.js +36 -0
- package/dist/powered-file-system/write.test.d.ts +1 -0
- package/dist/powered-file-system/write.test.js +97 -0
- package/dist/powered-file-system.d.ts +127 -0
- package/dist/powered-file-system.js +144 -0
- package/dist/powered-file-system.test.d.ts +1 -0
- package/dist/powered-file-system.test.js +21 -0
- package/dist/recurse-io-sync.d.ts +20 -0
- package/dist/{src/recurse-io-sync.js → recurse-io-sync.js} +37 -37
- package/dist/{src/recurse-io.d.ts → recurse-io.d.ts} +15 -1
- package/dist/{src/recurse-io.js → recurse-io.js} +52 -58
- package/dist/suite.test.d.ts +1 -0
- package/dist/suite.test.js +40 -0
- package/dist/test-utils.d.ts +18 -0
- package/dist/test-utils.js +72 -0
- package/package.json +31 -14
- package/readme.md +331 -246
- package/.travis.yml +0 -12
- package/appveyor.yml +0 -16
- package/dist/src/bitmask.d.ts +0 -1
- package/dist/src/bitmask.js +0 -18
- package/dist/src/powered-file-system.d.ts +0 -173
- package/dist/src/powered-file-system.js +0 -262
- package/dist/src/recurse-io-sync.d.ts +0 -5
- package/src/bitmask.ts +0 -20
- package/src/index.ts +0 -7
- package/src/powered-file-system.ts +0 -508
- package/src/recurse-io-sync.ts +0 -108
- package/src/recurse-io.ts +0 -238
- package/test/__fmock.ts +0 -45
- package/test/append.spec.ts +0 -71
- package/test/bitmask.spec.ts +0 -23
- package/test/chmod.spec.ts +0 -77
- package/test/chown.spec.ts +0 -92
- package/test/constructor.spec.ts +0 -15
- package/test/copy.spec.ts +0 -101
- package/test/mkdir.spec.ts +0 -121
- package/test/read.spec.ts +0 -91
- package/test/readdir.spec.ts +0 -86
- package/test/remove.spec.ts +0 -78
- package/test/rename.spec.ts +0 -84
- package/test/stat.spec.ts +0 -99
- package/test/symlink.spec.ts +0 -95
- package/test/test.spec.ts +0 -80
- package/test/write.spec.ts +0 -104
- package/tsconfig.json +0 -14
package/src/recurse-io.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import fs, { NoParamCallback } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
type Files = Array<string>;
|
|
5
|
-
|
|
6
|
-
const { sep } = path;
|
|
7
|
-
|
|
8
|
-
export function chmod(src: string, mode: number, callback: NoParamCallback) {
|
|
9
|
-
let reduce = 0;
|
|
10
|
-
|
|
11
|
-
fs.stat(src, (err, stats) => {
|
|
12
|
-
if (err) {
|
|
13
|
-
return callback(err);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (stats.isDirectory()) {
|
|
17
|
-
fs.readdir(src, (err, list) => {
|
|
18
|
-
if (err) {
|
|
19
|
-
return callback(err);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (list.length === 0) {
|
|
23
|
-
return fs.chmod(src, mode, callback);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
reduce += list.length;
|
|
27
|
-
|
|
28
|
-
for (const loc of list) {
|
|
29
|
-
chmod(`${src}${sep}${loc}`, mode, (err) => {
|
|
30
|
-
if (err) {
|
|
31
|
-
return callback(err);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (--reduce === 0) {
|
|
35
|
-
fs.chmod(src, mode, callback);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
fs.chmod(src, mode, callback);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function chown(src: string, uid: number, gid: number, callback: NoParamCallback) {
|
|
48
|
-
let reduce = 0;
|
|
49
|
-
|
|
50
|
-
fs.stat(src, (err, stats) => {
|
|
51
|
-
if (err) {
|
|
52
|
-
return callback(err);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (uid === 0) {
|
|
56
|
-
uid = stats.uid;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (gid === 0) {
|
|
60
|
-
gid = stats.gid;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (stats.isDirectory()) {
|
|
64
|
-
fs.readdir(src, (err, list) => {
|
|
65
|
-
if (err) {
|
|
66
|
-
return callback(err);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (list.length === 0) {
|
|
70
|
-
return fs.chown(src, uid, gid, callback);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
reduce += list.length;
|
|
74
|
-
|
|
75
|
-
for (const loc of list) {
|
|
76
|
-
chown(`${src}${sep}${loc}`, uid, gid, (err) => {
|
|
77
|
-
if (err) {
|
|
78
|
-
return callback(err);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (--reduce === 0) {
|
|
82
|
-
fs.chown(src, uid, gid, callback);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
fs.chown(src, uid, gid, callback);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function copy(src: string, dir: string, umask: number, callback: NoParamCallback) {
|
|
95
|
-
let reduce = 0;
|
|
96
|
-
|
|
97
|
-
fs.stat(src, (err, stat) => {
|
|
98
|
-
if (err) {
|
|
99
|
-
return callback(err);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (stat.isDirectory()) {
|
|
103
|
-
fs.readdir(src, (err, list) => {
|
|
104
|
-
if (err) {
|
|
105
|
-
return callback(err);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
reduce += list.length;
|
|
109
|
-
|
|
110
|
-
const paths = src.split(sep);
|
|
111
|
-
const loc = paths[paths.length - 1];
|
|
112
|
-
const mode = 0o777 - umask;
|
|
113
|
-
|
|
114
|
-
dir = `${dir}${sep}${loc}`;
|
|
115
|
-
|
|
116
|
-
fs.mkdir(dir, { mode }, (err) => {
|
|
117
|
-
if (err) {
|
|
118
|
-
return callback(err);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (reduce === 0) {
|
|
122
|
-
return callback(null);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
for (const loc of list) {
|
|
126
|
-
copy(`${src}${sep}${loc}`, dir, umask, (err) => {
|
|
127
|
-
if (err) {
|
|
128
|
-
return callback(err);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (--reduce === 0) {
|
|
132
|
-
callback(null);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
const mode = 0o666 - umask;
|
|
141
|
-
const loc = path.basename(src);
|
|
142
|
-
|
|
143
|
-
const readStream = fs.createReadStream(src);
|
|
144
|
-
const writeStream = fs.createWriteStream(`${dir}${sep}${loc}`, {
|
|
145
|
-
mode
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
readStream.on('error', callback);
|
|
149
|
-
writeStream.on('error', callback);
|
|
150
|
-
|
|
151
|
-
writeStream.on('close', () => {
|
|
152
|
-
callback(null);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
readStream.pipe(writeStream);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function remove(src: string, callback: NoParamCallback) {
|
|
161
|
-
fs.stat(src, (err, stat) => {
|
|
162
|
-
if (err) {
|
|
163
|
-
return callback(err);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (stat.isDirectory()) {
|
|
167
|
-
fs.readdir(src, (err, list) => {
|
|
168
|
-
if (err) {
|
|
169
|
-
return callback(err);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let reduce = list.length;
|
|
173
|
-
|
|
174
|
-
if (reduce === 0) {
|
|
175
|
-
return fs.rmdir(src, callback);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
for (const loc of list) {
|
|
179
|
-
remove(`${src}${sep}${loc}`, (err) => {
|
|
180
|
-
if (err) {
|
|
181
|
-
return callback(err);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (--reduce === 0) {
|
|
185
|
-
fs.rmdir(src, callback);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
fs.unlink(src, callback);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function mkdir(dir: string, umask: number, callback: NoParamCallback) {
|
|
198
|
-
const cwd = process.cwd();
|
|
199
|
-
|
|
200
|
-
if (dir === cwd) {
|
|
201
|
-
return callback(null);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const sequence = function* (dir: string, files: Files, mode: number): Generator<void, void, Generator> {
|
|
205
|
-
const iter = yield;
|
|
206
|
-
|
|
207
|
-
for (const item of files) {
|
|
208
|
-
dir += `${sep}${item}`;
|
|
209
|
-
|
|
210
|
-
fs.mkdir(dir, { mode }, (err) => {
|
|
211
|
-
if (err && err.errno !== -17) {
|
|
212
|
-
return callback(err);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
iter.next();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
yield;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
callback(null);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
let use = '';
|
|
225
|
-
|
|
226
|
-
if (dir.indexOf(cwd) === 0) {
|
|
227
|
-
use = cwd;
|
|
228
|
-
dir = dir.substring(cwd.length);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const files = dir.split(sep);
|
|
232
|
-
const mode = 0o777 - umask;
|
|
233
|
-
|
|
234
|
-
const iter = sequence(use, files, mode);
|
|
235
|
-
|
|
236
|
-
iter.next();
|
|
237
|
-
iter.next(iter);
|
|
238
|
-
}
|
package/test/__fmock.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
export interface Iframe {
|
|
5
|
-
[key: string]: any
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function fmock(frame: Iframe) {
|
|
9
|
-
for (const src of Object.keys(frame)) {
|
|
10
|
-
const { dir } = path.parse(src);
|
|
11
|
-
const value = frame[src];
|
|
12
|
-
|
|
13
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
14
|
-
|
|
15
|
-
if (value.type === 'directory') {
|
|
16
|
-
fs.mkdirSync(src);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (value.type === 'file') {
|
|
20
|
-
fs.writeFileSync(src, value.data);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (value.type === 'symlink') {
|
|
24
|
-
fs.symlinkSync(value.target, src);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function restore(tmpDir: string) {
|
|
30
|
-
const removeRecursive = (src: string) => {
|
|
31
|
-
if (fs.existsSync(src)) {
|
|
32
|
-
fs.readdirSync(src).forEach((item) => {
|
|
33
|
-
const curl = `${src}/${item}`;
|
|
34
|
-
|
|
35
|
-
fs.lstatSync(curl).isDirectory()
|
|
36
|
-
? removeRecursive(curl)
|
|
37
|
-
: fs.unlinkSync(curl);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
fs.rmdirSync(src);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
removeRecursive(tmpDir);
|
|
45
|
-
}
|
package/test/append.spec.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import Chance from 'chance';
|
|
4
|
-
import { expect } from 'expect';
|
|
5
|
-
import { fmock, restore } from './__fmock';
|
|
6
|
-
import { pfs } from '../src';
|
|
7
|
-
|
|
8
|
-
describe('append(src, data [, options])', () => {
|
|
9
|
-
const chance = new Chance();
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
fmock({
|
|
13
|
-
'./tmpdir/tings.txt': {
|
|
14
|
-
type: 'file',
|
|
15
|
-
data: 'hoodie'
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
restore('./tmpdir');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
it('Positive: Must append content to file', async () => {
|
|
26
|
-
const payload = chance.paragraph();
|
|
27
|
-
|
|
28
|
-
await pfs.append('./tmpdir/tings.txt', payload);
|
|
29
|
-
const { size } = fs.statSync('./tmpdir/tings.txt');
|
|
30
|
-
|
|
31
|
-
assert(payload.length + 6 === size);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
it(`Negative: Unexpected option 'flag' returns Error`, async () => {
|
|
36
|
-
const payload = chance.paragraph();
|
|
37
|
-
|
|
38
|
-
await expect(async () => {
|
|
39
|
-
await pfs.append('./tmpdir/tings.txt', payload, {
|
|
40
|
-
flag: 'r'
|
|
41
|
-
});
|
|
42
|
-
})
|
|
43
|
-
.rejects
|
|
44
|
-
.toThrow();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
it(`[sync] Positive: Must append content to file`, () => {
|
|
49
|
-
const payload = chance.paragraph();
|
|
50
|
-
|
|
51
|
-
pfs.append('./tmpdir/tings.txt', payload, {
|
|
52
|
-
sync: true
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const { size } = fs.statSync('./tmpdir/tings.txt');
|
|
56
|
-
|
|
57
|
-
assert(payload.length + 6 === size);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
it(`[sync] Negative: Unexpected option 'flag' returns Error`, () => {
|
|
62
|
-
const payload = chance.paragraph();
|
|
63
|
-
|
|
64
|
-
assert.throws(() => {
|
|
65
|
-
pfs.append('./tmpdir/tings.txt', payload, {
|
|
66
|
-
sync: true,
|
|
67
|
-
flag: 'r'
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
package/test/bitmask.spec.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import { bitmask } from '../src';
|
|
3
|
-
|
|
4
|
-
describe('static bitmask(mode: number)', () => {
|
|
5
|
-
it('Positive: Calculate bitmask', () => {
|
|
6
|
-
assert(bitmask(33024) === 0o400); // (r--------)
|
|
7
|
-
assert(bitmask(33152) === 0o600); // (rw-------)
|
|
8
|
-
assert(bitmask(33216) === 0o700); // (rwx------)
|
|
9
|
-
assert(bitmask(32800) === 0o040); // (---r-----)
|
|
10
|
-
assert(bitmask(32816) === 0o060); // (---rw----)
|
|
11
|
-
assert(bitmask(32824) === 0o070); // (---rwx---)
|
|
12
|
-
assert(bitmask(32772) === 0o004); // (------r--)
|
|
13
|
-
assert(bitmask(32774) === 0o006); // (------rw-)
|
|
14
|
-
assert(bitmask(32775) === 0o007); // (------rwx)
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it(`Negative: Throw an exception if the argument is 'null' type`, () => {
|
|
18
|
-
assert.throws(() => {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
bitmask(null);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
package/test/chmod.spec.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import Chance from 'chance';
|
|
4
|
-
import { expect } from 'expect';
|
|
5
|
-
import { fmock, restore } from './__fmock';
|
|
6
|
-
import { pfs, bitmask } from '../src';
|
|
7
|
-
|
|
8
|
-
describe('chmod(src, mode [, options])', () => {
|
|
9
|
-
const chance = new Chance();
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
fmock({
|
|
13
|
-
'./tmpdir/tings.txt': {
|
|
14
|
-
type: 'file',
|
|
15
|
-
data: chance.string()
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
restore('./tmpdir');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
it('Positive: Changes directory and file permissions', async () => {
|
|
26
|
-
await pfs.chmod('./tmpdir', 0o744);
|
|
27
|
-
|
|
28
|
-
const { mode } = fs.lstatSync('./tmpdir/tings.txt');
|
|
29
|
-
const umask = bitmask(mode);
|
|
30
|
-
|
|
31
|
-
assert(umask === 0o744);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
it('Negative: Throw if not exists resource', async () => {
|
|
36
|
-
await expect(async () => {
|
|
37
|
-
await pfs.chmod('./non-existent-source', 0o744);
|
|
38
|
-
})
|
|
39
|
-
.rejects
|
|
40
|
-
.toThrow();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
it(`[sync] Positive: Changes permissions of directory`, () => {
|
|
45
|
-
pfs.chmod('./tmpdir', 0o744, {
|
|
46
|
-
sync: true
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const { mode } = fs.lstatSync('./tmpdir');
|
|
50
|
-
const umask = bitmask(mode);
|
|
51
|
-
|
|
52
|
-
assert(umask === 0o744);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
it(`[sync] Positive: Changes file permissions`, () => {
|
|
57
|
-
pfs.chmod('./tmpdir', 0o744, {
|
|
58
|
-
sync: true
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const { mode } = fs.lstatSync('./tmpdir/tings.txt');
|
|
62
|
-
const umask = bitmask(mode);
|
|
63
|
-
|
|
64
|
-
assert(umask === 0o744);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
it('[sync] Negative: Throw if not exists resource', () => {
|
|
69
|
-
const guid = chance.guid();
|
|
70
|
-
|
|
71
|
-
assert.throws(() => {
|
|
72
|
-
pfs.chmod(`./${guid}`, 0o744, {
|
|
73
|
-
sync: true
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
package/test/chown.spec.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import Chance from 'chance';
|
|
4
|
-
import { expect } from 'expect';
|
|
5
|
-
import { fmock, restore } from './__fmock';
|
|
6
|
-
import { pfs } from '../src';
|
|
7
|
-
|
|
8
|
-
describe('chown(src, [, options])', () => {
|
|
9
|
-
const chance = new Chance();
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
fmock({
|
|
13
|
-
'./tmpdir/tings.txt': {
|
|
14
|
-
type: 'file',
|
|
15
|
-
data: chance.string()
|
|
16
|
-
},
|
|
17
|
-
'./tmpdir/digest/': { type: 'directory' }
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
restore('./tmpdir');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
it('Positive: Changes the permissions of a file', async () => {
|
|
27
|
-
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
28
|
-
await pfs.chown('./tmpdir/tings.txt', { uid, gid });
|
|
29
|
-
|
|
30
|
-
assert(uid && gid);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
it('Positive: Changes the permissions of a directory', async () => {
|
|
35
|
-
const { uid, gid } = fs.statSync('./tmpdir/digest');
|
|
36
|
-
await pfs.chown('./tmpdir/digest', { uid, gid });
|
|
37
|
-
|
|
38
|
-
assert(uid && gid);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
it('Negative: To a non-existent resource to return an Error', async () => {
|
|
43
|
-
const guid = chance.guid();
|
|
44
|
-
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
45
|
-
|
|
46
|
-
await expect(async () => {
|
|
47
|
-
await pfs.chown(`./tmpdir/${guid}`, { uid, gid });
|
|
48
|
-
})
|
|
49
|
-
.rejects
|
|
50
|
-
.toThrow();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
it('[sync] Positive: Changes the permissions of a file', () => {
|
|
55
|
-
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
56
|
-
|
|
57
|
-
pfs.chown('./tmpdir/tings.txt', {
|
|
58
|
-
sync: true,
|
|
59
|
-
uid,
|
|
60
|
-
gid
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
assert(uid && gid);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
it('[sync] Positive: Changes the permissions of a directory', () => {
|
|
68
|
-
const { uid, gid } = fs.statSync('./tmpdir/digest');
|
|
69
|
-
|
|
70
|
-
pfs.chown('./tmpdir/digest', {
|
|
71
|
-
sync: true,
|
|
72
|
-
uid,
|
|
73
|
-
gid
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
assert(uid && gid);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
it('[sync] Negative: To a non-existent resource to return an Error', () => {
|
|
81
|
-
const guid = chance.guid();
|
|
82
|
-
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
83
|
-
|
|
84
|
-
assert.throws(() => {
|
|
85
|
-
pfs.chown(`./tmpdir/${guid}`, {
|
|
86
|
-
sync: true,
|
|
87
|
-
uid,
|
|
88
|
-
gid
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
package/test/constructor.spec.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import { PoweredFileSystem } from '../src';
|
|
3
|
-
|
|
4
|
-
describe('#constructor: new PoweredFileSystem(pwd?)', () => {
|
|
5
|
-
it('Positive: An empty path must match the context of the cwd', () => {
|
|
6
|
-
const { pwd } = new PoweredFileSystem();
|
|
7
|
-
assert(pwd === process.cwd());
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
it('Positive: Absolute path must match the context of the pwd', () => {
|
|
12
|
-
const { pwd } = new PoweredFileSystem(__dirname);
|
|
13
|
-
assert(pwd === __dirname);
|
|
14
|
-
});
|
|
15
|
-
});
|
package/test/copy.spec.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import Chance from 'chance';
|
|
4
|
-
import { expect } from 'expect';
|
|
5
|
-
import { fmock, restore } from './__fmock';
|
|
6
|
-
import { pfs } from '../src';
|
|
7
|
-
|
|
8
|
-
describe('copy(src, dir [, options])', () => {
|
|
9
|
-
const chance = new Chance();
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
fmock({
|
|
13
|
-
'./tmpdir/tings.txt': {
|
|
14
|
-
type: 'file',
|
|
15
|
-
data: chance.string()
|
|
16
|
-
},
|
|
17
|
-
'./tmpdir/digest/': { type: 'directory' }
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
restore('./tmpdir');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('Positive: Copying a item file', async () => {
|
|
26
|
-
await pfs.copy('./tmpdir/tings.txt', './tmpdir/digest');
|
|
27
|
-
const exist = fs.existsSync(`./tmpdir/digest/tings.txt`);
|
|
28
|
-
|
|
29
|
-
assert(exist);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
it('Positive: Recursive copying a directory', async () => {
|
|
34
|
-
await pfs.copy('./src', './tmpdir');
|
|
35
|
-
const exist = fs.existsSync(`./tmpdir/src`);
|
|
36
|
-
|
|
37
|
-
assert(exist);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
it('Negative: Throw if not exists resource', async () => {
|
|
42
|
-
const guid = chance.guid();
|
|
43
|
-
|
|
44
|
-
await expect(async () => {
|
|
45
|
-
await pfs.copy(`./${guid}`, '.');
|
|
46
|
-
})
|
|
47
|
-
.rejects
|
|
48
|
-
.toThrow();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
|
|
53
|
-
await expect(async () => {
|
|
54
|
-
await pfs.copy('./tmpdir', '.');
|
|
55
|
-
})
|
|
56
|
-
.rejects
|
|
57
|
-
.toThrow();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
it('[sync] Positive: Copying a file', () => {
|
|
62
|
-
pfs.copy('./tmpdir/tings.txt', './tmpdir/digest', {
|
|
63
|
-
sync: true
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const exist = fs.existsSync(`./tmpdir/digest/tings.txt`);
|
|
67
|
-
|
|
68
|
-
assert(exist);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
it('[sync] Positive: Recursive copying a directory', () => {
|
|
73
|
-
pfs.copy('./src', './tmpdir', {
|
|
74
|
-
sync: true
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const exist = fs.existsSync(`./tmpdir/src`);
|
|
78
|
-
|
|
79
|
-
assert(exist);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
it('[sync] Negative: Throw if not exists resource', () => {
|
|
84
|
-
const guid = chance.guid();
|
|
85
|
-
|
|
86
|
-
assert.throws(() => {
|
|
87
|
-
pfs.copy(`./${guid}`, '.', {
|
|
88
|
-
sync: true
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
it('[sync] Negative: An attempt to copy to an existing resource should return an Error', () => {
|
|
95
|
-
assert.throws(() => {
|
|
96
|
-
pfs.copy('./tmpdir', '.', {
|
|
97
|
-
sync: true
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|