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

Side by Side Diff: lib/cros_build_lib.py

Issue 5025002: Fix infinite loop when FindRepoDir argument is a relative path. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Created 10 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Common python commands used by various build scripts.""" 5 """Common python commands used by various build scripts."""
6 6
7 import inspect 7 import inspect
8 import os 8 import os
9 import subprocess 9 import subprocess
10 import sys 10 import sys
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 140
141 def FindRepoDir(path=None): 141 def FindRepoDir(path=None):
142 """Returns the nearest higher-level repo dir from the specified path. 142 """Returns the nearest higher-level repo dir from the specified path.
143 143
144 Args: 144 Args:
145 path: The path to use. Defaults to cwd. 145 path: The path to use. Defaults to cwd.
146 """ 146 """
147 if path is None: 147 if path is None:
148 path = os.getcwd() 148 path = os.getcwd()
149 path = os.path.abspath(path)
149 while path != '/': 150 while path != '/':
150 repo_dir = os.path.join(path, '.repo') 151 repo_dir = os.path.join(path, '.repo')
151 if os.path.isdir(repo_dir): 152 if os.path.isdir(repo_dir):
152 return repo_dir 153 return repo_dir
153 path = os.path.dirname(path) 154 path = os.path.dirname(path)
154 return None 155 return None
155 156
156 157
157 def ReinterpretPathForChroot(path): 158 def ReinterpretPathForChroot(path):
158 """Returns reinterpreted path from outside the chroot for use inside. 159 """Returns reinterpreted path from outside the chroot for use inside.
159 160
160 Keyword arguments: 161 Keyword arguments:
161 path: The path to reinterpret. Must be in src tree. 162 path: The path to reinterpret. Must be in src tree.
162 """ 163 """
163 root_path = os.path.join(FindRepoDir(path), '..') 164 root_path = os.path.join(FindRepoDir(path), '..')
164 165
165 path_abs_path = os.path.abspath(path) 166 path_abs_path = os.path.abspath(path)
166 root_abs_path = os.path.abspath(root_path) 167 root_abs_path = os.path.abspath(root_path)
167 168
168 # Strip the repository root from the path and strip first /. 169 # Strip the repository root from the path and strip first /.
169 relative_path = path_abs_path.replace(root_abs_path, '')[1:] 170 relative_path = path_abs_path.replace(root_abs_path, '')[1:]
170 171
171 if relative_path == path_abs_path: 172 if relative_path == path_abs_path:
172 raise Exception('Error: path is outside your src tree, cannot reinterpret.') 173 raise Exception('Error: path is outside your src tree, cannot reinterpret.')
173 174
174 new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path) 175 new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path)
175 return new_path 176 return new_path
176 177
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698