bversion/storage/versioned_storage.py
def verify_fs(self) -> str:
        """
        Checks index structure is intact, and reads and rehashes the entire
        filesystem to ensure than hashes have not changed.
        """

        head, reachable_objects = self.get_reachable_objects()
        all_objects             = self.get_all_object_hashes()

        issues = []

        #================================================================
        # if head is root, but commits exists, this is suspisious
        #================================================================
        number_of_commits = 0
        for object_hash in all_objects['index']:
            object_path = sfs.cpjoin(self.base_path, 'index', object_hash[:2], object_hash[2:])
            file_contents = json.loads(sfs.file_get_contents(object_path))
            if file_contents['type'] == 'commit':
                number_of_commits += 1

        if head == 'root' and number_of_commits != 0:
            msg = 'Commits exist, but head is root.'
            print(msg)
            issues.append(msg)
            return False, issues

        #================================================================
        # Subtract the two, to find if there are unreachable objects
        #================================================================
        # index objects
        index_objects_that_should_exist =   set(reachable_objects['commits'].keys()) \
                                          | set(reachable_objects['trees'])

        index_objects_that_do_exist     =   set(all_objects['index'].keys())

        # file objects
        file_objects_that_should_exist =   set(reachable_objects['files'].keys())
        file_objects_that_do_exist     =   set(all_objects['files'].keys())

        # ===============
        garbage_index_objects = index_objects_that_should_exist - index_objects_that_do_exist
        garbage_file_objects = file_objects_that_should_exist - file_objects_that_do_exist

        # ===============
        for it in garbage_index_objects:
            msg = 'Garbage index object: ' + it
            print(msg)
            issues.append(msg)

        for it in garbage_file_objects:
            msg = 'Garbage file object: ' + it
            print(msg)
            issues.append(msg)

        #================================================================
        # Re hash all objects to check that the hashes have not changed
        #================================================================
        for object_hash, object_path in all_objects['index'].items():
            print('Rehashing: ' + object_path)
            current_hash = sfs.hash_file(object_path)
            if object_hash != current_hash:
                msg = 'Index opject hash has changed: ' + object_hash
                print(msg)
                issues.append(msg)

        for object_hash, object_path in all_objects['files'].items():
            print('Rehashing: ' + object_path)
            current_hash = sfs.hash_file(object_path)
            if object_hash != current_hash:
                msg = 'File object hash has changed: ' + object_hash
                print(msg)
                issues.append(msg)

        # ================================
        return len(issues) == 0, issues

        Checks index structure is intact, and reads and rehashes the entire
        filesystem to ensure than hashes have not changed.
        
Checks index structure is intact, and reads and rehashes the entire
filesystem to ensure than hashes have not changed.
Checks index structure is intact and reads and rehashes the entire filesystem to ensure than hashes have not changed .
def verify_fs(self) -> str:
        head, reachable_objects = self.get_reachable_objects()
        all_objects             = self.get_all_object_hashes()
        issues = []
        number_of_commits = 0
        for object_hash in all_objects['index']:
            object_path = sfs.cpjoin(self.base_path, 'index', object_hash[:2], object_hash[2:])
            file_contents = json.loads(sfs.file_get_contents(object_path))
            if file_contents['type'] == 'commit':
                number_of_commits += 1
        if head == 'root' and number_of_commits != 0:
            msg = 'Commits exist, but head is root.'
            print(msg)
            issues.append(msg)
            return False, issues
        index_objects_that_should_exist =   set(reachable_objects['commits'].keys()) \
                                          | set(reachable_objects['trees'])
        index_objects_that_do_exist     =   set(all_objects['index'].keys())
        file_objects_that_should_exist =   set(reachable_objects['files'].keys())
        file_objects_that_do_exist     =   set(all_objects['files'].keys())
        garbage_index_objects = index_objects_that_should_exist - index_objects_that_do_exist
        garbage_file_objects = file_objects_that_should_exist - file_objects_that_do_exist
        for it in garbage_index_objects:
            msg = 'Garbage index object: ' + it
            print(msg)
            issues.append(msg)
        for it in garbage_file_objects:
            msg = 'Garbage file object: ' + it
            print(msg)
            issues.append(msg)
        for object_hash, object_path in all_objects['index'].items():
            print('Rehashing: ' + object_path)
            current_hash = sfs.hash_file(object_path)
            if object_hash != current_hash:
                msg = 'Index opject hash has changed: ' + object_hash
                print(msg)
                issues.append(msg)
        for object_hash, object_path in all_objects['files'].items():
            print('Rehashing: ' + object_path)
            current_hash = sfs.hash_file(object_path)
            if object_hash != current_hash:
                msg = 'File object hash has changed: ' + object_hash
                print(msg)
                issues.append(msg)
        =================
        return len(issues) == 0, issues
def verify_fs ( self ) -> str : head , reachable_objects = self . get_reachable_objects ( ) all_objects = self . get_all_object_hashes ( ) issues = [ ] number_of_commits = 0 for object_hash in all_objects [ 'index' ] : object_path = sfs . cpjoin ( self . base_path , 'index' , object_hash [ : 2 ] , object_hash [ 2 : ] ) file_contents = json . loads ( sfs . file_get_contents ( object_path ) ) if file_contents [ 'type' ] == 'commit' : number_of_commits += 1 if head == 'root' and number_of_commits != 0 : msg = 'Commits exist, but head is root.' print ( msg ) issues . append ( msg ) return False , issues index_objects_that_should_exist = set ( reachable_objects [ 'commits' ] . keys ( ) ) | set ( reachable_objects [ 'trees' ] ) index_objects_that_do_exist = set ( all_objects [ 'index' ] . keys ( ) ) file_objects_that_should_exist = set ( reachable_objects [ 'files' ] . keys ( ) ) file_objects_that_do_exist = set ( all_objects [ 'files' ] . keys ( ) ) garbage_index_objects = index_objects_that_should_exist - index_objects_that_do_exist garbage_file_objects = file_objects_that_should_exist - file_objects_that_do_exist for it in garbage_index_objects : msg = 'Garbage index object: ' + it print ( msg ) issues . append ( msg ) for it in garbage_file_objects : msg = 'Garbage file object: ' + it print ( msg ) issues . append ( msg ) for object_hash , object_path in all_objects [ 'index' ] . items ( ) : print ( 'Rehashing: ' + object_path ) current_hash = sfs . hash_file ( object_path ) if object_hash != current_hash : msg = 'Index opject hash has changed: ' + object_hash print ( msg ) issues . append ( msg ) for object_hash , object_path in all_objects [ 'files' ] . items ( ) : print ( 'Rehashing: ' + object_path ) current_hash = sfs . hash_file ( object_path ) if object_hash != current_hash : msg = 'File object hash has changed: ' + object_hash print ( msg ) issues . append ( msg ) return len ( issues ) == 0 , issues
Checks index structure is intact, and reads and rehashes the entire
filesystem to ensure than hashes have not changed.
Checks index structure is intact and reads and rehashes the entire filesystem to ensure than hashes have not changed .
"""
        Checks index structure is intact, and reads and rehashes the entire
        filesystem to ensure than hashes have not changed.
        """ #================================================================ # if head is root, but commits exists, this is suspisious #================================================================ #================================================================ # Subtract the two, to find if there are unreachable objects #================================================================ # index objects # file objects # =============== # =============== #================================================================ # Re hash all objects to check that the hashes have not changed #================================================================ # ================================
self