From 666eb33dfc35d676f92d6ddaa1283477f9df0b37 Mon Sep 17 00:00:00 2001 From: "skylined@chromium.org" Date: Mon, 8 Jun 2009 14:04:23 +0000 Subject: [PATCH] PathDifference cuts a supplied "root path" from a second path and returns what remains. It is assumed that this can be used as a relative path from the "root path" to the second path. If the root path ends with a path separator (\ or /), the function used to cut an additional character from the path and the returned value would be incorrect. This fix makes sure the behavior is consistent and correct no matter if the root path ends with a separator or not. (This fixes the "epot_tools" tools bug.) Review URL: http://codereview.chromium.org/118376 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@17855 0039d316-1c4b-4281-b951-d872f2087c98 --- trychange.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/trychange.py b/trychange.py index 7facec34a7..5c8c1c57bf 100755 --- a/trychange.py +++ b/trychange.py @@ -66,8 +66,11 @@ def PathDifference(root, subpath): """Returns the difference subpath minus root.""" if subpath.find(root) != 0: return None - # The + 1 is for the trailing / or \. - return subpath[len(root) + len(os.sep):] + # If the root does not have a trailing \ or /, we add it so the returned path + # starts immediately after the seperator regardless of whether it is provided. + if not root.endswith(os.sep): + root += os.sep + return subpath[len(root):] def GetSourceRoot():