[mirrorbrain-commits] r8271 - in /trunk/mb/mb: files.py util.py

From: <poeml_at_mirrorbrain.org>
Date: Wed, 11 Apr 2012 21:20:45 -0000
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
_at_@ -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'
_at_@ -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
_at_@ -210,3 +210,9 @@
         netloc = netloc.split('_at_')[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-request_at_mirrorbrain.org
Received on Wed Apr 11 2012 - 21:20:46 GMT

This archive was generated by hypermail 2.3.0 : Wed Apr 11 2012 - 21:32:03 GMT