Exemplo n.º 1
0
 def deprecate(self):
     """Deprecates the database"""
     if self.is_deprecated:
         return
     db_name = os.path.join(self.dir, 'database')
     fp = open(db_name + '.index', 'r+b')
     with lock_complete(fp):
         ## FIXME: anyone holding the database open will still be able to write to it
         ## Maybe copy and truncate the database?
         ## FIXME: also this could fail if deprecated also exists, which is kind
         ## of okay, but should be caught more formally
         os.rename(db_name, os.path.join(self.dir, 'deprecated'))
         os.rename(db_name + '.index', os.path.join(self.dir, 'deprecated.index'))
     fp.close()
Exemplo n.º 2
0
 def save_blob(self, name, content_type, data):
     """Saves a blob"""
     dir = os.path.join(self.dir, 'blobs')
     ensure_dir(dir)
     # I believe this is safe from concurrent access, because there
     # can't be more than one writer.  But I'm not sure.  FIXME
     content_type_name = os.path.join(dir, name + '.content-type')
     blob_name = os.path.join(dir, name)
     try:
         fp = open(content_type_name, 'wb')
         with lock_complete(fp):
             fp.write(content_type)
             blob_fp = open(blob_name, 'wb')
             try:
                 blob_fp.write(data)
             finally:
                 blob_fp.close()
     finally:
         fp.close()