Skip to content

Commit

Permalink
Fix deprecated APIs warnings (#259)
Browse files Browse the repository at this point in the history
* Fix deprecated APIs warnings
* Use `Deno.FsFile.syncDataSync` (stabilized in Deno v1.44)
* Remove flockSync/funlockSync check

We now require at least Deno v1.44 for stable syncDataSync.
lockSync/unlockSync were also stabilized in Deno v1.44 so there is no
reason to check for their availability anymore.

* Document minimum supported Deno version
  • Loading branch information
canac authored Sep 7, 2024
1 parent 07befa6 commit 81e5599
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ encounter. Note that the `master` branch might contain new or breaking features.
The versioning guarantee applies only to
[tagged releases](https://github.com/dyedgreen/deno-sqlite/releases).

This module relies on filesystem APIs stabilized in Deno v1.44. To use it with
earlier Deno versions, you must pass the `--unstable-fs` flag when running your
application.

## Documentation

Documentation is available [Deno Docs](https://deno.land/x/sqlite). There is
Expand Down
50 changes: 36 additions & 14 deletions build/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { getStr } from "../src/wasm.ts";

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

const OPEN_FILES = [];

function getOpenFile(rid) {
const file = OPEN_FILES[rid];
if (!file) {
throw new Error(`Resource ID ${rid} does not exist.`);
}
return file;
}

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

const write = !!(flags & 0x00000002);
const create = !!(flags & 0x00000004);
const rid = Deno.openSync(path, { read: true, write, create }).rid;
return rid;
const file = Deno.openSync(path, { read: true, write, create });
OPEN_FILES.push(file);
return OPEN_FILES.length - 1;
},
// Close a file
js_close: (rid) => {
Deno.close(rid);
const file = getOpenFile(rid);
file.close();
OPEN_FILES[rid] = null;
},
// Delete file at path
js_delete: (path_ptr) => {
Expand All @@ -45,8 +58,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 +69,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();
},
// 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);
// this has issues on Windows ...
if (!isWindows) {
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);
// this has issues on Windows ...
if (!isWindows) {
getOpenFile(rid).unlockSync();
}
},
// Return current time in ms since UNIX epoch
js_time: () => {
Expand Down

0 comments on commit 81e5599

Please sign in to comment.