edk2toollib/utility_functions.py
def RemoveTree(dir_path: str, ignore_errors: bool = False) -> None:
    '''
    Helper for removing a directory.  Over time there have been
    many private implementations of this due to reliability issues in the
    shutil implementations.  To consolidate on a single function this helper is added.

    On error try to change file attributes.  Also add retry logic.

    dir_path: Path to directory to remove.
    ignore_errors: ignore errors during removal
    '''

    def remove_readonly(func, path, _):
        ''' private function to attempt to change permissions on file/folder being deleted'''
        os.chmod(path, stat.S_IWRITE)
        func(path)

    for _ in range(3):  # retry up to 3 times
        try:
            shutil.rmtree(dir_path, ignore_errors=ignore_errors, onerror=remove_readonly)
        except OSError as err:
            logging.warning(f"Failed to fully remove {dir_path}: {err}")
        else:
            break
    else:
        raise RuntimeError(f"Failed to remove {dir_path}")

    Helper for removing a directory.  Over time there have been
    many private implementations of this due to reliability issues in the
    shutil implementations.  To consolidate on a single function this helper is added.

    On error try to change file attributes.  Also add retry logic.

    dir_path: Path to directory to remove.
    ignore_errors: ignore errors during removal
    
Helper for removing a directory.  Over time there have been
many private implementations of this due to reliability issues in the
shutil implementations.  To consolidate on a single function this helper is added.

On error try to change file attributes.  Also add retry logic.

Path to directory to remove.
ignore_errors: ignore errors during removal
Helper for removing a directory . Over time there have been many private implementations of this due to reliability issues in the shutil implementations . To consolidate on a single function this helper is added . On error try to change file attributes . Also add retry logic . Path to directory to remove . ignore_errors : ignore errors during removal
def RemoveTree(dir_path: str, ignore_errors: bool = False) -> None:
    def remove_readonly(func, path, _):
        os.chmod(path, stat.S_IWRITE)
        func(path)
    for _ in range(3):  
        try:
            shutil.rmtree(dir_path, ignore_errors=ignore_errors, onerror=remove_readonly)
        except OSError as err:
            logging.warning(f"Failed to fully remove {dir_path}: {err}")
        else:
            break
    else:
        raise RuntimeError(f"Failed to remove {dir_path}")
def RemoveTree ( dir_path : str , ignore_errors : bool = False ) -> None : def remove_readonly ( func , path , _ ) : ''' private function to attempt to change permissions on file/folder being deleted''' os . chmod ( path , stat . S_IWRITE ) func ( path ) for _ in range ( 3 ) : try : shutil . rmtree ( dir_path , ignore_errors = ignore_errors , onerror = remove_readonly ) except OSError as err : logging . warning ( f"Failed to fully remove {dir_path}: {err}" ) else : break else : raise RuntimeError ( f"Failed to remove {dir_path}" )
Helper for removing a directory.
Helper for removing a directory .
'''
    Helper for removing a directory.  Over time there have been
    many private implementations of this due to reliability issues in the
    shutil implementations.  To consolidate on a single function this helper is added.

    On error try to change file attributes.  Also add retry logic.

    dir_path: Path to directory to remove.
    ignore_errors: ignore errors during removal
    ''' ''' private function to attempt to change permissions on file/folder being deleted''' # retry up to 3 times
dir_path
str
ignore_errors
bool