# or implied, of GRNET S.A.
from dbworker import DBWorker
-from sqlalchemy import Table, Column, String, Integer, MetaData
-from sqlalchemy.sql import select
+from sqlalchemy import Table, Column, String, Integer, Boolean, MetaData
+from sqlalchemy.sql import and_, select
from sqlalchemy.schema import Index
metadata = MetaData()
columns=[]
columns.append(Column('public_id', Integer, primary_key=True))
- columns.append(Column('path', String(2048)))
+ columns.append(Column('path', String(2048), nullable=False))
+ columns.append(Column('active', Boolean, nullable=False, default=True))
self.public = Table('public', metadata, *columns, mysql_engine='InnoDB', sqlite_autoincrement=True)
# place an index on path
Index('idx_public_path', self.public.c.path, unique=True)
metadata.create_all(self.engine)
def public_set(self, path):
- s = self.public.select()
+ s = select([self.public.c.public_id])
s = s.where(self.public.c.path == path)
r = self.conn.execute(s)
- public = r.fetchall()
+ row = r.fetchone()
r.close()
- if len(public) == 0:
+ if row:
+ s = self.public.update().where(self.public.c.public_id == row[0])
+ s = s.values(active=True)
+ else:
s = self.public.insert()
- r = self.conn.execute(s, path = path)
- r.close()
+ s = s.values(path=path, active=True)
+ r = self.conn.execute(s)
+ r.close()
def public_unset(self, path):
- s = self.public.delete().where(self.public.c.path == path)
+ s = self.public.update()
+ s = s.where(self.public.c.path == path)
+ s = s.values(active=False)
r = self.conn.execute(s)
r.close()
def public_get(self, path):
- s = select([self.public.c.public_id], self.public.c.path == path)
+ s = select([self.public.c.public_id])
+ s = s.where(and_(self.public.c.path == path,
+ self.public.c.active == True))
r = self.conn.execute(s)
row = r.fetchone()
r.close()
return None
def public_path(self, public):
- s = select([self.public.c.path], self.public.c.public_id == public)
+ s = select([self.public.c.path])
+ s = s.where(and_(self.public.c.public_id == public,
+ self.public.c.active == True))
r = self.conn.execute(s)
row = r.fetchone()
r.close()
execute(""" create table if not exists public
( public_id integer primary key autoincrement,
- path text ) """)
+ path text not null,
+ active boolean not null default 1 ) """)
execute(""" create unique index if not exists idx_public_path
on public(path) """)
def public_set(self, path):
q = "insert or ignore into public (path) values (?)"
self.execute(q, (path,))
+ q = "update public set active = 1 where path = ?"
+ self.execute(q, (path,))
def public_unset(self, path):
- q = "delete from public where path = ?"
+ q = "update public set active = 0 where path = ?"
self.execute(q, (path,))
def public_get(self, path):
- q = "select public_id from public where path = ?"
+ q = "select public_id from public where path = ? and active = 1"
self.execute(q, (path,))
row = self.fetchone()
if row:
return None
def public_path(self, public):
- q = "select path from public where public_id = ?"
+ q = "select path from public where public_id = ? and active = 1"
self.execute(q, (public,))
row = self.fetchone()
if row:
@backend_method
def get_uuid(self, user, uuid):
"""Return the (account, container, name) for the UUID given."""
+
logger.debug("get_uuid: %s", uuid)
info = self.node.latest_uuid(uuid)
if info is None:
@backend_method
def get_public(self, user, public):
"""Return the (account, container, name) for the public id given."""
+
logger.debug("get_public: %s", public)
if public is None or public < ULTIMATE_ANSWER:
raise NameError