Author: poeml
Date: Wed Apr 11 23:20:45 2012
New Revision: 8271

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8271&view=rev
Log:
mb makehashes:
- fixing issue #94 by escaping string literals in the regular expression that 
we use to 
  search for existing files in the hash table. Otherwise they would be used as
  regexp themselves by PostgreSQL. Thanks KDE sysadmins for help!

Modified:
    trunk/mb/mb/files.py
    trunk/mb/mb/util.py

Modified: trunk/mb/mb/files.py
URL: 
http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/files.py?rev=8271&r1=8270&r2=8271&view=diff
==============================================================================
--- trunk/mb/mb/files.py        (original)
+++ trunk/mb/mb/files.py        Wed Apr 11 23:20:45 2012
@@ -1,5 +1,6 @@
 from sqlobject.sqlbuilder import AND
 
+from mb import util
 
 def has_file(conn, path, mirror_id):
     """check if file 'path' exists on mirror 'mirror_id'
@@ -156,7 +157,7 @@
                    FROM filearr 
                LEFT JOIN hash 
                    ON hash.file_id = filearr.id 
-               WHERE filearr.path ~ '^%s/[^/]*$'""" % path
+               WHERE filearr.path ~ '^""" + util.pgsql_regexp_esc(path) 
+"""/[^/]*$'""" 
 
     result = conn.Server._connection.queryAll(query)
     return result

Modified: trunk/mb/mb/util.py
URL: 
http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/util.py?rev=8271&r1=8270&r2=8271&view=diff
==============================================================================
--- trunk/mb/mb/util.py (original)
+++ trunk/mb/mb/util.py Wed Apr 11 23:20:45 2012
@@ -210,3 +210,9 @@
         netloc = netloc.split('@')[1]
     return urlparse.urlunsplit((u[0], netloc, u[2], u[3], u[4]))
 
+def pgsql_regexp_esc(s):
+    if s:
+        return '\\\\' + '\\\\'.join(['%03o' % ord(c) for c in s])
+    else:
+        return s
+




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
        unsubscribe
to the address mirrorbrain-commits-requ...@mirrorbrain.org

Reply via email to