Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
Fix windows unsupported mode number

Fix windows tests

Use modes that windows can handle

use more open modes for windows
  • Loading branch information
nkaradzhov committed Jan 5, 2025
1 parent a7c5dac commit 5a7a2c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
14 changes: 7 additions & 7 deletions ext/node/polyfills/internal/fs/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { EventEmitter } from "node:events";
import { Buffer } from "node:buffer";
import { promises, read, write } from "node:fs";
import { promises, read, write } from "node:fs";
export type { BigIntStats, Stats } from "ext:deno_node/_fs/_fs_stat.ts";
import {
BinaryOptionsArgument,
Expand All @@ -26,10 +26,10 @@ interface ReadResult {
buffer: Buffer;
}

type Path =string | Buffer | URL;
type Path = string | Buffer | URL;
export class FileHandle extends EventEmitter {
#rid: number;
#path: Path
#path: Path;

constructor(rid: number, path: Path) {
super();
Expand Down Expand Up @@ -149,8 +149,8 @@ export class FileHandle extends EventEmitter {
return fsCall(promises.fstat, this, options);
}
chmod(mode: number): Promise<void> {
assertNotClosed(this, promises.chmod.name)
return promises.chmod(this.#path, mode)
assertNotClosed(this, promises.chmod.name);
return promises.chmod(this.#path, mode);
}
}

Expand All @@ -159,13 +159,13 @@ function assertNotClosed(handle: FileHandle, syscall: string) {
const err = new Error("file closed");
throw Object.assign(err, {
code: "EBADF",
syscall
syscall,
});
}
}

function fsCall(fn, handle, ...args) {
assertNotClosed(handle, fn.name)
assertNotClosed(handle, fn.name);
return fn(handle.fd, ...args);
}

Expand Down
17 changes: 10 additions & 7 deletions tests/unit_node/_fs/_fs_handle_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,16 @@ Deno.test(
},
);

Deno.test("chmod", async function () {
Deno.test("[node/fs filehandle.chmod] Change the permissions of the file", async function () {
const fileHandle = await fs.open(testData);
await fileHandle.chmod(0o666)
const info1 = await Deno.stat(testData)
assertEquals(info1.mode?.toString(8), `100666`)
await fileHandle.chmod(0o555)
const info2 = await Deno.stat(testData)
assertEquals(info2.mode?.toString(8), `100555`)

const readOnly = 0o444;
await fileHandle.chmod(readOnly.toString(8));
assertEquals(Deno.statSync(testData).mode! & 0o777, readOnly);

const readWrite = 0o666;
await fileHandle.chmod(readWrite.toString(8));
assertEquals(Deno.statSync(testData).mode! & 0o777, readWrite);

await fileHandle.close();
});

0 comments on commit 5a7a2c9

Please sign in to comment.