Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2061)

Unified Diff: presubmit_support.py

Issue 118370: Add InputApi.ReadFile() and presubmit_canned_checks.CheckChangeHasNoCR(). (Closed)
Patch Set: Use mode 'rb' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « presubmit_canned_checks.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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."""
« no previous file with comments | « presubmit_canned_checks.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698