Skip to content

Commit 53ed21e

Browse files
committed
Readonly now throws EROFS on write and writeSync
1 parent d4e71cf commit 53ed21e

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

src/mixins/readonly.ts

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import { Errno, ErrnoError } from '../error.js';
2-
import type { File } from '../file.js';
32
import type { FileSystem, FileSystemMetadata } from '../filesystem.js';
4-
import type { Stats } from '../stats.js';
3+
import type { StatsLike } from '../stats.js';
54
import type { Mixin } from './shared.js';
65

76
/**
87
* @internal
98
*/
109
export interface ReadonlyMixin {
1110
metadata(): FileSystemMetadata;
12-
rename(oldPath: string, newPath: string): Promise<void>;
13-
renameSync(oldPath: string, newPath: string): void;
14-
createFile(path: string, flag: string, mode: number): Promise<File>;
15-
createFileSync(path: string, flag: string, mode: number): File;
16-
unlink(path: string): Promise<void>;
17-
unlinkSync(path: string): void;
18-
rmdir(path: string): Promise<void>;
19-
rmdirSync(path: string): void;
20-
mkdir(path: string, mode: number): Promise<void>;
21-
mkdirSync(path: string, mode: number): void;
22-
link(srcpath: string, dstpath: string): Promise<void>;
23-
linkSync(srcpath: string, dstpath: string): void;
24-
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
25-
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
11+
rename(oldPath: string, newPath: string): Promise<never>;
12+
renameSync(oldPath: string, newPath: string): never;
13+
createFile(path: string, flag: string, mode: number): Promise<never>;
14+
createFileSync(path: string, flag: string, mode: number): never;
15+
unlink(path: string): Promise<never>;
16+
unlinkSync(path: string): never;
17+
rmdir(path: string): Promise<never>;
18+
rmdirSync(path: string): never;
19+
mkdir(path: string, mode: number): Promise<never>;
20+
mkdirSync(path: string, mode: number): never;
21+
link(srcpath: string, dstpath: string): Promise<never>;
22+
linkSync(srcpath: string, dstpath: string): never;
23+
sync(path: string, data: Uint8Array, stats: Readonly<StatsLike<number>>): Promise<never>;
24+
syncSync(path: string, data: Uint8Array, stats: Readonly<StatsLike<number>>): never;
25+
write(path: string, buffer: Uint8Array, offset: number): Promise<never>;
26+
writeSync(path: string, buffer: Uint8Array, offset: number): Promise<never>;
2627
}
2728

2829
/**
@@ -35,59 +36,67 @@ export function Readonly<T extends typeof FileSystem>(FS: T): Mixin<T, ReadonlyM
3536
return { ...super.metadata(), readonly: true };
3637
}
3738

38-
public async rename(): Promise<void> {
39+
public async rename(): Promise<never> {
3940
throw new ErrnoError(Errno.EROFS);
4041
}
4142

42-
public renameSync(): void {
43+
public renameSync(): never {
4344
throw new ErrnoError(Errno.EROFS);
4445
}
4546

46-
public async createFile(): Promise<File> {
47+
public async createFile(): Promise<never> {
4748
throw new ErrnoError(Errno.EROFS);
4849
}
4950

50-
public createFileSync(): File {
51+
public createFileSync(): never {
5152
throw new ErrnoError(Errno.EROFS);
5253
}
5354

54-
public async unlink(): Promise<void> {
55+
public async unlink(): Promise<never> {
5556
throw new ErrnoError(Errno.EROFS);
5657
}
5758

58-
public unlinkSync(): void {
59+
public unlinkSync(): never {
5960
throw new ErrnoError(Errno.EROFS);
6061
}
6162

62-
public async rmdir(): Promise<void> {
63+
public async rmdir(): Promise<never> {
6364
throw new ErrnoError(Errno.EROFS);
6465
}
6566

66-
public rmdirSync(): void {
67+
public rmdirSync(): never {
6768
throw new ErrnoError(Errno.EROFS);
6869
}
6970

70-
public async mkdir(): Promise<void> {
71+
public async mkdir(): Promise<never> {
7172
throw new ErrnoError(Errno.EROFS);
7273
}
7374

74-
public mkdirSync(): void {
75+
public mkdirSync(): never {
7576
throw new ErrnoError(Errno.EROFS);
7677
}
7778

78-
public async link(): Promise<void> {
79+
public async link(): Promise<never> {
7980
throw new ErrnoError(Errno.EROFS);
8081
}
8182

82-
public linkSync(): void {
83+
public linkSync(): never {
8384
throw new ErrnoError(Errno.EROFS);
8485
}
8586

86-
public async sync(): Promise<void> {
87+
public async sync(): Promise<never> {
8788
throw new ErrnoError(Errno.EROFS);
8889
}
8990

90-
public syncSync(): void {
91+
public syncSync(): never {
92+
throw new ErrnoError(Errno.EROFS);
93+
}
94+
95+
public async write(): Promise<never> {
96+
throw new ErrnoError(Errno.EROFS);
97+
}
98+
99+
public writeSync(): never {
91100
throw new ErrnoError(Errno.EROFS);
92101
}
93102
}

0 commit comments

Comments
 (0)