How to use the chownSync function from fs

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

13
14
15
16
17
18
19
20
21
22
exports.appendFile = co.promisify(fs.appendFile);
exports.appendFileSync = fs.appendFileSync;
exports.chmod = co.promisify(fs.chmod);
exports.chmodSync = fs.chmodSync;
exports.chown = co.promisify(fs.chown);
exports.chownSync = fs.chownSync;
exports.close = co.promisify(fs.close);
exports.closeSync = fs.closeSync;
exports.constants = fs.constants;
exports.createReadStream = fs.createReadStream;
fork icon22
star icon45
watch icon26

604
605
606
607
608
609
610
611
612
613
614
615


  fs.chown(nonexistentFile, process.getuid(), process.getgid(),
           common.mustCall(validateError));


  assert.throws(
    () => fs.chownSync(nonexistentFile,
                       process.getuid(), process.getgid()),
    validateError
  );
}
fork icon42
star icon19
watch icon0

776
777
778
779
780
781
782
783
784
785

try {
  fs.fchownSync(fd, uid, gid)
} catch (fchowner) {
  try {
    fs.chownSync(entry.absolute, uid, gid)
  } catch (chowner) {
    er = er || fchowner
  }
}
fork icon3
star icon2
watch icon0

107
108
109
110
111
112
113
114
115
116
117


// fs.chownSync (should not bypass)
{
  assert.throws(() => {
    // This operation will work fine
    fs.chownSync(blockedFile, uid, gid);
    fs.readFileSync(blockedFile);
  }, common.expectsError({
    code: 'ERR_ACCESS_DENIED',
    permission: 'FileSystemRead',
fork icon0
star icon0
watch icon0

21
22
23
24
25
26
27
28
29
30
31
}


/* istanbul ignore next */
const chownSync = (path, uid, gid) => {
  try {
    return fs.chownSync(path, uid, gid)
  } catch (er) {
    if (er.code !== 'ENOENT')
      throw er
  }
fork icon0
star icon0
watch icon0

34
35
36
37
38
39
40
41
42
43
    code: 'ERR_INVALID_ARG_TYPE',
    name: 'TypeError'
  }
);
assert.throws(
  () => fs.chownSync('not_a_file_that_exists', i, 1),
  {
    code: 'ERR_INVALID_ARG_TYPE',
    name: 'TypeError'
  }
fork icon0
star icon0
watch icon0

+ 5 other calls in file

87
88
89
90
91
92
93
94
95
CACHE_DIR = path.resolve(common.cache, '' + cacheIteration++)
npm.config.set('cache', CACHE_DIR)
mkdirp.sync(CACHE_DIR)

if (isRoot && sudoUID && sudoGID) {
  chownSync(CACHE_DIR, sudoUID, sudoGID)
}

installAskedFor = undefined
fork icon0
star icon0
watch icon0