[tor-commits] [tor/master] practracker: Normalize filesystem paths across Windows and Posix.

nickm at torproject.org nickm at torproject.org
Wed Mar 13 13:30:09 UTC 2019


commit 8c9835c6e5de6f17affb9b7d9f5802dee54a9e37
Author: George Kadianakis <desnacked at riseup.net>
Date:   Tue Mar 5 15:03:27 2019 +0200

    practracker: Normalize filesystem paths across Windows and Posix.
    
    This was causing issues because the exceptions file is written using Posix
    paths, whereas practracker in Windows was trying to match Windows paths ("\"
    instead of "/").
---
 scripts/maint/practracker/problem.py | 7 ++++++-
 scripts/maint/practracker/util.py    | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/maint/practracker/problem.py b/scripts/maint/practracker/problem.py
index 2330098ef..00e029d1c 100644
--- a/scripts/maint/practracker/problem.py
+++ b/scripts/maint/practracker/problem.py
@@ -7,6 +7,8 @@ problem is worse than a registered exception so that it only warns when things
 get worse.
 """
 
+import os.path
+
 class ProblemVault(object):
     """
     Singleton where we store the various new problems we
@@ -70,7 +72,10 @@ class Problem(object):
 
     def key(self):
         """Generate a unique key that describes this problem that can be used as a dictionary key"""
-        return "%s:%s" % (self.problem_location, self.problem_type)
+        # Problem location is a filesystem path, so we need to normalize this
+        # across platforms otherwise same paths are not gonna match.
+        canonical_location = os.path.normcase(self.problem_location)
+        return "%s:%s" % (canonical_location, self.problem_type)
 
     def __str__(self):
         return "problem %s %s %s" % (self.problem_type, self.problem_location, self.metric_value)
diff --git a/scripts/maint/practracker/util.py b/scripts/maint/practracker/util.py
index 905cb8a5e..966c62515 100644
--- a/scripts/maint/practracker/util.py
+++ b/scripts/maint/practracker/util.py
@@ -18,7 +18,7 @@ def get_tor_c_files(tor_topdir):
 
             # Exclude the excluded paths
             full_path = os.path.join(root,filename)
-            if any(exclude_dir in full_path for exclude_dir in EXCLUDE_SOURCE_DIRS):
+            if any(os.path.normcase(exclude_dir) in full_path for exclude_dir in EXCLUDE_SOURCE_DIRS):
                 continue
 
             files_list.append(full_path)





More information about the tor-commits mailing list