Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated APIs warnings #259

Merged
merged 5 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ jobs:
run: /home/runner/.deno/bin/deno test --allow-read --allow-write
- name: Run tests (unstable)
run: /home/runner/.deno/bin/deno test --unstable --allow-read --allow-write
- name: Run tests (DENO_FUTURE)
run: DENO_FUTURE=1 /home/runner/.deno/bin/deno test --allow-read --allow-write
- name: Run tests (DENO_FUTURE and unstable)
run: DENO_FUTURE=1 /home/runner/.deno/bin/deno test --unstable --allow-read --allow-write
- name: Run benchmarks
run: /home/runner/.deno/bin/deno run bench.ts
50 changes: 39 additions & 11 deletions build/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ import { getStr } from "../src/wasm.ts";

const isWindows = Deno.build.os === "windows";

const OPEN_FILES = new Map();

function nextRid() {
const rid = (nextRid?.LAST_RID ?? 0) + 1;
nextRid.LAST_RID = rid;
return rid;
}

function getOpenFile(rid) {
if (!OPEN_FILES.has(rid)) {
throw new Error(`Resource ID ${rid} does not exist.`);
}
return OPEN_FILES.get(rid);
}

// Closure to return an environment that links
// the current wasm context
export default function env(inst) {
Expand All @@ -26,12 +41,16 @@ export default function env(inst) {

const write = !!(flags & 0x00000002);
const create = !!(flags & 0x00000004);
const rid = Deno.openSync(path, { read: true, write, create }).rid;
const file = Deno.openSync(path, { read: true, write, create });
const rid = nextRid();
OPEN_FILES.set(rid, file);
return rid;
},
// Close a file
js_close: (rid) => {
Deno.close(rid);
const file = getOpenFile(rid);
file.close();
OPEN_FILES.delete(rid);
},
// Delete file at path
js_delete: (path_ptr) => {
Expand All @@ -45,8 +64,9 @@ export default function env(inst) {
buffer_ptr,
amount,
);
Deno.seekSync(rid, offset, Deno.SeekMode.Start);
return Deno.readSync(rid, buffer);
const file = getOpenFile(rid);
file.seekSync(offset, Deno.SeekMode.Start);
return file.readSync(buffer);
},
// Write to a file from a buffer in the module
js_write: (rid, buffer_ptr, offset, amount) => {
Expand All @@ -55,30 +75,38 @@ export default function env(inst) {
buffer_ptr,
amount,
);
Deno.seekSync(rid, offset, Deno.SeekMode.Start);
return Deno.writeSync(rid, buffer);
const file = getOpenFile(rid);
file.seekSync(offset, Deno.SeekMode.Start);
return file.writeSync(buffer);
},
// Truncate the given file
js_truncate: (rid, size) => {
Deno.ftruncateSync(rid, size);
const file = getOpenFile(rid);
file.truncateSync(size);
},
// Sync file data to disk
js_sync: (rid) => {
Deno.fdatasyncSync(rid);
const file = getOpenFile(rid);
file.syncDataSync();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dyedgreen I don't know of a good way to make this method support Deno versions before v1.44.

  • We could make it a no-op like the lock/unlock method. Is that acceptable or would that break things?
  • Or we could bump the minimum supported Deno version to v1.44 after this lands.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dyedgreen Let me know when you get a chance to look at this. I'm thinking we may need to bump the minimum supported Deno version to get access to the new file flushing APIs. What are your thoughts?

},
// Retrieve the size of the given file
js_size: (rid) => {
return Deno.fstatSync(rid).size;
const file = getOpenFile(rid);
return file.statSync().size;
},
// Acquire a SHARED or EXCLUSIVE file lock
js_lock: (rid, exclusive) => {
// this is unstable and has issues on Windows ...
if (Deno.flockSync && !isWindows) Deno.flockSync(rid, exclusive !== 0);
if (Deno.flockSync && !isWindows) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dyedgreen What do you think is the best way to detect the availability of FsFile.lockSync?

  • FsFile.lockSync is available in v1.44.0, but Deno.flockSync is still undefined without --unstable or --unstable-fs. So we can't check Deno.flockSync.
  • FsFile.lockSync exists in versions before v1.44.0, but calling it terminates deno, even from inside of a try/catch block. So we can't check the existence of FsFile.lockSync.
  • Deno.version.deno >= "1.44.0" is the only condition I could get to work. Should we go with that?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I feel like we’ll just need to do a version check here 😕

getOpenFile(rid).lockSync(exclusive !== 0);
}
},
// Release a file lock
js_unlock: (rid) => {
// this is unstable and has issues on Windows ...
if (Deno.funlockSync && !isWindows) Deno.funlockSync(rid);
if (Deno.funlockSync && !isWindows) {
getOpenFile(rid).unlockSync();
}
},
// Return current time in ms since UNIX epoch
js_time: () => {
Expand Down
Loading