Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
909 bytes
|
Line | |
---|
1 | module.exports = isexe
|
---|
2 | isexe.sync = sync
|
---|
3 |
|
---|
4 | var fs = require('fs')
|
---|
5 |
|
---|
6 | function isexe (path, options, cb) {
|
---|
7 | fs.stat(path, function (er, stat) {
|
---|
8 | cb(er, er ? false : checkStat(stat, options))
|
---|
9 | })
|
---|
10 | }
|
---|
11 |
|
---|
12 | function sync (path, options) {
|
---|
13 | return checkStat(fs.statSync(path), options)
|
---|
14 | }
|
---|
15 |
|
---|
16 | function checkStat (stat, options) {
|
---|
17 | return stat.isFile() && checkMode(stat, options)
|
---|
18 | }
|
---|
19 |
|
---|
20 | function checkMode (stat, options) {
|
---|
21 | var mod = stat.mode
|
---|
22 | var uid = stat.uid
|
---|
23 | var gid = stat.gid
|
---|
24 |
|
---|
25 | var myUid = options.uid !== undefined ?
|
---|
26 | options.uid : process.getuid && process.getuid()
|
---|
27 | var myGid = options.gid !== undefined ?
|
---|
28 | options.gid : process.getgid && process.getgid()
|
---|
29 |
|
---|
30 | var u = parseInt('100', 8)
|
---|
31 | var g = parseInt('010', 8)
|
---|
32 | var o = parseInt('001', 8)
|
---|
33 | var ug = u | g
|
---|
34 |
|
---|
35 | var ret = (mod & o) ||
|
---|
36 | (mod & g) && gid === myGid ||
|
---|
37 | (mod & u) && uid === myUid ||
|
---|
38 | (mod & ug) && myUid === 0
|
---|
39 |
|
---|
40 | return ret
|
---|
41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.