Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 def IsSameFilePath(path1, path2): | |
| 7 """Determines if two paths represent same path. | |
|
Martin Barbella
2016/04/15 06:05:24
What's the use case for this? Just trying to under
Sharu
2016/04/15 22:59:46
If a file moved directory, like from 'a/b/c/file.c
| |
| 8 | |
| 9 Compares the name of the folders in the path (by split('/')), and checks | |
| 10 if they match either more than 3 or min of path lengths. | |
|
stgao
2016/04/15 18:35:18
How about adding the reason behind this comparison
Sharu
2016/04/15 22:59:46
I just port over this method which is the method w
| |
| 11 | |
| 12 Args: | |
| 13 path1 (str): First path. | |
| 14 path2 (str): Second path to compare. | |
| 15 | |
| 16 Returns: | |
| 17 Boolean, True if it they are thought to be a same path, False otherwise. | |
| 18 """ | |
| 19 path_parts1 = path1.split('/') | |
|
Martin Barbella
2016/04/15 06:05:24
Nit: _1. Ditto for the other.
Sharu
2016/04/15 22:59:46
Done.
| |
| 20 path_parts2 = path2.split('/') | |
| 21 | |
| 22 if path_parts1[-1] != path_parts2[-1]: | |
| 23 return False | |
| 24 | |
| 25 intersection = set(path_parts1).intersection(set(path_parts2)) | |
| 26 return len(intersection) >= (min(3, min(len(path_parts1), | |
|
stgao
2016/04/15 18:35:18
min(3, 2, 1) == 1
Sharu
2016/04/15 22:59:46
I think this is the intended behavior of this meth
| |
| 27 len(path_parts2)))) | |
| OLD | NEW |