Galerie und tage
This commit is contained in:
49
node_modules/executable/index.js
generated
vendored
49
node_modules/executable/index.js
generated
vendored
@@ -1,36 +1,47 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const pify = require('pify');
|
||||
|
||||
const isExe = (mode, gid, uid) => {
|
||||
var fs = require('fs');
|
||||
|
||||
function isExe(mode, gid, uid) {
|
||||
if (process.platform === 'win32') {
|
||||
return true;
|
||||
}
|
||||
|
||||
const isGroup = gid ? process.getgid && gid === process.getgid() : true;
|
||||
const isUser = uid ? process.getuid && uid === process.getuid() : true;
|
||||
return (mode & parseInt('0001', 8)) ||
|
||||
(mode & parseInt('0010', 8)) && process.getgid && gid === process.getgid() ||
|
||||
(mode & parseInt('0100', 8)) && process.getuid && uid === process.getuid();
|
||||
}
|
||||
|
||||
return Boolean((mode & 0o0001) ||
|
||||
((mode & 0o0010) && isGroup) ||
|
||||
((mode & 0o0100) && isUser));
|
||||
};
|
||||
|
||||
module.exports = name => {
|
||||
module.exports = function (name, cb) {
|
||||
if (typeof name !== 'string') {
|
||||
return Promise.reject(new TypeError('Expected a string'));
|
||||
throw new Error('Filename required');
|
||||
}
|
||||
|
||||
return pify(fs.stat)(name).then(stats => stats && stats.isFile() && isExe(stats.mode, stats.gid, stats.uid));
|
||||
fs.stat(name, function (err, stats) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (stats && stats.isFile() && isExe(stats.mode, stats.gid, stats.uid)) {
|
||||
cb(null, true);
|
||||
return;
|
||||
}
|
||||
|
||||
cb(null, false);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.sync = name => {
|
||||
module.exports.sync = function (name) {
|
||||
if (typeof name !== 'string') {
|
||||
throw new TypeError('Expected a string');
|
||||
throw new Error('Filename required');
|
||||
}
|
||||
|
||||
const stats = fs.statSync(name);
|
||||
var file = fs.statSync(name);
|
||||
|
||||
return stats && stats.isFile() && isExe(stats.mode, stats.gid, stats.uid);
|
||||
if (file && file.isFile() && isExe(file.mode, file.gid, file.uid)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
module.exports.checkMode = isExe;
|
||||
|
||||
Reference in New Issue
Block a user