@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
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isString = require( '@ohos-ports/stdlib-assert/is-string' ).isPrimitive;
|
|
24
|
+
var isNonNegativeInteger = require( '@ohos-ports/stdlib-assert/is-nonnegative-integer' ).isPrimitive;
|
|
25
|
+
var isBoolean = require( '@ohos-ports/stdlib-assert/is-boolean' ).isPrimitive;
|
|
26
|
+
var isObject = require( '@ohos-ports/stdlib-assert/is-plain-object' );
|
|
27
|
+
var hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
|
|
28
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
29
|
+
var toSymbolic = require( './to_symbolic.js' );
|
|
30
|
+
var fromSymbolic = require( './from_symbolic.js' );
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// VARIABLES //
|
|
34
|
+
|
|
35
|
+
var MASK = 0|0; // asm type annotation
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// MAIN //
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get/set the process mask.
|
|
42
|
+
*
|
|
43
|
+
* ## Notes
|
|
44
|
+
*
|
|
45
|
+
* - If provided a mask, the function sets the current mask and returns the previous process mask. Otherwise, the function returns the current process mask.
|
|
46
|
+
* - Browser environments do not support process masks. Hence, this function always returns either `0` or `u=rwx,g=rwx,o=rwx`.
|
|
47
|
+
*
|
|
48
|
+
* @param {(NonNegativeInteger|string)} [mask] - mask
|
|
49
|
+
* @param {Object} [options] - options
|
|
50
|
+
* @param {boolean} [options.symbolic] - boolean indicating whether to return a mask using symbolic notation
|
|
51
|
+
* @throws {TypeError} must provide either a string, nonnegative integer, or an options object
|
|
52
|
+
* @throws {TypeError} must provide valid options
|
|
53
|
+
* @throws {Error} must provide a parseable expression mask
|
|
54
|
+
* @returns {(NonNegativeInteger|string)} process mask
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* var mask = umask();
|
|
58
|
+
* // returns 0
|
|
59
|
+
*/
|
|
60
|
+
function umask() {
|
|
61
|
+
var options;
|
|
62
|
+
var nargs;
|
|
63
|
+
var mask;
|
|
64
|
+
var opts;
|
|
65
|
+
var arg;
|
|
66
|
+
|
|
67
|
+
nargs = arguments.length;
|
|
68
|
+
if ( nargs === 0 ) {
|
|
69
|
+
return MASK;
|
|
70
|
+
}
|
|
71
|
+
opts = {};
|
|
72
|
+
arg = arguments[ 0 ];
|
|
73
|
+
if ( nargs === 1 ) {
|
|
74
|
+
if ( isString( arg ) ) {
|
|
75
|
+
mask = fromSymbolic( MASK, arg );
|
|
76
|
+
if ( mask instanceof Error ) {
|
|
77
|
+
throw mask;
|
|
78
|
+
}
|
|
79
|
+
return MASK;
|
|
80
|
+
}
|
|
81
|
+
if ( isNonNegativeInteger( arg ) ) {
|
|
82
|
+
// Easy case where we use the built-in function to set the mask and return its return value:
|
|
83
|
+
return MASK;
|
|
84
|
+
}
|
|
85
|
+
if ( isObject( arg ) ) {
|
|
86
|
+
if ( hasOwnProp( arg, 'symbolic' ) ) {
|
|
87
|
+
opts.symbolic = arg.symbolic;
|
|
88
|
+
if ( !isBoolean( opts.symbolic ) ) {
|
|
89
|
+
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'symbolic', opts.symbolic ) );
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
mask = MASK;
|
|
93
|
+
if ( opts.symbolic ) {
|
|
94
|
+
mask = toSymbolic( mask );
|
|
95
|
+
}
|
|
96
|
+
return mask;
|
|
97
|
+
}
|
|
98
|
+
throw new TypeError( format( 'invalid argument. Must provide either a string, nonnegative integer, or an options object. Value: `%s`.', arg ) );
|
|
99
|
+
}
|
|
100
|
+
options = arguments[ 1 ];
|
|
101
|
+
if ( !isObject( options ) ) {
|
|
102
|
+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
103
|
+
}
|
|
104
|
+
if ( hasOwnProp( options, 'symbolic' ) ) {
|
|
105
|
+
opts.symbolic = options.symbolic;
|
|
106
|
+
if ( !isBoolean( opts.symbolic ) ) {
|
|
107
|
+
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'symbolic', opts.symbolic ) );
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if ( isString( arg ) ) {
|
|
111
|
+
mask = fromSymbolic( MASK, arg );
|
|
112
|
+
if ( mask instanceof Error ) {
|
|
113
|
+
throw mask;
|
|
114
|
+
}
|
|
115
|
+
} else if ( isNonNegativeInteger( arg ) ) {
|
|
116
|
+
mask = arg;
|
|
117
|
+
} else {
|
|
118
|
+
throw new TypeError( format( 'invalid argument. First argument must be either a string or nonnegative integer. Value: `%s`.', arg ) );
|
|
119
|
+
}
|
|
120
|
+
// Set the mask:
|
|
121
|
+
mask = MASK;
|
|
122
|
+
|
|
123
|
+
// Determine how to format the output value:
|
|
124
|
+
if ( opts.symbolic ) {
|
|
125
|
+
mask = toSymbolic( mask );
|
|
126
|
+
}
|
|
127
|
+
return mask;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
// EXPORTS //
|
|
132
|
+
|
|
133
|
+
module.exports = umask;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
24
|
+
var lpad = require( '@ohos-ports/stdlib-string/left-pad' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// VARIABLES //
|
|
28
|
+
|
|
29
|
+
// Regular expression to parse a mask expression:
|
|
30
|
+
var RE_MASK_EXPRESSION = /^(u{0,1}g{0,1}o{0,1}a{0,1}|)([+\-=])(r{0,1}w{0,1}x{0,1})$/;
|
|
31
|
+
|
|
32
|
+
// Table of permission bit mask offsets:
|
|
33
|
+
var PERMS = {
|
|
34
|
+
'r': 2, // read
|
|
35
|
+
'w': 1, // write
|
|
36
|
+
'x': 0 // execute
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Table of class indices in the octal format (e.g., `0o0077`):
|
|
40
|
+
var WHO = {
|
|
41
|
+
's': 0, // special mode (ignored; see http://man7.org/linux/man-pages/man2/umask.2.html)
|
|
42
|
+
'u': 1, // user
|
|
43
|
+
'g': 2, // group
|
|
44
|
+
'o': 3 // other/non-group
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// FUNCTIONS //
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns a bit mask.
|
|
52
|
+
*
|
|
53
|
+
* @private
|
|
54
|
+
* @param {NonNegativeInteger} offset - bit offset (right-to-left)
|
|
55
|
+
* @returns {NonNegativeInteger} bit mask
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var y = bitMask( 3 );
|
|
59
|
+
* // returns 8
|
|
60
|
+
*/
|
|
61
|
+
function bitMask( offset ) {
|
|
62
|
+
return ( 1 << offset )>>>0; // asm type annotation
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Sets a bit.
|
|
67
|
+
*
|
|
68
|
+
* @private
|
|
69
|
+
* @param {NonNegativeInteger} value - value
|
|
70
|
+
* @param {NonNegativeInteger} offset - bit offset (right-to-left)
|
|
71
|
+
* @returns {NonNegativeInteger} updated value
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* var y = setBit( 8, 2 );
|
|
75
|
+
*/
|
|
76
|
+
function setBit( value, offset ) {
|
|
77
|
+
return ( value | bitMask( offset ) )>>>0; // asm type annotation
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Clears a bit.
|
|
82
|
+
*
|
|
83
|
+
* @private
|
|
84
|
+
* @param {NonNegativeInteger} value - value
|
|
85
|
+
* @param {NonNegativeInteger} offset - bit offset (right-to-left)
|
|
86
|
+
* @returns {NonNegativeInteger} updated value
|
|
87
|
+
*/
|
|
88
|
+
function clearBit( value, offset ) {
|
|
89
|
+
return ( value & ~bitMask( offset ) )>>>0; // asm type annotation
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// MAIN //
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Converts a mask expression in symbolic notation to an integer.
|
|
97
|
+
*
|
|
98
|
+
* @private
|
|
99
|
+
* @param {NonNegativeInteger} mask - current mask
|
|
100
|
+
* @param {string} expr - mask expression
|
|
101
|
+
* @returns {(NonNegativeInteger|Error)} integer mask or parse error
|
|
102
|
+
*/
|
|
103
|
+
function fromSymbolic( mask, expr ) {
|
|
104
|
+
var digits;
|
|
105
|
+
var parts;
|
|
106
|
+
var perm;
|
|
107
|
+
var who;
|
|
108
|
+
var tmp;
|
|
109
|
+
var idx;
|
|
110
|
+
var op;
|
|
111
|
+
var w;
|
|
112
|
+
var o;
|
|
113
|
+
var i;
|
|
114
|
+
var j;
|
|
115
|
+
var k;
|
|
116
|
+
|
|
117
|
+
// Split the mask into octal digits (e.g., [ '0', '0', '7', '7' ]):
|
|
118
|
+
digits = lpad( mask.toString( 8 ), 4, '0' ).split( '' );
|
|
119
|
+
|
|
120
|
+
// Convert each octal digit to an integer value:
|
|
121
|
+
for ( i = 0; i < digits.length; i++ ) {
|
|
122
|
+
digits[ i ] = parseInt( digits[ i ], 10 );
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// See if we can easily split the mask into separate mask expressions (e.g., `u+x,g=rw,o=` => [ 'u+x', 'g=rw', 'o=' ] ):
|
|
126
|
+
parts = expr.split( ',' );
|
|
127
|
+
|
|
128
|
+
// For each expression, split into "class", "operator", and "symbols" and update the mask octal digits:
|
|
129
|
+
for ( i = 0; i < parts.length; i++ ) {
|
|
130
|
+
tmp = parts[ i ].match( RE_MASK_EXPRESSION );
|
|
131
|
+
if ( tmp === null ) {
|
|
132
|
+
return new Error( format( 'invalid argument. Unable to parse mask expression. Ensure the expression is properly formatted, only uses the class letters "u", "g", "o", and "a", only uses the operators "+", "-", and "=", and only uses the permission symbols "r", "w", and "x". Value: `%s`.', expr ) );
|
|
133
|
+
}
|
|
134
|
+
// Extract the expression parts:
|
|
135
|
+
who = tmp[ 1 ];
|
|
136
|
+
if ( who === '' ) {
|
|
137
|
+
// If a user class is not specified (e.g., `+x`), "ugo" (user, group, other) is implied...
|
|
138
|
+
who = 'ugo';
|
|
139
|
+
} else {
|
|
140
|
+
// Replace `a` (all) user class letter with "ugo" (user, group, other) equivalent...
|
|
141
|
+
w = '';
|
|
142
|
+
for ( k = 0; k < who.length; k++ ) {
|
|
143
|
+
if ( who[ k ] === 'a' ) {
|
|
144
|
+
w += 'ugo';
|
|
145
|
+
} else {
|
|
146
|
+
w += who[ k ];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
who = w;
|
|
150
|
+
}
|
|
151
|
+
op = tmp[ 2 ];
|
|
152
|
+
perm = tmp[ 3 ];
|
|
153
|
+
|
|
154
|
+
// NOTE: the algorithm below is from the perspective of the mask. If implemented for, say, `chmod`, the "disabling"/"enabling" logic would be reversed. Recall that a "1" in the mask, serves to **disable** a permission setting, not enable.
|
|
155
|
+
|
|
156
|
+
// Disable permissions...
|
|
157
|
+
if ( op === '-' ) {
|
|
158
|
+
if ( perm === '' ) {
|
|
159
|
+
// The `-` operation by itself does not change any bits...
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
for ( j = 0; j < perm.length; j++ ) {
|
|
163
|
+
o = PERMS[ perm[j] ];
|
|
164
|
+
for ( k = 0; k < who.length; k++ ) {
|
|
165
|
+
idx = WHO[ who[k] ];
|
|
166
|
+
digits[ idx ] = setBit( digits[ idx ], o ); // to disable, we flip on mask bits
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Enable permissions...
|
|
171
|
+
else if ( op === '+' ) {
|
|
172
|
+
if ( perm === '' ) {
|
|
173
|
+
// The `+` operation by itself does not change any bits...
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
for ( j = 0; j < perm.length; j++ ) {
|
|
177
|
+
o = PERMS[ perm[j] ];
|
|
178
|
+
for ( k = 0; k < who.length; k++ ) {
|
|
179
|
+
idx = WHO[ who[k] ];
|
|
180
|
+
digits[ idx ] = clearBit( digits[ idx ], o ); // to enable, we clear mask bits
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Disable all permissions by flipping on all permission mask bits...
|
|
185
|
+
else if ( perm === '' ) { // op === '='
|
|
186
|
+
for ( k = 0; k < who.length; k++ ) {
|
|
187
|
+
idx = WHO[ who[k] ];
|
|
188
|
+
digits[ idx ] = 7;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Explicitly set permissions...
|
|
192
|
+
else { // op === '='
|
|
193
|
+
// First, disable all permissions by flipping on all permission mask bits...
|
|
194
|
+
for ( k = 0; k < who.length; k++ ) {
|
|
195
|
+
idx = WHO[ who[k] ];
|
|
196
|
+
digits[ idx ] = 7;
|
|
197
|
+
}
|
|
198
|
+
// Then, explicitly enable permissions by clearing mask bits...
|
|
199
|
+
for ( j = 0; j < perm.length; j++ ) {
|
|
200
|
+
o = PERMS[ perm[j] ];
|
|
201
|
+
for ( k = 0; k < who.length; k++ ) {
|
|
202
|
+
idx = WHO[ who[k] ];
|
|
203
|
+
digits[ idx ] = clearBit( digits[ idx ], o );
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Convert the digits to an integer value...
|
|
209
|
+
for ( i = 0; i < digits.length; i++ ) {
|
|
210
|
+
digits[ i ] = digits[ i ].toString();
|
|
211
|
+
}
|
|
212
|
+
return parseInt( digits.join( '' ), 8 );
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
// EXPORTS //
|
|
217
|
+
|
|
218
|
+
module.exports = fromSymbolic;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get/set the process mask.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/process/umask
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var umask = require( '@ohos-ports/stdlib-process/umask' );
|
|
28
|
+
*
|
|
29
|
+
* var mask = umask();
|
|
30
|
+
* // returns <number>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// MODULES //
|
|
34
|
+
|
|
35
|
+
var main = require( './main.js' );
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// EXPORTS //
|
|
39
|
+
|
|
40
|
+
module.exports = main;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var proc = require( 'process' );
|
|
24
|
+
var isString = require( '@ohos-ports/stdlib-assert/is-string' ).isPrimitive;
|
|
25
|
+
var isNonNegativeInteger = require( '@ohos-ports/stdlib-assert/is-nonnegative-integer' ).isPrimitive;
|
|
26
|
+
var isBoolean = require( '@ohos-ports/stdlib-assert/is-boolean' ).isPrimitive;
|
|
27
|
+
var isObject = require( '@ohos-ports/stdlib-assert/is-plain-object' );
|
|
28
|
+
var hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
|
|
29
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
30
|
+
var toSymbolic = require( './to_symbolic.js' );
|
|
31
|
+
var fromSymbolic = require( './from_symbolic.js' );
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// MAIN //
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get/set the process mask.
|
|
38
|
+
*
|
|
39
|
+
* ## Notes
|
|
40
|
+
*
|
|
41
|
+
* - If provided a mask, the function sets the current mask and returns the previous process mask. Otherwise, the function returns the current process mask.
|
|
42
|
+
*
|
|
43
|
+
* @param {(NonNegativeInteger|string)} [mask] - mask
|
|
44
|
+
* @param {Object} [options] - options
|
|
45
|
+
* @param {boolean} [options.symbolic] - boolean indicating whether to return a mask using symbolic notation
|
|
46
|
+
* @throws {TypeError} must provide either a string, nonnegative integer, or an options object
|
|
47
|
+
* @throws {TypeError} must provide valid options
|
|
48
|
+
* @throws {Error} must provide a parseable expression mask
|
|
49
|
+
* @returns {(NonNegativeInteger|string)} process mask
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* var mask = umask();
|
|
53
|
+
* // returns <number>
|
|
54
|
+
*/
|
|
55
|
+
function umask() {
|
|
56
|
+
var options;
|
|
57
|
+
var nargs;
|
|
58
|
+
var mask;
|
|
59
|
+
var opts;
|
|
60
|
+
var arg;
|
|
61
|
+
|
|
62
|
+
nargs = arguments.length;
|
|
63
|
+
if ( nargs === 0 ) {
|
|
64
|
+
return proc.umask();
|
|
65
|
+
}
|
|
66
|
+
opts = {};
|
|
67
|
+
arg = arguments[ 0 ];
|
|
68
|
+
if ( nargs === 1 ) {
|
|
69
|
+
if ( isString( arg ) ) {
|
|
70
|
+
mask = fromSymbolic( proc.umask(), arg );
|
|
71
|
+
if ( mask instanceof Error ) {
|
|
72
|
+
throw mask;
|
|
73
|
+
}
|
|
74
|
+
return proc.umask( mask );
|
|
75
|
+
}
|
|
76
|
+
if ( isNonNegativeInteger( arg ) ) {
|
|
77
|
+
// Easy case where we use the built-in function to set the mask and return its return value:
|
|
78
|
+
return proc.umask( arg );
|
|
79
|
+
}
|
|
80
|
+
if ( isObject( arg ) ) {
|
|
81
|
+
if ( hasOwnProp( arg, 'symbolic' ) ) {
|
|
82
|
+
opts.symbolic = arg.symbolic;
|
|
83
|
+
if ( !isBoolean( opts.symbolic ) ) {
|
|
84
|
+
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'symbolic', opts.symbolic ) );
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
mask = proc.umask();
|
|
88
|
+
if ( opts.symbolic ) {
|
|
89
|
+
mask = toSymbolic( mask );
|
|
90
|
+
}
|
|
91
|
+
return mask;
|
|
92
|
+
}
|
|
93
|
+
throw new TypeError( format( 'invalid argument. Must provide either a string, nonnegative integer, or an options object. Value: `%s`.', arg ) );
|
|
94
|
+
}
|
|
95
|
+
options = arguments[ 1 ];
|
|
96
|
+
if ( !isObject( options ) ) {
|
|
97
|
+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
98
|
+
}
|
|
99
|
+
if ( hasOwnProp( options, 'symbolic' ) ) {
|
|
100
|
+
opts.symbolic = options.symbolic;
|
|
101
|
+
if ( !isBoolean( opts.symbolic ) ) {
|
|
102
|
+
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'symbolic', opts.symbolic ) );
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if ( isString( arg ) ) {
|
|
106
|
+
mask = fromSymbolic( proc.umask(), arg );
|
|
107
|
+
if ( mask instanceof Error ) {
|
|
108
|
+
throw mask;
|
|
109
|
+
}
|
|
110
|
+
} else if ( isNonNegativeInteger( arg ) ) {
|
|
111
|
+
mask = arg;
|
|
112
|
+
} else {
|
|
113
|
+
throw new TypeError( format( 'invalid argument. First argument must be either a string or nonnegative integer. Value: `%s`.', arg ) );
|
|
114
|
+
}
|
|
115
|
+
// Set the mask:
|
|
116
|
+
mask = proc.umask( mask );
|
|
117
|
+
|
|
118
|
+
// Determine how to format the output value:
|
|
119
|
+
if ( opts.symbolic ) {
|
|
120
|
+
mask = toSymbolic( mask );
|
|
121
|
+
}
|
|
122
|
+
return mask;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// EXPORTS //
|
|
127
|
+
|
|
128
|
+
module.exports = umask;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var lpad = require( '@ohos-ports/stdlib-string/left-pad' );
|
|
24
|
+
var OCTAL_CODES = require( './octal_codes.json' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Converts an integer mask to symbolic notation.
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
* @param {NonNegativeInteger} mask - integer mask
|
|
34
|
+
* @returns {string} mask in symbolic notation
|
|
35
|
+
*/
|
|
36
|
+
function toSymbolic( mask ) {
|
|
37
|
+
var out;
|
|
38
|
+
|
|
39
|
+
// Convert the mask to a four-digit octal string representation (e.g., 0077):
|
|
40
|
+
mask = mask.toString( 8 );
|
|
41
|
+
mask = lpad( mask, 4, '0' );
|
|
42
|
+
|
|
43
|
+
// For each digit, get the permissions: (NOTE: we skip the special modes digit, as only the file permission bits of the mask are used; see http://man7.org/linux/man-pages/man2/umask.2.html)
|
|
44
|
+
out = '';
|
|
45
|
+
out += 'u='+OCTAL_CODES[ mask[1] ];
|
|
46
|
+
out += ',';
|
|
47
|
+
out += 'g='+OCTAL_CODES[ mask[2] ];
|
|
48
|
+
out += ',';
|
|
49
|
+
out += 'o='+OCTAL_CODES[ mask[3] ];
|
|
50
|
+
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// EXPORTS //
|
|
56
|
+
|
|
57
|
+
module.exports = toSymbolic;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/process/umask",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Get/set the process mask.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"bin": {
|
|
17
|
+
"umask": "./bin/cli"
|
|
18
|
+
},
|
|
19
|
+
"main": "./lib",
|
|
20
|
+
"browser": {
|
|
21
|
+
"./lib": "./lib/browser.js",
|
|
22
|
+
"process": "process/"
|
|
23
|
+
},
|
|
24
|
+
"directories": {
|
|
25
|
+
"benchmark": "./benchmark",
|
|
26
|
+
"doc": "./docs",
|
|
27
|
+
"example": "./examples",
|
|
28
|
+
"lib": "./lib",
|
|
29
|
+
"scripts": "./scripts",
|
|
30
|
+
"test": "./test"
|
|
31
|
+
},
|
|
32
|
+
"types": "./docs/types",
|
|
33
|
+
"scripts": {},
|
|
34
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {},
|
|
43
|
+
"devDependencies": {},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=0.10.0",
|
|
46
|
+
"npm": ">2.7.0"
|
|
47
|
+
},
|
|
48
|
+
"os": [
|
|
49
|
+
"aix",
|
|
50
|
+
"darwin",
|
|
51
|
+
"freebsd",
|
|
52
|
+
"linux",
|
|
53
|
+
"macos",
|
|
54
|
+
"openbsd",
|
|
55
|
+
"sunos",
|
|
56
|
+
"win32",
|
|
57
|
+
"windows",
|
|
58
|
+
"openharmony"
|
|
59
|
+
],
|
|
60
|
+
"keywords": [
|
|
61
|
+
"stdlib",
|
|
62
|
+
"stdutils",
|
|
63
|
+
"stdutil",
|
|
64
|
+
"utilities",
|
|
65
|
+
"utility",
|
|
66
|
+
"utils",
|
|
67
|
+
"util",
|
|
68
|
+
"process",
|
|
69
|
+
"umask",
|
|
70
|
+
"permissions",
|
|
71
|
+
"mask",
|
|
72
|
+
"security",
|
|
73
|
+
"chmod",
|
|
74
|
+
"restrictions",
|
|
75
|
+
"filesystem",
|
|
76
|
+
"fs"
|
|
77
|
+
]
|
|
78
|
+
}
|