Revoke filesystem access permission and unmount for a given `path` and `id` combination. This removes the stored permission for accessing the user's local filesystem at the specified path and ID. Unlike `unmount()`, which only removes the mount point, `revoke()` also clears the
(path, id="pyscript")
| 215 | |
| 216 | |
| 217 | async def revoke(path, id="pyscript"): |
| 218 | """ |
| 219 | Revoke filesystem access permission and unmount for a given |
| 220 | `path` and `id` combination. |
| 221 | |
| 222 | This removes the stored permission for accessing the user's local |
| 223 | filesystem at the specified path and ID. Unlike `unmount()`, which only |
| 224 | removes the mount point, `revoke()` also clears the permission so the |
| 225 | user will be prompted again on next mount. |
| 226 | |
| 227 | ```python |
| 228 | from pyscript import fs |
| 229 | |
| 230 | |
| 231 | await fs.mount("/local", id="my-app") |
| 232 | # ... work with files ... |
| 233 | |
| 234 | # Revoke permission (user will be prompted again next time). |
| 235 | revoked = await fs.revoke("/local", id="my-app") |
| 236 | |
| 237 | if revoked: |
| 238 | print("Permission revoked successfully") |
| 239 | ``` |
| 240 | |
| 241 | After revoking, the user will need to grant permission again and |
| 242 | select a directory when `mount()` is called next time. |
| 243 | """ |
| 244 | mount_key = f"{path}@{id}" |
| 245 | |
| 246 | if RUNNING_IN_WORKER: |
| 247 | handler_exists = sync_with_worker.deleteFSHandler(mount_key) |
| 248 | else: |
| 249 | handler_exists = await _fs.idb.has(mount_key) |
| 250 | if handler_exists: |
| 251 | handler_exists = await _fs.idb.delete(mount_key) |
| 252 | |
| 253 | if handler_exists: |
| 254 | interpreter._module.FS.unmount(path) |
| 255 | if path in mounted: |
| 256 | del mounted[path] |
| 257 | |
| 258 | return handler_exists |