mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
fix(ext/node): add chown method to FileHandle class (#27638)
This commit is contained in:
parent
afc23fb2e0
commit
b22a50cb0c
2 changed files with 33 additions and 1 deletions
|
@ -165,6 +165,11 @@ export class FileHandle extends EventEmitter {
|
||||||
assertNotClosed(this, promises.utimes.name);
|
assertNotClosed(this, promises.utimes.name);
|
||||||
return promises.utimes(this.#path, atime, mtime);
|
return promises.utimes(this.#path, atime, mtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chown(uid: number, gid: number): Promise<void> {
|
||||||
|
assertNotClosed(this, promises.chown.name);
|
||||||
|
return promises.chown(this.#path, uid, gid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertNotClosed(handle: FileHandle, syscall: string) {
|
function assertNotClosed(handle: FileHandle, syscall: string) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import * as path from "@std/path";
|
import * as path from "@std/path";
|
||||||
import { Buffer } from "node:buffer";
|
import { Buffer } from "node:buffer";
|
||||||
import * as fs from "node:fs/promises";
|
import * as fs from "node:fs/promises";
|
||||||
import { assert, assertEquals } from "@std/assert";
|
import { assert, assertEquals, assertRejects } from "@std/assert";
|
||||||
|
|
||||||
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
|
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
|
||||||
const testData = path.resolve(moduleDir, "testdata", "hello.txt");
|
const testData = path.resolve(moduleDir, "testdata", "hello.txt");
|
||||||
|
@ -273,3 +273,30 @@ Deno.test({
|
||||||
await fileHandle.close();
|
await fileHandle.close();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[node/fs filehandle.chown] Change owner of the file",
|
||||||
|
ignore: Deno.build.os === "windows",
|
||||||
|
async fn() {
|
||||||
|
const fileHandle = await fs.open(testData);
|
||||||
|
|
||||||
|
const nobodyUid = 65534;
|
||||||
|
const nobodyGid = 65534;
|
||||||
|
|
||||||
|
await assertRejects(
|
||||||
|
async () => await fileHandle.chown(nobodyUid, nobodyGid),
|
||||||
|
Deno.errors.PermissionDenied,
|
||||||
|
"Operation not permitted",
|
||||||
|
);
|
||||||
|
|
||||||
|
const realUid = Deno.uid() || 1000;
|
||||||
|
const realGid = Deno.gid() || 1000;
|
||||||
|
|
||||||
|
await fileHandle.chown(realUid, realGid);
|
||||||
|
|
||||||
|
assertEquals(Deno.statSync(testData).uid, realUid);
|
||||||
|
assertEquals(Deno.statSync(testData).gid, realGid);
|
||||||
|
|
||||||
|
await fileHandle.close();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue