Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/stdlib/pyscript.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions core/src/stdlib/pyscript/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ async def mount(path, mode="readwrite", root="", id="pyscript"):
mounted[path] = await interpreter.mountNativeFS(path, handler)


async def revoke(path, id="pyscript"):
from _pyscript import fs, interpreter
from pyscript.magic_js import (
RUNNING_IN_WORKER,
sync,
)

uid = f"{path}@{id}"

if RUNNING_IN_WORKER:
had = sync.deleteFSHandler(uid)
else:
had = await fs.idb.has(uid)
if had:
had = await fs.idb.delete(uid)

if had:
interpreter._module.FS.unmount(path)

return had


async def sync(path):
await mounted[path].syncfs()

Expand Down
13 changes: 12 additions & 1 deletion core/src/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
* Ask a user action via dialog and returns the directory handler once granted.
* @param {string} uid
* @param {{id?:string, mode?:"read"|"readwrite", hint?:"desktop"|"documents"|"downloads"|"music"|"pictures"|"videos"}} options
* @returns {boolean}
* @returns {Promise<boolean>}
*/
async storeFSHandler(uid, options = {}) {
if (await idb.has(uid)) return true;
Expand All @@ -28,4 +28,15 @@ export default {
() => false,
);
},

/**
* Explicitly remove the unique identifier for the FS handler.
* @param {string} uid
* @returns {Promise<boolean>}
*/
async deleteFSHandler(uid) {
const had = await idb.has(uid);
if (had) await idb.delete(uid);
return had;
},
};
4 changes: 3 additions & 1 deletion core/tests/manual/fs/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

await fs.sync("/persistent")

# await fs.revoke("/persistent")

elif not RUNNING_IN_WORKER:
from pyscript import document

Expand All @@ -39,7 +41,7 @@ async def mount(event):
js.alert("unable to grant access")

async def unmount(event):
await fs.unmount("/persistent")
await fs.revoke("/persistent")
button.textContent = "mount"
button.onclick = mount

Expand Down
10 changes: 8 additions & 2 deletions core/types/sync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ declare namespace _default {
* Ask a user action via dialog and returns the directory handler once granted.
* @param {string} uid
* @param {{id?:string, mode?:"read"|"readwrite", hint?:"desktop"|"documents"|"downloads"|"music"|"pictures"|"videos"}} options
* @returns {boolean}
* @returns {Promise<boolean>}
*/
function storeFSHandler(uid: string, options?: {
id?: string;
mode?: "read" | "readwrite";
hint?: "desktop" | "documents" | "downloads" | "music" | "pictures" | "videos";
}): boolean;
}): Promise<boolean>;
/**
* Explicitly remove the unique identifier for the FS handler.
* @param {string} uid
* @returns {Promise<boolean>}
*/
function deleteFSHandler(uid: string): Promise<boolean>;
}
export default _default;
Loading