All files / fs / unstable_umask.ts

0.00% Branches 0/1
46.15% Lines 6/13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
 
x1
x1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
x1
x4
x4
 
 
 
 
 
 
 
x4





























I






// Copyright 2018-2025 the Deno authors. MIT license.

import { mapError } from "./_map_error.ts";
import { getNodeProcess, isDeno } from "./_utils.ts";

/** Retrieve the process umask.  If `mask` is provided, sets the process umask.
 * This call always returns what the umask was before the call.
 * @example Usage
 *
 * ```ts ignore
 * import { assert } from "@std/assert";
 * import { umask } from "@std/fs/unstable-umask";
 *
 * const prevUmaskValue = Deno.umask(0o077);
 * const currentUmaskValue = Deno.umask();
 * assert(prevUmaskValue !== currentUmaskValue)
 * ```
 *
 * This API is under consideration to determine if permissions are required to
 * call it.
 *
 * *Note*: This API is not implemented on Windows
 *
 * @category File System
 * @param mask The new process mask
 * @returns The previous mask
 */
export function umask(mask?: number): number {
  if (isDeno) {
    return Deno.umask(mask);
  } else {
    try {
      return getNodeProcess().umask(mask);
    } catch (error) {
      throw mapError(error);
    }
  }
}