Path.unlink

Path.unlink(...)

Description

Documentation for Path.unlink.

Python Python Pathlib Official Docs

Real-World Examples

Practical code examples showing how Path.unlink is used in real projects.

"""Log out from GitHub."""
    try:
        settings_dir = get_app_data_path() / "settings"
        token_path = settings_dir / "github_token.json"
        if token_path.exists():
            token_path.unlink()
        return {"success": True, "message": "Successfully logged out"}
    except Exception as e:
        return {"success": False, "message": str(e)}

@app.get("/serve-file")
async def serve_file(path: str, currentDir: str = None):
    """Serve any file (binary or text) for display in the editor."""
    try:
        # Handle relative paths and ensure they're safe
        paths_to_try = []

        # If path is absolute, use it directly
        if os.path.isabs(path):
            paths_to_try.append(path)
        else:
            # Try relative to current directory first if provided
            if currentDir:
                paths_to_try.append(os.path.join(currentDir, path))
# Read edited content
        with open(path, "r", encoding="utf-8") as f:
            return f.read()
    finally:
        try:
            os.unlink(path)
        except Exception:
            pass