 Chromium Code Reviews
 Chromium Code Reviews Issue 118370:
  Add InputApi.ReadFile() and presubmit_canned_checks.CheckChangeHasNoCR().  (Closed)
    
  
    Issue 118370:
  Add InputApi.ReadFile() and presubmit_canned_checks.CheckChangeHasNoCR().  (Closed) 
  | Index: presubmit_support.py | 
| diff --git a/presubmit_support.py b/presubmit_support.py | 
| index 86398cb8f2f07166af24d6544c373bfa67968dae..f83f4bd090ac1a5b391a9402b2c910583ae6bbfa 100755 | 
| --- a/presubmit_support.py | 
| +++ b/presubmit_support.py | 
| @@ -6,7 +6,7 @@ | 
| """Enables directory-specific presubmit checks to run at upload and/or commit. | 
| """ | 
| -__version__ = '1.3' | 
| +__version__ = '1.3.1' | 
| # TODO(joi) Add caching where appropriate/needed. The API is designed to allow | 
| # caching (between all different invocations of presubmit scripts for a given | 
| @@ -271,6 +271,16 @@ class InputApi(object): | 
| filter(lambda x: x.IsTextFile(), | 
| self.AffectedFiles(include_deletes=False))) | 
| + def ReadFile(self, file, mode='r'): | 
| + """Reads an arbitrary file. | 
| + | 
| + Deny reading anything outside the repository.""" | 
| 
Jói Sigurðsson
2009/06/08 10:52:50
For consistency with the rest of the code, please
 | 
| + if isinstance(file, AffectedFile): | 
| + file = file.AbsoluteLocalPath() | 
| + if not file.startswith(self.change.RepositoryRoot()): | 
| + raise IOError('Access outside the repository root is denied.') | 
| + return gcl.ReadFile(file, mode) | 
| + | 
| @staticmethod | 
| def _RightHandSideLinesImpl(affected_files): | 
| """Implements RightHandSideLines for InputApi and GclChange.""" |