From 7aefe2bf5b394c2b03b0df6512cac23cbdc4740b Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Thu, 24 May 2012 11:58:35 -0400 Subject: [PATCH] bug 632616 - fix symbolstore.py's handling of relative paths. r=catlee --- toolkit/crashreporter/Makefile.in | 3 ++ toolkit/crashreporter/tools/symbolstore.py | 6 +-- .../crashreporter/tools/unit-symbolstore.py | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 toolkit/crashreporter/tools/unit-symbolstore.py diff --git a/toolkit/crashreporter/Makefile.in b/toolkit/crashreporter/Makefile.in index 69891a26a53..b2a4c094351 100644 --- a/toolkit/crashreporter/Makefile.in +++ b/toolkit/crashreporter/Makefile.in @@ -98,3 +98,6 @@ endif include $(topsrcdir)/config/config.mk include $(topsrcdir)/ipc/chromium/chromium-config.mk include $(topsrcdir)/config/rules.mk + +check:: + $(PYTHON) $(srcdir)/tools/unit-symbolstore.py diff --git a/toolkit/crashreporter/tools/symbolstore.py b/toolkit/crashreporter/tools/symbolstore.py index 9d2b705bf37..57f4d5b7f96 100755 --- a/toolkit/crashreporter/tools/symbolstore.py +++ b/toolkit/crashreporter/tools/symbolstore.py @@ -286,9 +286,9 @@ class HGFileInfo(VCSFileInfo): if self.revision and self.clean_root: if self.srcdir: # strip the base path off - file = os.path.normpath(file) - if IsInDir(file, self.srcdir): - file = file[len(self.srcdir):] + abs_file = os.path.abspath(file) + if IsInDir(abs_file, self.srcdir): + file = abs_file[len(self.srcdir):] if file.startswith('/') or file.startswith('\\'): file = file[1:] return "hg:%s:%s:%s" % (self.clean_root, file, self.revision) diff --git a/toolkit/crashreporter/tools/unit-symbolstore.py b/toolkit/crashreporter/tools/unit-symbolstore.py new file mode 100644 index 00000000000..6e7cc4dc49d --- /dev/null +++ b/toolkit/crashreporter/tools/unit-symbolstore.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import os, tempfile, unittest, shutil +import symbolstore + +class TestGetVCSFilename(unittest.TestCase): + """ + Unit tests for GetVCSFilename + + """ + def setUp(self): + self.srcdir = tempfile.mkdtemp() + # make it look vaguely like a hg repo + os.mkdir(os.path.join(self.srcdir, ".hg")) + # and force-feed it to the symbolstore cache + symbolstore.HGRepoInfo.repos[self.srcdir] = \ + symbolstore.HGRepoInfo("http://example.com/repo", + "abcd", + 'example.com/repo') + objdir = os.path.join(self.srcdir, "obj") + os.mkdir(objdir) + self.oldcwd = os.getcwd() + os.chdir(objdir) + + def tearDown(self): + os.chdir(self.oldcwd) + shutil.rmtree(self.srcdir) + + def testRelativePath(self): + """ + Test that a relative path doesn't get + removed. + + """ + vcsfile, root = symbolstore.GetVCSFilename("../foo.h", [self.srcdir]) + vcs,location,filename,rev = vcsfile.split(":") + self.assertEqual(filename, "foo.h") + +if __name__ == '__main__': + unittest.main()