def remove_reference(self, name, expire=MARKER): file_path = self.get_reference_path(name) temporary_file_path = file_path + '.' + make_uuid_hash() move_file(file_path, temporary_file_path, retries=self.retries, retry_errno=self.retry_errno) references = self._get_references(temporary_file_path, name='') if name in references: references.remove(name) # Validate if references still exists if references: if expire is MARKER: # Dont use expire, we only need to know if file exists expire = None for name in references: path = self.get_file_path(name) if not self._contains(path, expire=expire): references.remove(name) if references: references = maybe_list(references) references.append(b_linesep) put_binary_on_file( file_path, binary=bytes_join(b_linesep, references), mode='ab', retries=self.retries, retry_errno=self.retry_errno) self._delete_path(temporary_file_path)
def delete_session_key_tokens(self, session_key_256): file_path = self.get_reference_file_path(session_key_256) if isfile(file_path): temporary_file_path = self.get_reference_file_path(session_key_256 + '.tmp') move_file(file_path, temporary_file_path) binary = get_file_binary(temporary_file_path, mode='r') if binary: tokens_to_delete = binary.splitlines() if tokens_to_delete: for token_256 in set(tokens_to_delete): if token_256: token_file_path = self.get_token_file_path(token_256) remove_file_quietly(token_file_path) # Remove references file remove_file_quietly(temporary_file_path) return True