pwd-fs 3.1.4 → 3.2.1
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/src/bitmask.d.ts +1 -0
- package/dist/src/bitmask.js +18 -0
- package/{lib → dist}/src/powered-file-system.d.ts +20 -3
- package/{lib → dist}/src/powered-file-system.js +39 -41
- package/dist/src/recurse-io-sync.d.ts +5 -0
- package/{lib → dist}/src/recurse-io-sync.js +28 -23
- package/dist/src/recurse-io.d.ts +7 -0
- package/{lib → dist}/src/recurse-io.js +15 -10
- package/package.json +5 -5
- package/readme.md +4 -4
- package/src/bitmask.ts +20 -0
- package/src/powered-file-system.ts +48 -52
- package/src/recurse-io-sync.ts +24 -24
- package/src/recurse-io.ts +18 -19
- package/test/chown.spec.ts +16 -10
- package/tsconfig.json +2 -2
- package/lib/src/recurse-io-sync.d.ts +0 -13
- package/lib/src/recurse-io.d.ts +0 -17
- package/lib/test/__fmock.d.ts +0 -5
- package/lib/test/__fmock.js +0 -40
- package/lib/test/append.spec.d.ts +0 -1
- package/lib/test/append.spec.js +0 -58
- package/lib/test/bitmask.spec.d.ts +0 -1
- package/lib/test/bitmask.spec.js +0 -26
- package/lib/test/chmod.spec.d.ts +0 -1
- package/lib/test/chmod.spec.js +0 -62
- package/lib/test/chown.spec.d.ts +0 -1
- package/lib/test/chown.spec.js +0 -68
- package/lib/test/constructor.spec.d.ts +0 -1
- package/lib/test/constructor.spec.js +0 -17
- package/lib/test/copy.spec.d.ts +0 -1
- package/lib/test/copy.spec.js +0 -80
- package/lib/test/mkdir.spec.d.ts +0 -1
- package/lib/test/mkdir.spec.js +0 -90
- package/lib/test/read.spec.d.ts +0 -1
- package/lib/test/read.spec.js +0 -73
- package/lib/test/readdir.spec.d.ts +0 -1
- package/lib/test/readdir.spec.js +0 -70
- package/lib/test/remove.spec.d.ts +0 -1
- package/lib/test/remove.spec.js +0 -63
- package/lib/test/rename.spec.d.ts +0 -1
- package/lib/test/rename.spec.js +0 -66
- package/lib/test/stat.spec.d.ts +0 -1
- package/lib/test/stat.spec.js +0 -76
- package/lib/test/symlink.spec.d.ts +0 -1
- package/lib/test/symlink.spec.js +0 -74
- package/lib/test/test.spec.d.ts +0 -1
- package/lib/test/test.spec.js +0 -60
- package/lib/test/write.spec.d.ts +0 -1
- package/lib/test/write.spec.js +0 -82
- /package/{lib → dist}/src/index.d.ts +0 -0
- /package/{lib → dist}/src/index.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bitmask(mode: number): number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bitmask = void 0;
|
|
4
|
+
function bitmask(mode) {
|
|
5
|
+
const type = typeof mode;
|
|
6
|
+
if (type !== 'number') {
|
|
7
|
+
throw new Error(`Argument of type '${type}' is not assignable to parameter of type 'number'.`);
|
|
8
|
+
}
|
|
9
|
+
const permissions = [0o400, 0o200, 0o100, 0o040, 0o020, 0o010, 0o004, 0o002, 0o001];
|
|
10
|
+
let umask = 0o000;
|
|
11
|
+
for (const flag of permissions) {
|
|
12
|
+
if (mode & flag) {
|
|
13
|
+
umask += flag;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return umask;
|
|
17
|
+
}
|
|
18
|
+
exports.bitmask = bitmask;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import fs from 'node:fs';
|
|
4
|
+
import { bitmask } from './bitmask';
|
|
4
5
|
export type Mode = keyof IConstants;
|
|
5
6
|
export type Flag = Mode | 'a';
|
|
6
7
|
export type Stats = fs.Stats;
|
|
8
|
+
export * from './bitmask';
|
|
7
9
|
export interface IConstants {
|
|
8
10
|
e: number;
|
|
9
11
|
r: number;
|
|
10
12
|
w: number;
|
|
11
13
|
x: number;
|
|
12
14
|
}
|
|
13
|
-
export declare function bitmask(mode: number): number;
|
|
14
15
|
export declare class PoweredFileSystem {
|
|
15
16
|
readonly pwd: string;
|
|
16
17
|
readonly constants: IConstants;
|
|
@@ -37,11 +38,15 @@ export declare class PoweredFileSystem {
|
|
|
37
38
|
chmod(src: string, mode: number, options?: {
|
|
38
39
|
sync?: false;
|
|
39
40
|
}): Promise<void>;
|
|
40
|
-
chown(src: string,
|
|
41
|
+
chown(src: string, options: {
|
|
41
42
|
sync: true;
|
|
43
|
+
uid?: number;
|
|
44
|
+
gid?: number;
|
|
42
45
|
}): void;
|
|
43
|
-
chown(src: string,
|
|
46
|
+
chown(src: string, options?: {
|
|
44
47
|
sync?: false;
|
|
48
|
+
uid?: number;
|
|
49
|
+
gid?: number;
|
|
45
50
|
}): Promise<void>;
|
|
46
51
|
symlink(src: string, use: string, options: {
|
|
47
52
|
sync: true;
|
|
@@ -113,24 +118,36 @@ export declare class PoweredFileSystem {
|
|
|
113
118
|
umask?: number;
|
|
114
119
|
flag?: Flag;
|
|
115
120
|
}): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated The method should not be used
|
|
123
|
+
*/
|
|
116
124
|
append(src: string, data: Buffer, options: {
|
|
117
125
|
sync: true;
|
|
118
126
|
encoding: null;
|
|
119
127
|
umask?: number;
|
|
120
128
|
flag?: Flag;
|
|
121
129
|
}): void;
|
|
130
|
+
/**
|
|
131
|
+
* @deprecated The method should not be used
|
|
132
|
+
*/
|
|
122
133
|
append(src: string, data: string, options: {
|
|
123
134
|
sync: true;
|
|
124
135
|
encoding?: BufferEncoding;
|
|
125
136
|
umask?: number;
|
|
126
137
|
flag?: Flag;
|
|
127
138
|
}): void;
|
|
139
|
+
/**
|
|
140
|
+
* @deprecated The method should not be used
|
|
141
|
+
*/
|
|
128
142
|
append(src: string, data: Buffer, options: {
|
|
129
143
|
sync?: false;
|
|
130
144
|
encoding: null;
|
|
131
145
|
umask?: number;
|
|
132
146
|
flag?: Flag;
|
|
133
147
|
}): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* @deprecated The method should not be used
|
|
150
|
+
*/
|
|
134
151
|
append(src: string, data: string, options?: {
|
|
135
152
|
sync?: false;
|
|
136
153
|
encoding?: BufferEncoding;
|
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
5
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PoweredFileSystem =
|
|
20
|
+
exports.PoweredFileSystem = void 0;
|
|
7
21
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
22
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const recurse_io_1 =
|
|
10
|
-
const recurse_io_sync_1 =
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
0o200, // OWNER_WRITE
|
|
14
|
-
0o100, // OWNER_EXECUTE
|
|
15
|
-
0o040, // GROUP_READ
|
|
16
|
-
0o020, // GROUP_WRITE
|
|
17
|
-
0o010, // GROUP_EXECUTE
|
|
18
|
-
0o004, // OTHERS_READ
|
|
19
|
-
0o002, // OTHERS_WRITE
|
|
20
|
-
0o001 // OTHERS_EXECUTE
|
|
21
|
-
];
|
|
22
|
-
function bitmask(mode) {
|
|
23
|
-
const type = typeof mode;
|
|
24
|
-
if (type !== 'number') {
|
|
25
|
-
throw new Error(`Argument of type '${type}' is not assignable to parameter of type 'number'.`);
|
|
26
|
-
}
|
|
27
|
-
let umask = 0o000;
|
|
28
|
-
for (const flag of permissions) {
|
|
29
|
-
if (mode & flag) {
|
|
30
|
-
umask += flag;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return umask;
|
|
34
|
-
}
|
|
35
|
-
exports.bitmask = bitmask;
|
|
23
|
+
const recurse_io_1 = require("./recurse-io");
|
|
24
|
+
const recurse_io_sync_1 = require("./recurse-io-sync");
|
|
25
|
+
const bitmask_1 = require("./bitmask");
|
|
26
|
+
__exportStar(require("./bitmask"), exports);
|
|
36
27
|
class PoweredFileSystem {
|
|
37
28
|
pwd;
|
|
38
29
|
constants = {
|
|
@@ -41,7 +32,7 @@ class PoweredFileSystem {
|
|
|
41
32
|
w: node_fs_1.default.constants.W_OK,
|
|
42
33
|
x: node_fs_1.default.constants.X_OK
|
|
43
34
|
};
|
|
44
|
-
static bitmask = bitmask;
|
|
35
|
+
static bitmask = bitmask_1.bitmask;
|
|
45
36
|
constructor(pwd) {
|
|
46
37
|
this.pwd = pwd ? node_path_1.default.resolve(pwd) : process.cwd();
|
|
47
38
|
}
|
|
@@ -80,10 +71,10 @@ class PoweredFileSystem {
|
|
|
80
71
|
chmod(src, mode, { sync = false } = {}) {
|
|
81
72
|
src = this.resolve(src);
|
|
82
73
|
if (sync) {
|
|
83
|
-
return recurse_io_sync_1.
|
|
74
|
+
return (0, recurse_io_sync_1.chmodSync)(src, mode);
|
|
84
75
|
}
|
|
85
76
|
return new Promise((resolve, reject) => {
|
|
86
|
-
recurse_io_1.
|
|
77
|
+
(0, recurse_io_1.chmod)(src, mode, (err) => {
|
|
87
78
|
if (err) {
|
|
88
79
|
return reject(err);
|
|
89
80
|
}
|
|
@@ -91,13 +82,13 @@ class PoweredFileSystem {
|
|
|
91
82
|
});
|
|
92
83
|
});
|
|
93
84
|
}
|
|
94
|
-
chown(src,
|
|
85
|
+
chown(src, { sync = false, uid = 0, gid = 0 } = {}) {
|
|
95
86
|
src = this.resolve(src);
|
|
96
87
|
if (sync) {
|
|
97
|
-
return recurse_io_sync_1.
|
|
88
|
+
return (0, recurse_io_sync_1.chownSync)(src, uid, gid);
|
|
98
89
|
}
|
|
99
90
|
return new Promise((resolve, reject) => {
|
|
100
|
-
recurse_io_1.
|
|
91
|
+
(0, recurse_io_1.chown)(src, uid, gid, (err) => {
|
|
101
92
|
if (err) {
|
|
102
93
|
return reject(err);
|
|
103
94
|
}
|
|
@@ -124,10 +115,10 @@ class PoweredFileSystem {
|
|
|
124
115
|
src = this.resolve(src);
|
|
125
116
|
dir = this.resolve(dir);
|
|
126
117
|
if (sync) {
|
|
127
|
-
return recurse_io_sync_1.
|
|
118
|
+
return (0, recurse_io_sync_1.copySync)(src, dir, umask);
|
|
128
119
|
}
|
|
129
120
|
return new Promise((resolve, reject) => {
|
|
130
|
-
recurse_io_1.
|
|
121
|
+
(0, recurse_io_1.copy)(src, dir, umask, (err) => {
|
|
131
122
|
if (err) {
|
|
132
123
|
return reject(err);
|
|
133
124
|
}
|
|
@@ -153,15 +144,19 @@ class PoweredFileSystem {
|
|
|
153
144
|
remove(src, { sync = false } = {}) {
|
|
154
145
|
src = this.resolve(src);
|
|
155
146
|
if (sync) {
|
|
156
|
-
|
|
147
|
+
(0, recurse_io_sync_1.removeSync)(src);
|
|
157
148
|
}
|
|
158
149
|
return new Promise((resolve, reject) => {
|
|
159
|
-
|
|
150
|
+
const callback = (err) => {
|
|
160
151
|
if (err) {
|
|
161
152
|
return reject(err);
|
|
162
153
|
}
|
|
163
154
|
resolve();
|
|
164
|
-
}
|
|
155
|
+
};
|
|
156
|
+
if ('rm' in node_fs_1.default) {
|
|
157
|
+
return node_fs_1.default.rm(src, { recursive: true }, callback);
|
|
158
|
+
}
|
|
159
|
+
(0, recurse_io_1.remove)(src, callback);
|
|
165
160
|
});
|
|
166
161
|
}
|
|
167
162
|
read(src, { sync = false, encoding = 'utf8', flag = 'r' } = {}) {
|
|
@@ -207,6 +202,9 @@ class PoweredFileSystem {
|
|
|
207
202
|
});
|
|
208
203
|
});
|
|
209
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated The method should not be used
|
|
207
|
+
*/
|
|
210
208
|
append(src, data, { sync = false, encoding = 'utf8', umask = 0o000, flag = 'a' } = {}) {
|
|
211
209
|
src = this.resolve(src);
|
|
212
210
|
const mode = 0o666 - umask;
|
|
@@ -249,10 +247,10 @@ class PoweredFileSystem {
|
|
|
249
247
|
mkdir(dir, { umask = 0o000, sync = false } = {}) {
|
|
250
248
|
dir = this.resolve(dir);
|
|
251
249
|
if (sync) {
|
|
252
|
-
return recurse_io_sync_1.
|
|
250
|
+
return (0, recurse_io_sync_1.mkdirSync)(dir, umask);
|
|
253
251
|
}
|
|
254
252
|
return new Promise((resolve, reject) => {
|
|
255
|
-
recurse_io_1.
|
|
253
|
+
(0, recurse_io_1.mkdir)(dir, umask, (err) => {
|
|
256
254
|
if (err) {
|
|
257
255
|
return reject(err);
|
|
258
256
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function chmodSync(src: string, mode: number): void;
|
|
2
|
+
export declare function chownSync(src: string, uid: number, gid: number): void;
|
|
3
|
+
export declare function copySync(src: string, dir: string, umask: number): void;
|
|
4
|
+
export declare function removeSync(src: string): void;
|
|
5
|
+
export declare function mkdirSync(dir: string, umask: number): void;
|
|
@@ -3,30 +3,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mkdirSync = exports.removeSync = exports.copySync = exports.chownSync = exports.chmodSync = void 0;
|
|
6
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const { sep } = node_path_1.default;
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
10
|
+
function chmodSync(src, mode) {
|
|
11
|
+
const stats = node_fs_1.default.statSync(src);
|
|
12
|
+
if (stats.isDirectory()) {
|
|
12
13
|
const list = node_fs_1.default.readdirSync(src);
|
|
13
14
|
for (const loc of list) {
|
|
14
|
-
|
|
15
|
+
chmodSync(`${src}${sep}${loc}`, mode);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
node_fs_1.default.chmodSync(src, mode);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
exports.chmodSync = chmodSync;
|
|
21
|
+
function chownSync(src, uid, gid) {
|
|
22
|
+
const stats = node_fs_1.default.statSync(src);
|
|
23
|
+
if (uid === 0) {
|
|
24
|
+
uid = stats.uid;
|
|
25
|
+
}
|
|
26
|
+
if (gid === 0) {
|
|
27
|
+
gid = stats.gid;
|
|
28
|
+
}
|
|
29
|
+
if (stats.isDirectory()) {
|
|
22
30
|
const list = node_fs_1.default.readdirSync(src);
|
|
23
31
|
for (const loc of list) {
|
|
24
|
-
|
|
32
|
+
chownSync(`${src}${sep}${loc}`, uid, gid);
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
node_fs_1.default.chownSync(src, uid, gid);
|
|
28
36
|
}
|
|
29
|
-
|
|
37
|
+
exports.chownSync = chownSync;
|
|
38
|
+
function copySync(src, dir, umask) {
|
|
30
39
|
const stat = node_fs_1.default.statSync(src);
|
|
31
40
|
if (stat.isDirectory()) {
|
|
32
41
|
const list = node_fs_1.default.readdirSync(src);
|
|
@@ -36,7 +45,7 @@ function copy(src, dir, umask) {
|
|
|
36
45
|
dir = `${dir}${sep}${loc}`;
|
|
37
46
|
node_fs_1.default.mkdirSync(dir, mode);
|
|
38
47
|
for (const loc of list) {
|
|
39
|
-
|
|
48
|
+
copySync(`${src}${sep}${loc}`, dir, umask);
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
else {
|
|
@@ -45,12 +54,13 @@ function copy(src, dir, umask) {
|
|
|
45
54
|
node_fs_1.default.copyFileSync(src, use);
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
exports.copySync = copySync;
|
|
58
|
+
function removeSync(src) {
|
|
59
|
+
const stats = node_fs_1.default.statSync(src);
|
|
60
|
+
if (stats.isDirectory()) {
|
|
51
61
|
const list = node_fs_1.default.readdirSync(src);
|
|
52
62
|
for (const loc of list) {
|
|
53
|
-
|
|
63
|
+
removeSync(`${src}${sep}${loc}`);
|
|
54
64
|
}
|
|
55
65
|
node_fs_1.default.rmdirSync(src);
|
|
56
66
|
}
|
|
@@ -58,13 +68,14 @@ function remove(src) {
|
|
|
58
68
|
node_fs_1.default.unlinkSync(src);
|
|
59
69
|
}
|
|
60
70
|
}
|
|
61
|
-
|
|
71
|
+
exports.removeSync = removeSync;
|
|
72
|
+
function mkdirSync(dir, umask) {
|
|
62
73
|
const mode = 0o777 - umask;
|
|
63
74
|
const cwd = process.cwd();
|
|
64
75
|
let use = '';
|
|
65
76
|
if (dir.indexOf(cwd) === 0) {
|
|
66
77
|
use = cwd;
|
|
67
|
-
dir = dir.
|
|
78
|
+
dir = dir.substring(cwd.length);
|
|
68
79
|
}
|
|
69
80
|
const ways = dir.split(sep).slice(1);
|
|
70
81
|
for (const loc of ways) {
|
|
@@ -79,10 +90,4 @@ function mkdir(dir, umask) {
|
|
|
79
90
|
}
|
|
80
91
|
}
|
|
81
92
|
}
|
|
82
|
-
exports.
|
|
83
|
-
chmod,
|
|
84
|
-
chown,
|
|
85
|
-
copy,
|
|
86
|
-
remove,
|
|
87
|
-
mkdir
|
|
88
|
-
};
|
|
93
|
+
exports.mkdirSync = mkdirSync;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { NoParamCallback } from 'node:fs';
|
|
3
|
+
export declare function chmod(src: string, mode: number, callback: NoParamCallback): void;
|
|
4
|
+
export declare function chown(src: string, uid: number, gid: number, callback: NoParamCallback): void;
|
|
5
|
+
export declare function copy(src: string, dir: string, umask: number, callback: NoParamCallback): void;
|
|
6
|
+
export declare function remove(src: string, callback: NoParamCallback): void;
|
|
7
|
+
export declare function mkdir(dir: string, umask: number, callback: NoParamCallback): void;
|
|
@@ -3,16 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mkdir = exports.remove = exports.copy = exports.chown = exports.chmod = void 0;
|
|
6
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const { sep } = node_path_1.default;
|
|
9
10
|
function chmod(src, mode, callback) {
|
|
10
11
|
let reduce = 0;
|
|
11
|
-
node_fs_1.default.stat(src, (err,
|
|
12
|
+
node_fs_1.default.stat(src, (err, stats) => {
|
|
12
13
|
if (err) {
|
|
13
14
|
return callback(err);
|
|
14
15
|
}
|
|
15
|
-
if (
|
|
16
|
+
if (stats.isDirectory()) {
|
|
16
17
|
node_fs_1.default.readdir(src, (err, list) => {
|
|
17
18
|
if (err) {
|
|
18
19
|
return callback(err);
|
|
@@ -38,12 +39,19 @@ function 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) {
|
|
@@ -70,6 +78,7 @@ function 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) => {
|
|
@@ -122,6 +131,7 @@ 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) {
|
|
@@ -153,6 +163,7 @@ function remove(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) {
|
|
@@ -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,10 +194,4 @@ function mkdir(dir, umask, callback) {
|
|
|
183
194
|
iter.next();
|
|
184
195
|
iter.next(iter);
|
|
185
196
|
}
|
|
186
|
-
exports.
|
|
187
|
-
chmod,
|
|
188
|
-
chown,
|
|
189
|
-
copy,
|
|
190
|
-
remove,
|
|
191
|
-
mkdir
|
|
192
|
-
};
|
|
197
|
+
exports.mkdir = mkdir;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pwd-fs",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Extend the file system the capabilities of declaring the present working directory and recursive execution",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"umask",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
|
-
"url": "
|
|
27
|
+
"url": "git@github.com:woodger/pwd-fs.git"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=13.2.0"
|
|
31
31
|
},
|
|
32
|
-
"main": "./
|
|
33
|
-
"types": "./
|
|
32
|
+
"main": "./dist/src/index.js",
|
|
33
|
+
"types": "./dist/src/index.d.ts",
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsc",
|
|
36
|
-
"test": "mocha ./
|
|
36
|
+
"test": "mocha ./dist/test"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/chance": "^1.1.6",
|
package/readme.md
CHANGED
|
@@ -47,7 +47,7 @@ The scope `URI` of the class methods are divided into groups.
|
|
|
47
47
|
| URI | Methods |
|
|
48
48
|
|-----------------------------|------------------------------------------------------------------|
|
|
49
49
|
| Common (file and directory) | `chmod` `chown` `copy` `remove` `rename` `symlink` `stat` `test` |
|
|
50
|
-
| File only | `read` `write`
|
|
50
|
+
| File only | `read` `write` |
|
|
51
51
|
| Directory only | `mkdir` `readdir` |
|
|
52
52
|
|
|
53
53
|
|
|
@@ -151,13 +151,13 @@ console.log(bitmask(mode) === 0o750); // true
|
|
|
151
151
|
|
|
152
152
|
See manuals [chmod(2)](http://man7.org/linux/man-pages/man2/chmod.2.html)
|
|
153
153
|
|
|
154
|
-
#### pfs.chown(src,
|
|
154
|
+
#### pfs.chown(src, [, options])
|
|
155
155
|
|
|
156
156
|
- `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths will be resolved relative to the present working directory as specified by `pfs.pwd`.
|
|
157
|
-
- `uid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>
|
|
158
|
-
- `gid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>
|
|
159
157
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
160
158
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
159
|
+
- `uid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> The file's new owner's user id.
|
|
160
|
+
- `gid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> The file's new group's group id.
|
|
161
161
|
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful change, the `Promise` is resolved with an value with a `undefined`.
|
|
162
162
|
|
|
163
163
|
Asynchronously changes owner and group of a file.
|
package/src/bitmask.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function bitmask(mode: number) {
|
|
2
|
+
const type = typeof mode;
|
|
3
|
+
|
|
4
|
+
if (type !== 'number') {
|
|
5
|
+
throw new Error(
|
|
6
|
+
`Argument of type '${type}' is not assignable to parameter of type 'number'.`
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const permissions: number[] = [ 0o400, 0o200, 0o100, 0o040, 0o020, 0o010, 0o004, 0o002, 0o001 ];
|
|
11
|
+
let umask = 0o000;
|
|
12
|
+
|
|
13
|
+
for (const flag of permissions) {
|
|
14
|
+
if (mode & flag) {
|
|
15
|
+
umask += flag;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return umask;
|
|
20
|
+
}
|