Revision 7759260d

b/pithos/backends/lib/sqlalchemy/dbworker.py
39 39
        self.params = params
40 40
        self.conn = params['wrapper'].conn
41 41
        self.engine = params['wrapper'].engine
42
    
43
    def escape_like(self, s):
44
        return s.replace('\\', '\\\\').replace('%', '\%').replace('_', '\_')
b/pithos/backends/lib/sqlalchemy/node.py
210 210
        """
211 211
        
212 212
        # Use LIKE for comparison to avoid MySQL problems with trailing spaces.
213
        path = path.replace('%', '\%')
214
        path = path.replace('_', '\_')
215
        s = select([self.nodes.c.node], self.nodes.c.path.like(path, escape='\\'))
213
        s = select([self.nodes.c.node], self.nodes.c.path.like(self.escape_like(path), escape='\\'))
216 214
        r = self.conn.execute(s)
217 215
        row = r.fetchone()
218 216
        r.close()
......
541 539
            self.versions.c.node == v.c.node)
542 540
        if before != inf:
543 541
            c1 = c1.where(self.versions.c.mtime < before)
544
        c2 = select([self.nodes.c.node], self.nodes.c.path.like(path + '%'))
542
        c2 = select([self.nodes.c.node], self.nodes.c.path.like(self.escape_like(path) + '%', escape='\\'))
545 543
        s = s.where(and_(v.c.serial == c1,
546 544
                         v.c.cluster != except_cluster,
547 545
                         v.c.node.in_(c2)))
......
744 742
        s = s.where(n.c.node == v.c.node)
745 743
        conj = []
746 744
        for x in pathq:
747
            conj.append(n.c.path.like(x + '%'))
745
            conj.append(n.c.path.like(self.escape_like(x) + '%', escape='\\'))
748 746
        if conj:
749 747
            s = s.where(or_(*conj))
750 748
        rp = self.conn.execute(s)
......
823 821
        s = s.where(and_(n.c.path > bindparam('start'), n.c.path < nextling))
824 822
        conj = []
825 823
        for x in pathq:
826
            conj.append(n.c.path.like(x + '%'))
824
            conj.append(n.c.path.like(self.escape_like(x) + '%', escape='\\'))
827 825
        
828 826
        if conj:
829 827
            s = s.where(or_(*conj))
b/pithos/backends/lib/sqlalchemy/permissions.py
132 132
                    self.xfeaturevals.c.value == u.c.value)
133 133
        s = select([self.xfeatures.c.path], from_obj=[inner_join]).distinct()
134 134
        if prefix:
135
            s = s.where(self.xfeatures.c.path.like(prefix + '%'))
135
            s = s.where(self.xfeatures.c.path.like(self.escape_like(prefix) + '%', escape='\\'))
136 136
        r = self.conn.execute(s)
137 137
        l = [row[0] for row in r.fetchall()]
138 138
        r.close()
......
142 142
        """Return the list of shared paths."""
143 143
        
144 144
        s = select([self.xfeatures.c.path],
145
            self.xfeatures.c.path.like(prefix + '%')).order_by(self.xfeatures.c.path.asc())
145
            self.xfeatures.c.path.like(self.escape_like(prefix) + '%', escape='\\')).order_by(self.xfeatures.c.path.asc())
146 146
        r = self.conn.execute(s)
147 147
        l = [row[0] for row in r.fetchall()]
148 148
        r.close()
b/pithos/backends/lib/sqlalchemy/xfeatures.py
92 92
            return [inherited]
93 93
        
94 94
        s = select([self.xfeatures.c.path, self.xfeatures.c.feature_id])
95
        s = s.where(and_(self.xfeatures.c.path.like(path + '%'),
95
        s = s.where(and_(self.xfeatures.c.path.like(self.escape_like(path) + '%', escape='\\'),
96 96
                     self.xfeatures.c.path != path))
97 97
        s = s.order_by(self.xfeatures.c.path)
98 98
        r = self.conn.execute(s)
b/pithos/backends/lib/sqlite/dbworker.py
45 45
        self.fetchall = cur.fetchall
46 46
        self.cur = cur
47 47
        self.conn = conn
48
    
49
    def escape_like(self, s):
50
        return s.replace('\\', '\\\\').replace('%', '\%').replace('_', '\_')
b/pithos/backends/lib/sqlite/dbwrapper.py
38 38
    
39 39
    def __init__(self, db):
40 40
        self.conn = sqlite3.connect(db, check_same_thread=False)
41
        self.conn.execute(""" pragma case_sensitive_like = on """)
41 42
    
42 43
    def close(self):
43 44
        self.conn.close()
b/pithos/backends/lib/sqlite/node.py
447 447
             "and cluster != ? "
448 448
             "and node in (select node "
449 449
                          "from nodes "
450
                          "where path like ?)")
451
        execute(q, (before, except_cluster, path + '%'))
450
                          "where path like ? escape '\\')")
451
        execute(q, (before, except_cluster, self.escape_like(path) + '%'))
452 452
        r = fetchone()
453 453
        if r is None:
454 454
            return None
......
605 605
            return None, None
606 606
        
607 607
        subq = " and ("
608
        subq += ' or '.join(('n.path like ?' for x in pathq))
608
        subq += ' or '.join(("n.path like ? escape '\\'" for x in pathq))
609 609
        subq += ")"
610
        args = tuple([x + '%' for x in pathq])
610
        args = tuple([self.escape_like(x) + '%' for x in pathq])
611 611
        
612 612
        return subq, args
613 613
    
b/pithos/backends/lib/sqlite/permissions.py
123 123
             "using (feature_id)")
124 124
        p = (member, member)
125 125
        if prefix:
126
            q += " where path like ?"
127
            p += (prefix + '%',)
126
            q += " where path like ? escape '\\'"
127
            p += (self.escape_like(prefix) + '%',)
128 128
        self.execute(q, p)
129 129
        return [r[0] for r in self.fetchall()]
130 130
    
131 131
    def access_list_shared(self, prefix=''):
132 132
        """Return the list of shared paths."""
133 133
        
134
        q = "select path from xfeatures where path like ?"
135
        self.execute(q, (prefix + '%',))
134
        q = "select path from xfeatures where path like ? escape '\\'"
135
        self.execute(q, (self.escape_like(prefix) + '%',))
136 136
        return [r[0] for r in self.fetchall()]
b/pithos/backends/lib/sqlite/xfeatures.py
84 84
            return [inherited]
85 85
        
86 86
        q = ("select path, feature_id from xfeatures "
87
             "where path like ? and path != ? order by path")
88
        self.execute(q, (path + '%', path,))
87
             "where path like ? escape '\\' and path != ? order by path")
88
        self.execute(q, (self.escape_like(path) + '%', path,))
89 89
        return self.fetchall()
90 90
    
91 91
    def xfeature_create(self, path):

Also available in: Unified diff