def get_persistent_storage_path()

in app/app.py [0:0]


def get_persistent_storage_path(filename: str) -> tuple[Path, bool]:
    """Check if persistent storage is available and return the appropriate path.
    
    Args:
        filename: The name of the file to check/create
        
    Returns:
        A tuple containing (file_path, is_persistent)
    """
    persistent_path = Path("/data") / filename
    local_path = Path(__file__).parent / filename
    
    # Check if persistent storage is available and writable
    use_persistent = False
    if Path("/data").exists() and Path("/data").is_dir():
        try:
            # Test if we can write to the directory
            test_file = Path("/data/write_test.tmp")
            test_file.touch()
            test_file.unlink()  # Remove the test file
            use_persistent = True
        except (PermissionError, OSError):
            print("Persistent storage exists but is not writable, falling back to local storage")
            use_persistent = False
    
    return (persistent_path if use_persistent else local_path, use_persistent)