4
* Ensures that files are not executable unless they are either binary or
7
final class ArcanistChmodLinter extends ArcanistLinter {
9
const LINT_INVALID_EXECUTABLE = 1;
11
public function getInfoName() {
15
public function getInfoDescription() {
17
'Checks the permissions on files and ensures that they are not made to '.
18
'be executable unnecessarily. In particular, a file should not be '.
19
'executable unless it is either binary or contain a shebang.');
22
public function getLinterName() {
26
public function getLinterConfigurationName() {
30
public function shouldLintBinaryFiles() {
34
public function getLintNameMap() {
36
self::LINT_INVALID_EXECUTABLE => pht('Invalid Executable'),
40
public function getLintSeverityMap() {
42
self::LINT_INVALID_EXECUTABLE => ArcanistLintSeverity::SEVERITY_WARNING,
46
public function lintPath($path) {
47
if (is_executable($path)) {
48
if ($this->getEngine()->isBinaryFile($path)) {
49
$mime = Filesystem::getMimeType($path);
53
case 'application/jar':
54
case 'application/java-archive':
55
case 'application/x-bzip2':
56
case 'application/x-gzip':
57
case 'application/x-rar-compressed':
58
case 'application/x-tar':
59
case 'application/zip':
68
case 'application/vnd.ms-fontobject':
69
case 'application/x-font-ttf':
70
case 'application/x-woff':
73
case 'application/x-shockwave-flash':
79
case 'image/x-ms-bmp':
82
case 'application/msword':
83
case 'application/pdf':
84
case 'application/postscript':
85
case 'application/rtf':
86
case 'application/vnd.ms-excel':
87
case 'application/vnd.ms-powerpoint':
91
case 'video/quicktime':
93
case 'video/x-msvideo':
94
case 'video/x-ms-wmv':
96
$this->raiseLintAtPath(
97
self::LINT_INVALID_EXECUTABLE,
98
pht("'%s' files should not be executable.", $mime));
102
// Path is a binary file, which makes it a valid executable.
104
} else if ($this->getShebang($path)) {
105
// Path contains a shebang, which makes it a valid executable.
108
$this->raiseLintAtPath(
109
self::LINT_INVALID_EXECUTABLE,
111
'Executable files should either be binary or contain a shebang.'));
117
* Returns the path's shebang.
120
* @return string|null
122
private function getShebang($path) {
123
$line = head(phutil_split_lines($this->getEngine()->loadData($path), true));
126
if (preg_match('/^#!(.*)$/', $line, $matches)) {