def run(self): """ Cycles through every database record in order, removing any records associated with files that do not exist. """ ctime = -1.0 while True: while not self._within_window(DATABASE_WINDOWS): _logger.debug("Not in execution window; sleeping" % { 'name': self.name, }) time.sleep(60) records_retrieved = False for record in database.enumerate_all(ctime): ctime = record['physical']['ctime'] records_retrieved = True filesystem = state.get_filesystem(record['physical']['family']) if not filesystem.file_exists(record): _logger.warn("Discovered database record for '%(uid)s' without matching file; dropping record..." % { 'uid': record['_id'], }) database.drop_record(record['_id']) if not records_retrieved: #Cycle complete _logger.debug("All records processed; sleeping") time.sleep(CONFIG.maintainer_database_sleep) ctime = -1.0
def _post(self): request = _get_json(self.request.body) uid = request['uid'] _logger.info("Proceeding with unlink request for '%(uid)s'..." % { 'uid': uid, }) record = database.get_record(uid) if not record: self.send_error(404) return trust = _get_trust(record, request.get('keys'), self.request.remote_ip) if not trust.write: self.send_error(403) return fs = state.get_filesystem(record['physical']['family']) try: fs.unlink(record) except filesystem.FileNotFoundError as e: _logger.error("Database record exists for '%(uid)s', but filesystem entry does not" % { 'uid': uid, }) self.send_error(404) return else: database.drop_record(uid)
def _process_record(self, record): """ Determines whether the given `record` is a candidate for deletion, removing it and the associated file if it is. """ _logger.info("Unlinking record...") filesystem = state.get_filesystem(record['physical']['family']) try: filesystem.unlink(record) except Exception as e: _logger.warn("Unable to unlink record: %(error)s" % { 'error': str(e), }) return False else: database.drop_record(record['_id']) return True