How to use the chmodSync function from fs-extra

Find comprehensive JavaScript fs-extra.chmodSync code examples handpicked from public code repositorys.

fs-extra.chmodSync is a method in the fs-extra library that synchronously changes the permissions of a file or directory.

56
57
58
59
60
61
62
63
64
65
            }
        }
    }
    fs.copySync(source, output)
}
fs.chmodSync(output, stat.mode)

if (options.preserve) {
    fs.chownSync(output, stat.uid, stat.gid)
    fs.utimesSync(output, stat.atime, stat.mtime)
fork icon3
star icon28
watch icon0

+ 3 other calls in file

134
135
136
137
138
139
140
141
142
143
// Linux does not have lchmod, so we have to make sure the target exists
if (!stats.isSymbolicLink() || followSymlink) {
  if (stats.isDirectory()) {
      if (data.hasOwnProperty('dmode')) {
        logdebug('Setting dmode ' + data.dmode.oct + ' for ' + realpath);
        fs.chmodSync(realpath, data.dmode.oct);
      } else if (data.hasOwnProperty('mode')) {
        logdebug('Setting mode ' + data.mode.oct + ' for ' + realpath);
        fs.chmodSync(realpath, data.mode.oct);
      }
fork icon0
star icon1
watch icon2

+ 7 other calls in file

How does fs-extra.chmodSync work?

fs-extra.chmodSync is a method in the fs-extra library that allows a user to change the permissions of a file or directory synchronously. It takes two arguments: the path to the file or directory whose permissions need to be changed, and a mode value that determines the new permissions.

31
32
33
34
35
36
37
38
39
40
    console.log(`Skipping '${sourcePath}' since it is already linked`);
    continue;
} else {
    // 移除目标文件夹的所有内容,
    console.log(`'${targetPath}' is already linked to another directory, removing`);
    fs.chmodSync(targetPath, '0755');
    rimraf(targetPath, () => {
        console.log('removed target path');
        fs.moveSync(sourcePath, targetPath);
        fs.symlinkSync(targetPath, sourcePath, 'junction');
fork icon0
star icon0
watch icon1

+ 11 other calls in file

285
286
287
288
289
290
291
292
293
294
      // have to build a temporary script
      tempScript = `${os.homedir()}/${project.name}-connect`;
      fs.writeFileSync(tempScript, `#!/bin/bash
ssh -i ${project['ssh-key']} -o IdentitiesOnly=yes $*`
      );
      fs.chmodSync(tempScript, 0o700);
      gitSpawnOptions.env.GIT_SSH = tempScript;
    }
    const beforeConnecting = existsInCheckout('deployment/before-connecting');
    if (fs.existsSync(checkout)) {
fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
const fs = require("fs-extra");

// set file permissions to read/write for owner and read-only for others
fs.chmodSync("/path/to/myfile", "644");

In this example, fs.chmodSync() is used to set the permissions of the file at /path/to/myfile to 644, which corresponds to read/write permissions for the owner and read-only permissions for others. The method call is synchronous, so the function will block until the operation is complete.

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)