@ohos-ports/stdlib-process 0.0.0-stage → 0.4.1-beta.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/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +220 -2
- package/SECURITY.md +5 -0
- package/argv/README.md +104 -0
- package/argv/docs/repl.txt +22 -0
- package/argv/docs/types/index.d.ts +33 -0
- package/argv/docs/types/test.ts +28 -0
- package/argv/lib/browser.js +28 -0
- package/argv/lib/index.js +40 -0
- package/argv/lib/main.js +43 -0
- package/argv/package.json +70 -0
- package/chdir/README.md +124 -0
- package/chdir/docs/repl.txt +25 -0
- package/chdir/docs/types/index.d.ts +42 -0
- package/chdir/docs/types/test.ts +45 -0
- package/chdir/lib/index.js +42 -0
- package/chdir/lib/main.js +52 -0
- package/chdir/lib/polyfill.js +42 -0
- package/chdir/package.json +73 -0
- package/cwd/README.md +140 -0
- package/cwd/bin/cli +60 -0
- package/cwd/docs/repl.txt +17 -0
- package/cwd/docs/types/index.d.ts +35 -0
- package/cwd/docs/types/test.ts +33 -0
- package/cwd/docs/usage.txt +8 -0
- package/cwd/etc/cli_opts.json +14 -0
- package/cwd/lib/index.js +40 -0
- package/cwd/lib/main.js +44 -0
- package/cwd/lib/polyfill.js +40 -0
- package/cwd/package.json +75 -0
- package/docs/types/index.d.ts +225 -0
- package/env/README.md +104 -0
- package/env/docs/repl.txt +12 -0
- package/env/docs/types/index.d.ts +32 -0
- package/env/docs/types/test.ts +28 -0
- package/env/lib/browser.js +28 -0
- package/env/lib/index.js +39 -0
- package/env/lib/main.js +42 -0
- package/env/package.json +72 -0
- package/exec-path/README.md +90 -0
- package/exec-path/docs/repl.txt +13 -0
- package/exec-path/docs/types/index.d.ts +36 -0
- package/exec-path/docs/types/test.ts +28 -0
- package/exec-path/lib/browser.js +23 -0
- package/exec-path/lib/index.js +55 -0
- package/exec-path/lib/main.js +46 -0
- package/exec-path/package.json +72 -0
- package/getegid/README.md +107 -0
- package/getegid/docs/repl.txt +20 -0
- package/getegid/docs/types/index.d.ts +38 -0
- package/getegid/docs/types/test.ts +33 -0
- package/getegid/lib/index.js +39 -0
- package/getegid/lib/main.js +45 -0
- package/getegid/lib/native.js +44 -0
- package/getegid/lib/polyfill.js +40 -0
- package/getegid/package.json +76 -0
- package/geteuid/README.md +111 -0
- package/geteuid/docs/repl.txt +20 -0
- package/geteuid/docs/types/index.d.ts +38 -0
- package/geteuid/docs/types/test.ts +33 -0
- package/geteuid/lib/index.js +39 -0
- package/geteuid/lib/main.js +45 -0
- package/geteuid/lib/native.js +44 -0
- package/geteuid/lib/polyfill.js +40 -0
- package/geteuid/package.json +76 -0
- package/getgid/README.md +107 -0
- package/getgid/docs/repl.txt +19 -0
- package/getgid/docs/types/index.d.ts +38 -0
- package/getgid/docs/types/test.ts +33 -0
- package/getgid/lib/index.js +39 -0
- package/getgid/lib/main.js +45 -0
- package/getgid/lib/native.js +44 -0
- package/getgid/lib/polyfill.js +40 -0
- package/getgid/package.json +75 -0
- package/getuid/README.md +111 -0
- package/getuid/docs/repl.txt +19 -0
- package/getuid/docs/types/index.d.ts +38 -0
- package/getuid/docs/types/test.ts +33 -0
- package/getuid/lib/index.js +39 -0
- package/getuid/lib/main.js +45 -0
- package/getuid/lib/native.js +44 -0
- package/getuid/lib/polyfill.js +40 -0
- package/getuid/package.json +75 -0
- package/lib/index.js +150 -0
- package/node-version/README.md +135 -0
- package/node-version/bin/cli +60 -0
- package/node-version/docs/repl.txt +12 -0
- package/node-version/docs/types/index.d.ts +42 -0
- package/node-version/docs/types/test.ts +28 -0
- package/node-version/docs/usage.txt +8 -0
- package/node-version/etc/cli_opts.json +14 -0
- package/node-version/lib/browser.js +23 -0
- package/node-version/lib/index.js +60 -0
- package/node-version/lib/main.js +43 -0
- package/node-version/lib/process.js +28 -0
- package/node-version/package.json +73 -0
- package/package.json +121 -4
- package/read-stdin/README.md +152 -0
- package/read-stdin/docs/types/index.d.ts +108 -0
- package/read-stdin/docs/types/test.ts +73 -0
- package/read-stdin/lib/browser.js +66 -0
- package/read-stdin/lib/index.js +47 -0
- package/read-stdin/lib/main.js +159 -0
- package/read-stdin/package.json +67 -0
- package/umask/README.md +281 -0
- package/umask/bin/cli +84 -0
- package/umask/docs/repl.txt +133 -0
- package/umask/docs/types/index.d.ts +69 -0
- package/umask/docs/types/test.ts +62 -0
- package/umask/docs/usage.txt +9 -0
- package/umask/etc/cli_opts.json +22 -0
- package/umask/lib/browser.js +133 -0
- package/umask/lib/from_symbolic.js +218 -0
- package/umask/lib/index.js +40 -0
- package/umask/lib/main.js +128 -0
- package/umask/lib/octal_codes.json +10 -0
- package/umask/lib/to_symbolic.js +57 -0
- package/umask/package.json +78 -0
package/umask/README.md
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2018 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
# umask
|
|
22
|
+
|
|
23
|
+
> Get/set the process mask.
|
|
24
|
+
|
|
25
|
+
<section class="intro">
|
|
26
|
+
|
|
27
|
+
A **mask** is a set of bits, each of which restricts how its corresponding permission is set for newly created files. On POSIX platforms, each file has a set of attributes that control who can read, write, or execute that file. Upon creating a file, file permissions must be set to an initial setting. The process mask restricts those permission settings.
|
|
28
|
+
|
|
29
|
+
If the mask contains a bit set to `1`, the corresponding initial file permission is disabled. If the mask contains a bit set to `0`, the corresponding permission is left to be determined by the requesting process and the system. The process mask is thus a filter that **removes** permissions as a file is created; i.e., each bit set to a `1` removes its corresponding permission.
|
|
30
|
+
|
|
31
|
+
In octal representation, a mask is a four digit number comprised as follows (using `0077` as an example):
|
|
32
|
+
|
|
33
|
+
- `0`: special permissions (setuid, setgid, sticky bit)
|
|
34
|
+
- `0`: (u)ser/owner permissions
|
|
35
|
+
- `7`: (g)roup permissions
|
|
36
|
+
- `7`: (o)thers/non-group permissions
|
|
37
|
+
|
|
38
|
+
Octal codes correspond to the following permissions:
|
|
39
|
+
|
|
40
|
+
- `0`: read, write, execute
|
|
41
|
+
- `1`: read, write
|
|
42
|
+
- `2`: read, execute
|
|
43
|
+
- `3`: read
|
|
44
|
+
- `4`: write, execute
|
|
45
|
+
- `5`: write
|
|
46
|
+
- `6`: execute
|
|
47
|
+
- `7`: no permissions
|
|
48
|
+
|
|
49
|
+
If provided fewer than four digits, the mask is left-padded with zeros. Note, however, that **only** the last three digits (i.e., the file permissions digits) of the mask are actually used when the mask is applied (i.e., `mask & 0777`).
|
|
50
|
+
|
|
51
|
+
Permissions can be represented using the following symbolic form:
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
u=rwx,g=rwx,o=rwx
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
where
|
|
58
|
+
|
|
59
|
+
- **u**: user permissions
|
|
60
|
+
- **g**: group permissions
|
|
61
|
+
- **o**: other/non-group permissions
|
|
62
|
+
- **r**: read
|
|
63
|
+
- **w**: write
|
|
64
|
+
- **x**: execute
|
|
65
|
+
|
|
66
|
+
When setting permissions using symbolic notation, one may use a _mask expression_ of the form:
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
[<classes>]<operator><symbols>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
where `<classes>` may be a combination of
|
|
73
|
+
|
|
74
|
+
- **u**: user
|
|
75
|
+
- **g**: group
|
|
76
|
+
- **o**: other/non-group
|
|
77
|
+
- **a**: all
|
|
78
|
+
|
|
79
|
+
`<symbols>` may be a combination of
|
|
80
|
+
|
|
81
|
+
- **r**: read
|
|
82
|
+
- **w**: write
|
|
83
|
+
- **x**: execute
|
|
84
|
+
- **X**: special execute
|
|
85
|
+
- **s**: setuid/gid on execution
|
|
86
|
+
- **t**: sticky
|
|
87
|
+
|
|
88
|
+
and `<operator>` may be one of
|
|
89
|
+
|
|
90
|
+
- **+**: enable
|
|
91
|
+
- **-**: disable
|
|
92
|
+
- **=**: enable specified and disable unspecified permissions
|
|
93
|
+
|
|
94
|
+
For example,
|
|
95
|
+
|
|
96
|
+
- `u-w`: disable user write permissions
|
|
97
|
+
- `u+w`: enable user write permissions
|
|
98
|
+
- `u=w`: enable user write permissions and disable user read and execute
|
|
99
|
+
|
|
100
|
+
To specify multiple changes, one can specify a comma-separated list of mask expressions. For example,
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
u+rwx,g-x,o=r
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
would enable user read, write, and execute permissions, disable group execute permissions, enable other read permissions, and disable other write and execute permissions.
|
|
107
|
+
|
|
108
|
+
The `a` class indicates "all", which is the same as specifying `ugo`. This is the default class if a class is omitted when specifying permissions. For example, `+x` is equivalent to `a+x` which is equivalent to `ugo+x` which is equivalent to `u+x,g+x,o+x` and enables execution for all classes.
|
|
109
|
+
|
|
110
|
+
</section>
|
|
111
|
+
|
|
112
|
+
<!-- /.intro -->
|
|
113
|
+
|
|
114
|
+
<section class="usage">
|
|
115
|
+
|
|
116
|
+
## Usage
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
var umask = require( '@stdlib/process/umask' );
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### umask( \[mask,] \[options] )
|
|
123
|
+
|
|
124
|
+
Returns the process mask.
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
var mask = umask();
|
|
128
|
+
// returns <number>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
To set the process mask, provide a `mask` argument. When provided a `mask`, the function returns the previous mask value.
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
var mask = umask();
|
|
135
|
+
// returns <number>
|
|
136
|
+
|
|
137
|
+
var prev = umask( 0 );
|
|
138
|
+
// returns <number>
|
|
139
|
+
|
|
140
|
+
var bool = ( prev === mask );
|
|
141
|
+
// returns true
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The `mask` argument may be either an integer value or a `string` representing the mask using symbolic notation.
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
var mask = umask( 'u=rwx,g=rw,o=rw' );
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The function accepts the following `options`:
|
|
151
|
+
|
|
152
|
+
- **symbolic**: `boolean` indicating whether to return the mask in symbolic notation. Default: `false`.
|
|
153
|
+
|
|
154
|
+
To return the process mask in symbolic notation, set the `symbolic` option to `true`.
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
var opts = {
|
|
158
|
+
'symbolic': true
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// Get the mask:
|
|
162
|
+
var mask = umask( opts );
|
|
163
|
+
// e.g., returns 'u=rwx,g=rw,o=rw'
|
|
164
|
+
|
|
165
|
+
// Set the mask:
|
|
166
|
+
mask = umask( 0, opts );
|
|
167
|
+
// e.g., returns 'u=rwx,g=rw,o=rw'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
</section>
|
|
171
|
+
|
|
172
|
+
<!-- /.usage -->
|
|
173
|
+
|
|
174
|
+
<section class="notes">
|
|
175
|
+
|
|
176
|
+
## Notes
|
|
177
|
+
|
|
178
|
+
- To set the process mask using an octal `string` (e.g., `0777`), use `parseInt` to convert the `string` to an integer value.
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
umask( parseInt( '0777', 8 ) );
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
- See [umask(2)][umask].
|
|
185
|
+
|
|
186
|
+
</section>
|
|
187
|
+
|
|
188
|
+
<!-- /.notes -->
|
|
189
|
+
|
|
190
|
+
<section class="examples">
|
|
191
|
+
|
|
192
|
+
## Examples
|
|
193
|
+
|
|
194
|
+
<!-- eslint no-undef: "error" -->
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
var lpad = require( '@stdlib/string/left-pad' );
|
|
198
|
+
var umask = require( '@stdlib/process/umask' );
|
|
199
|
+
|
|
200
|
+
// Print the process mask as an integer:
|
|
201
|
+
var mask = umask();
|
|
202
|
+
console.log( mask.toString() );
|
|
203
|
+
|
|
204
|
+
// Print the process mask as an octal string:
|
|
205
|
+
console.log( lpad( mask.toString(), 4, '0' ) );
|
|
206
|
+
|
|
207
|
+
// Print the process mask using symbolic notation:
|
|
208
|
+
var opts = {
|
|
209
|
+
'symbolic': true
|
|
210
|
+
};
|
|
211
|
+
console.log( umask( opts ) );
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
</section>
|
|
215
|
+
|
|
216
|
+
<!-- /.examples -->
|
|
217
|
+
|
|
218
|
+
* * *
|
|
219
|
+
|
|
220
|
+
<section class="cli">
|
|
221
|
+
|
|
222
|
+
## CLI
|
|
223
|
+
|
|
224
|
+
<section class="usage">
|
|
225
|
+
|
|
226
|
+
### Usage
|
|
227
|
+
|
|
228
|
+
```text
|
|
229
|
+
Usage: umask [options]
|
|
230
|
+
|
|
231
|
+
Options:
|
|
232
|
+
|
|
233
|
+
-h, --help Print this message.
|
|
234
|
+
-V, --version Print the package version.
|
|
235
|
+
-p, --print Print the mask command.
|
|
236
|
+
-S, --symbolic Print the mask using symbolic notation.
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
</section>
|
|
240
|
+
|
|
241
|
+
<!-- /.usage -->
|
|
242
|
+
|
|
243
|
+
<section class="examples">
|
|
244
|
+
|
|
245
|
+
### Examples
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
$ umask
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
To print the mask in command format, set the `-p` flag.
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
$ umask -p
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
</section>
|
|
258
|
+
|
|
259
|
+
<!-- /.examples -->
|
|
260
|
+
|
|
261
|
+
</section>
|
|
262
|
+
|
|
263
|
+
<!-- /.cli -->
|
|
264
|
+
|
|
265
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
266
|
+
|
|
267
|
+
<section class="related">
|
|
268
|
+
|
|
269
|
+
</section>
|
|
270
|
+
|
|
271
|
+
<!-- /.related -->
|
|
272
|
+
|
|
273
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
274
|
+
|
|
275
|
+
<section class="links">
|
|
276
|
+
|
|
277
|
+
[umask]: http://man7.org/linux/man-pages/man2/umask.2.html
|
|
278
|
+
|
|
279
|
+
</section>
|
|
280
|
+
|
|
281
|
+
<!-- /.links -->
|
package/umask/bin/cli
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2018 The Stdlib Authors.
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
'use strict';
|
|
22
|
+
|
|
23
|
+
// MODULES //
|
|
24
|
+
|
|
25
|
+
var resolve = require( 'path' ).resolve;
|
|
26
|
+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
|
|
27
|
+
var CLI = require( '@stdlib/cli/ctor' );
|
|
28
|
+
var lpad = require( '@stdlib/string/left-pad' );
|
|
29
|
+
var umask = require( './../lib' );
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// MAIN //
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Main execution sequence.
|
|
36
|
+
*
|
|
37
|
+
* @private
|
|
38
|
+
* @returns {void}
|
|
39
|
+
*/
|
|
40
|
+
function main() {
|
|
41
|
+
var flags;
|
|
42
|
+
var opts;
|
|
43
|
+
var cli;
|
|
44
|
+
var out;
|
|
45
|
+
|
|
46
|
+
// Create a command-line interface:
|
|
47
|
+
cli = new CLI({
|
|
48
|
+
'pkg': require( './../package.json' ),
|
|
49
|
+
'options': require( './../etc/cli_opts.json' ),
|
|
50
|
+
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
|
|
51
|
+
'encoding': 'utf8'
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Get any provided command-line options:
|
|
56
|
+
flags = cli.flags();
|
|
57
|
+
if ( flags.help || flags.version ) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
opts = {};
|
|
62
|
+
if ( flags.symbolic ) {
|
|
63
|
+
opts.symbolic = flags.symbolic;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Get the process `mask`:
|
|
67
|
+
out = umask( opts );
|
|
68
|
+
|
|
69
|
+
// Print the result:
|
|
70
|
+
if ( opts.symbolic ) {
|
|
71
|
+
out = out.toString();
|
|
72
|
+
if ( flags.print ) {
|
|
73
|
+
return console.log( 'umask -S %s', out ); // eslint-disable-line no-console
|
|
74
|
+
}
|
|
75
|
+
return console.log( out ); // eslint-disable-line no-console
|
|
76
|
+
}
|
|
77
|
+
out = lpad( out.toString( 8 ), 4, '0' );
|
|
78
|
+
if ( flags.print ) {
|
|
79
|
+
return console.log( 'umask %s', out ); // eslint-disable-line no-console
|
|
80
|
+
}
|
|
81
|
+
console.log( out ); // eslint-disable-line no-console
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
main();
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( [mask,] [options] )
|
|
3
|
+
Returns the current process mask, if not provided a mask; otherwise, sets
|
|
4
|
+
the process mask and returns the previous mask.
|
|
5
|
+
|
|
6
|
+
A mask is a set of bits, each of which restricts how its corresponding
|
|
7
|
+
permission is set for newly created files.
|
|
8
|
+
|
|
9
|
+
On POSIX platforms, each file has a set of attributes that control who can
|
|
10
|
+
read, write, or execute that file. Upon creating a file, file permissions
|
|
11
|
+
must be set to an initial setting. The process mask restricts those
|
|
12
|
+
permission settings.
|
|
13
|
+
|
|
14
|
+
If the mask contains a bit set to "1", the corresponding initial file
|
|
15
|
+
permission is disabled. If the mask contains a bit set to "0", the
|
|
16
|
+
corresponding permission is left to be determined by the requesting process
|
|
17
|
+
and the system.
|
|
18
|
+
|
|
19
|
+
The process mask is thus a filter that removes permissions as a file is
|
|
20
|
+
created; i.e., each bit set to a "1" removes its corresponding permission.
|
|
21
|
+
|
|
22
|
+
In octal representation, a mask is a four digit number, e.g., 0077,
|
|
23
|
+
comprised as follows:
|
|
24
|
+
|
|
25
|
+
- 0: special permissions (setuid, setgid, sticky bit)
|
|
26
|
+
- 0: (u)ser/owner permissions
|
|
27
|
+
- 7: (g)roup permissions
|
|
28
|
+
- 7: (o)thers/non-group permissions
|
|
29
|
+
|
|
30
|
+
Octal codes correspond to the following permissions:
|
|
31
|
+
|
|
32
|
+
- 0: read, write, execute
|
|
33
|
+
- 1: read, write
|
|
34
|
+
- 2: read, execute
|
|
35
|
+
- 3: read
|
|
36
|
+
- 4: write, execute
|
|
37
|
+
- 5: write
|
|
38
|
+
- 6: execute
|
|
39
|
+
- 7: no permissions
|
|
40
|
+
|
|
41
|
+
If provided fewer than four digits, the mask is left-padded with zeros.
|
|
42
|
+
|
|
43
|
+
Note, however, that only the last three digits (i.e., the file permissions
|
|
44
|
+
digits) of the mask are actually used when the mask is applied.
|
|
45
|
+
|
|
46
|
+
Permissions can be represented using the following symbolic form:
|
|
47
|
+
|
|
48
|
+
u=rwx,g=rwx,o=rwx
|
|
49
|
+
|
|
50
|
+
where
|
|
51
|
+
|
|
52
|
+
- u: user permissions
|
|
53
|
+
- g: group permissions
|
|
54
|
+
- o: other/non-group permissions
|
|
55
|
+
- r: read
|
|
56
|
+
- w: write
|
|
57
|
+
- x: execute
|
|
58
|
+
|
|
59
|
+
When setting permissions using symbolic notation, the function accepts a
|
|
60
|
+
mask expression of the form:
|
|
61
|
+
|
|
62
|
+
[<classes>]<operator><symbols>
|
|
63
|
+
|
|
64
|
+
where "classes" may be a combination of
|
|
65
|
+
|
|
66
|
+
- u: user
|
|
67
|
+
- g: group
|
|
68
|
+
- o: other/non-group
|
|
69
|
+
- a: all
|
|
70
|
+
|
|
71
|
+
"symbols" may be a combination of
|
|
72
|
+
|
|
73
|
+
- r: read
|
|
74
|
+
- w: write
|
|
75
|
+
- x: execute
|
|
76
|
+
- X: special execute
|
|
77
|
+
- s: setuid/gid on execution
|
|
78
|
+
- t: sticky
|
|
79
|
+
|
|
80
|
+
and "operator" may be one of
|
|
81
|
+
|
|
82
|
+
- +: enable
|
|
83
|
+
- -: disable
|
|
84
|
+
- =: enable specified and disable unspecified permissions
|
|
85
|
+
|
|
86
|
+
For example,
|
|
87
|
+
|
|
88
|
+
- u-w: disable user write permissions
|
|
89
|
+
- u+w: enable user write permissions
|
|
90
|
+
- u=w: enable user write permissions and disable user read and execute
|
|
91
|
+
|
|
92
|
+
To specify multiple changes, provide a comma-separated list of mask
|
|
93
|
+
expressions. For example,
|
|
94
|
+
|
|
95
|
+
u+rwx,g-x,o=r
|
|
96
|
+
|
|
97
|
+
would enable user read, write, and execute permissions, disable group
|
|
98
|
+
execute permissions, enable other read permissions, and disable other
|
|
99
|
+
write and execute permissions.
|
|
100
|
+
|
|
101
|
+
The `a` class indicates "all", which is the same as specifying "ugo". This
|
|
102
|
+
is the default class if a class is omitted when specifying permissions. For
|
|
103
|
+
example, `+x` is equivalent to `a+x` which is equivalent to `ugo+x` which
|
|
104
|
+
is equivalent to `u+x,g+x,o+x` and enables execution for all classes.
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
mask: integer|string (optional)
|
|
109
|
+
Mask or mask expression. If the mask is a string, the mask is assumed to
|
|
110
|
+
be in symbolic notation.
|
|
111
|
+
|
|
112
|
+
options: Object (optional)
|
|
113
|
+
Options.
|
|
114
|
+
|
|
115
|
+
options.symbolic: boolean (optional)
|
|
116
|
+
Boolean indicating whether to return the mask using symbolic notation.
|
|
117
|
+
|
|
118
|
+
Returns
|
|
119
|
+
-------
|
|
120
|
+
mask: integer|string
|
|
121
|
+
Process mask. If provided a mask, the returned value is the previous
|
|
122
|
+
mask; otherwise, the returned value is the current process mask.
|
|
123
|
+
|
|
124
|
+
Examples
|
|
125
|
+
--------
|
|
126
|
+
> var mask = {{alias}}()
|
|
127
|
+
<number>
|
|
128
|
+
> mask = {{alias}}( { 'symbolic': true } )
|
|
129
|
+
<string>
|
|
130
|
+
|
|
131
|
+
See Also
|
|
132
|
+
--------
|
|
133
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Interface defining function options.
|
|
23
|
+
*/
|
|
24
|
+
interface Options {
|
|
25
|
+
/**
|
|
26
|
+
* Boolean indicating whether to return a mask using symbolic notation.
|
|
27
|
+
*/
|
|
28
|
+
symbolic?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get/set the process mask.
|
|
33
|
+
*
|
|
34
|
+
* ## Notes
|
|
35
|
+
*
|
|
36
|
+
* - If provided a mask, the function sets the current mask and returns the previous process mask. Otherwise, the function returns the current process mask.
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
* @param mask - mask
|
|
40
|
+
* @param options - options
|
|
41
|
+
* @param options.symbolic - boolean indicating whether to return a mask using symbolic notation
|
|
42
|
+
* @throws must provide valid options
|
|
43
|
+
* @throws must provide a parseable expression mask
|
|
44
|
+
* @returns process mask
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* var mask = umask();
|
|
48
|
+
* // returns <number>
|
|
49
|
+
*/
|
|
50
|
+
declare function umask( mask: number | string, options?: Options ): number | string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get/set the process mask.
|
|
54
|
+
*
|
|
55
|
+
* @param options - options
|
|
56
|
+
* @param options.symbolic - boolean indicating whether to return a mask using symbolic notation
|
|
57
|
+
* @throws must provide valid options
|
|
58
|
+
* @returns process mask
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* var mask = umask();
|
|
62
|
+
* // returns <number>
|
|
63
|
+
*/
|
|
64
|
+
declare function umask( options?: Options ): number | string;
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// EXPORTS //
|
|
68
|
+
|
|
69
|
+
export = umask;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import umask = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
// The function returns a string or number...
|
|
25
|
+
{
|
|
26
|
+
umask(); // $ExpectType string | number
|
|
27
|
+
umask( 0 ); // $ExpectType string | number
|
|
28
|
+
umask( 'u=rwx,g=rw,o=rw' ); // $ExpectType string | number
|
|
29
|
+
umask( { 'symbolic': true } ); // $ExpectType string | number
|
|
30
|
+
umask( 0, { 'symbolic': true } ); // $ExpectType string | number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The compiler throws an error if the function is provided a first` argument which is not a string, number, or `options` object...
|
|
34
|
+
{
|
|
35
|
+
umask( false ); // $ExpectError
|
|
36
|
+
umask( true ); // $ExpectError
|
|
37
|
+
umask( ( x: number ): number => x ); // $ExpectError
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The compiler throws an error if the function is provided a second argument which is not an object...
|
|
41
|
+
{
|
|
42
|
+
umask( 0, 'abc' ); // $ExpectError
|
|
43
|
+
umask( 0, 3.12 ); // $ExpectError
|
|
44
|
+
umask( 0, false ); // $ExpectError
|
|
45
|
+
umask( 0, true ); // $ExpectError
|
|
46
|
+
umask( 0, ( x: number ): number => x ); // $ExpectError
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// The compiler throws an error if the function is provided a `symbolic` option which is not a boolean...
|
|
50
|
+
{
|
|
51
|
+
umask( 0, { 'symbolic': '5' } ); // $ExpectError
|
|
52
|
+
umask( 0, { 'symbolic': 123 } ); // $ExpectError
|
|
53
|
+
umask( 0, { 'symbolic': null } ); // $ExpectError
|
|
54
|
+
umask( 0, { 'symbolic': [] } ); // $ExpectError
|
|
55
|
+
umask( 0, { 'symbolic': {} } ); // $ExpectError
|
|
56
|
+
umask( 0, { 'symbolic': ( x: number ): number => x } ); // $ExpectError
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The compiler throws an error if the function is provided more than two arguments...
|
|
60
|
+
{
|
|
61
|
+
umask( 0, {}, {} ); // $ExpectError
|
|
62
|
+
}
|