Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | var fs = require('fs')
|
---|
2 | var core
|
---|
3 | if (process.platform === 'win32' || global.TESTING_WINDOWS) {
|
---|
4 | core = require('./windows.js')
|
---|
5 | } else {
|
---|
6 | core = require('./mode.js')
|
---|
7 | }
|
---|
8 |
|
---|
9 | module.exports = isexe
|
---|
10 | isexe.sync = sync
|
---|
11 |
|
---|
12 | function isexe (path, options, cb) {
|
---|
13 | if (typeof options === 'function') {
|
---|
14 | cb = options
|
---|
15 | options = {}
|
---|
16 | }
|
---|
17 |
|
---|
18 | if (!cb) {
|
---|
19 | if (typeof Promise !== 'function') {
|
---|
20 | throw new TypeError('callback not provided')
|
---|
21 | }
|
---|
22 |
|
---|
23 | return new Promise(function (resolve, reject) {
|
---|
24 | isexe(path, options || {}, function (er, is) {
|
---|
25 | if (er) {
|
---|
26 | reject(er)
|
---|
27 | } else {
|
---|
28 | resolve(is)
|
---|
29 | }
|
---|
30 | })
|
---|
31 | })
|
---|
32 | }
|
---|
33 |
|
---|
34 | core(path, options || {}, function (er, is) {
|
---|
35 | // ignore EACCES because that just means we aren't allowed to run it
|
---|
36 | if (er) {
|
---|
37 | if (er.code === 'EACCES' || options && options.ignoreErrors) {
|
---|
38 | er = null
|
---|
39 | is = false
|
---|
40 | }
|
---|
41 | }
|
---|
42 | cb(er, is)
|
---|
43 | })
|
---|
44 | }
|
---|
45 |
|
---|
46 | function sync (path, options) {
|
---|
47 | // my kingdom for a filtered catch
|
---|
48 | try {
|
---|
49 | return core.sync(path, options || {})
|
---|
50 | } catch (er) {
|
---|
51 | if (options && options.ignoreErrors || er.code === 'EACCES') {
|
---|
52 | return false
|
---|
53 | } else {
|
---|
54 | throw er
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.