| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Makes sure files have the right permissions. | 6 """Makes sure files have the right permissions. |
| 7 | 7 |
| 8 Some developers have broken SCM configurations that flip the svn:executable | 8 Some developers have broken SCM configurations that flip the svn:executable |
| 9 permission on for no good reason. Unix developers who run ls --color will then | 9 permission on for no good reason. Unix developers who run ls --color will then |
| 10 see .cc files in green and get confused. | 10 see .cc files in green and get confused. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 # Not whitelisted, stat the file and check permissions. | 171 # Not whitelisted, stat the file and check permissions. |
| 172 try: | 172 try: |
| 173 st_mode = os.stat(file_path).st_mode | 173 st_mode = os.stat(file_path).st_mode |
| 174 except IOError, e: | 174 except IOError, e: |
| 175 return 'Failed to stat file: %s' % e | 175 return 'Failed to stat file: %s' % e |
| 176 except OSError, e: | 176 except OSError, e: |
| 177 return 'Failed to stat file: %s' % e | 177 return 'Failed to stat file: %s' % e |
| 178 | 178 |
| 179 if EXECUTABLE_PERMISSION & st_mode: | 179 if EXECUTABLE_PERMISSION & st_mode: |
| 180 # Look if the file starts with #!/ |
| 181 with open(file_path, 'rb') as f: |
| 182 if f.read(3) == '#!/': |
| 183 # That's fine. |
| 184 return None |
| 185 # TODO(maruel): Check that non-executable file do not start with a shebang. |
| 180 error = 'Contains executable permission' | 186 error = 'Contains executable permission' |
| 181 if VERBOSE: | 187 if VERBOSE: |
| 182 return '%s: %06o' % (error, st_mode) | 188 return '%s: %06o' % (error, st_mode) |
| 183 return error | 189 return error |
| 184 return None | 190 return None |
| 185 | 191 |
| 186 | 192 |
| 187 def ShouldCheckDirectory(dir_path): | 193 def ShouldCheckDirectory(dir_path): |
| 188 """Determine if we should check the content of dir_path.""" | 194 """Determine if we should check the content of dir_path.""" |
| 189 if not IS_SVN: | 195 if not IS_SVN: |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 success = CheckDirectory(start_dir) | 340 success = CheckDirectory(start_dir) |
| 335 if not success: | 341 if not success: |
| 336 print '\nFAILED\n' | 342 print '\nFAILED\n' |
| 337 return 1 | 343 return 1 |
| 338 print '\nSUCCESS\n' | 344 print '\nSUCCESS\n' |
| 339 return 0 | 345 return 0 |
| 340 | 346 |
| 341 | 347 |
| 342 if '__main__' == __name__: | 348 if '__main__' == __name__: |
| 343 sys.exit(main(sys.argv)) | 349 sys.exit(main(sys.argv)) |
| OLD | NEW |