How to use the lchmod function from fs

Find comprehensive JavaScript fs.lchmod code examples handpicked from public code repositorys.

122
123
124
125
126
127
128
129
130
131
132
133
134
if (fs.lchmod) {
  const link = path.join(common.tmpDir, 'symbolic-link');


  fs.symlinkSync(file2, link);


  fs.lchmod(link, mode_async, common.mustCall((err) => {
    assert.ifError(err);


    assert.strictEqual(mode_async, fs.lstatSync(link).mode & 0o777);

fork icon16
star icon65
watch icon0

67
68
69
70
71
72
73
74
75
  const link = path.join(tmpdir.path, `lchmod-src-${suffix}`);
  const file = path.join(tmpdir.path, `lchmod-dest-${suffix}`);
  fs.writeFileSync(file, 'test', 'utf-8');
  fs.symlinkSync(file, link);

  fs.lchmod(link, input, common.mustSucceed(() => {
    assert.strictEqual(fs.lstatSync(link).mode & 0o777, mode);
  }));
}
fork icon0
star icon0
watch icon0

+ 4 other calls in file

133
134
135
136
137
138
139
140
141
142
try {
  fs.unlinkSync(link);
} catch (er) {}
fs.symlinkSync(file2, link);

fs.lchmod(link, mode_async, function(err) {
  if (err) {
    got_error = true;
  } else {
    console.log(fs.lstatSync(link).mode);
fork icon0
star icon0
watch icon0

127
128
129
130
131
132
133
134
135
136
137
138
139
if (fs.lchmod) {
  const link = path.join(tmpdir.path, 'symbolic-link');


  fs.symlinkSync(file2, link);


  fs.lchmod(link, mode_async, common.mustSucceed(() => {
    assert.strictEqual(fs.lstatSync(link).mode & 0o777, mode_async);


    fs.lchmodSync(link, mode_sync);
    assert.strictEqual(fs.lstatSync(link).mode & 0o777, mode_sync);
fork icon0
star icon0
watch icon0

+ 4 other calls in file

19
20
21
22
23
24
25
26
27
28
29
assert.throws(() => fs.lchmod(f, {}), { code: 'ERR_INVALID_CALLBACK' });


// Check path
[false, 1, {}, [], null, undefined].forEach((i) => {
  assert.throws(
    () => fs.lchmod(i, 0o777, common.mustNotCall()),
    {
      code: 'ERR_INVALID_ARG_TYPE',
      name: 'TypeError'
    }
fork icon0
star icon0
watch icon0

+ 7 other calls in file

12
13
14
15
16
17
18
19
20
21
22
23
  common.skip('lchmod is only available on macOS');
}


// Check callback
assert.throws(() => fs.lchmod(f), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => fs.lchmod(), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => fs.lchmod(f, {}), { code: 'ERR_INVALID_ARG_TYPE' });


// Check path
[false, 1, {}, [], null, undefined].forEach((i) => {
fork icon0
star icon0
watch icon0

+ 9 other calls in file