mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 16:19:12 -05:00
Rename name/filename arguments to path (#4227)
There's a lot of variation in doc comments and internal code about whether the first parameter to file system calls is `path` or `name` or `filename`. For consistency, have made it always be `path`.
This commit is contained in:
parent
bb3d9c8280
commit
acf0958e94
10 changed files with 111 additions and 114 deletions
|
@ -27,7 +27,7 @@ let OP_WRITE = -1;
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
||||||
*/
|
*/
|
||||||
export function openSync(filename: string, mode?: OpenOptions): File;
|
export function openSync(path: string, mode?: OpenOptions): File;
|
||||||
|
|
||||||
/** Synchronously open a file and return an instance of the `File` object.
|
/** Synchronously open a file and return an instance of the `File` object.
|
||||||
*
|
*
|
||||||
|
@ -35,11 +35,11 @@ export function openSync(filename: string, mode?: OpenOptions): File;
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
||||||
*/
|
*/
|
||||||
export function openSync(filename: string, mode?: OpenMode): File;
|
export function openSync(path: string, mode?: OpenMode): File;
|
||||||
|
|
||||||
/**@internal*/
|
/**@internal*/
|
||||||
export function openSync(
|
export function openSync(
|
||||||
filename: string,
|
path: string,
|
||||||
modeOrOptions: OpenOptions | OpenMode = "r"
|
modeOrOptions: OpenOptions | OpenMode = "r"
|
||||||
): File {
|
): File {
|
||||||
let mode = null;
|
let mode = null;
|
||||||
|
@ -52,7 +52,7 @@ export function openSync(
|
||||||
options = modeOrOptions;
|
options = modeOrOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rid = sendSyncJson("op_open", { filename, options, mode });
|
const rid = sendSyncJson("op_open", { path, options, mode });
|
||||||
return new File(rid);
|
return new File(rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,10 +62,7 @@ export function openSync(
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
||||||
*/
|
*/
|
||||||
export async function open(
|
export async function open(path: string, options?: OpenOptions): Promise<File>;
|
||||||
filename: string,
|
|
||||||
options?: OpenOptions
|
|
||||||
): Promise<File>;
|
|
||||||
|
|
||||||
/** Open a file and resolves to an instance of `Deno.File`.
|
/** Open a file and resolves to an instance of `Deno.File`.
|
||||||
*
|
*
|
||||||
|
@ -73,11 +70,11 @@ export async function open(
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
||||||
*/
|
*/
|
||||||
export async function open(filename: string, mode?: OpenMode): Promise<File>;
|
export async function open(path: string, mode?: OpenMode): Promise<File>;
|
||||||
|
|
||||||
/**@internal*/
|
/**@internal*/
|
||||||
export async function open(
|
export async function open(
|
||||||
filename: string,
|
path: string,
|
||||||
modeOrOptions: OpenOptions | OpenMode = "r"
|
modeOrOptions: OpenOptions | OpenMode = "r"
|
||||||
): Promise<File> {
|
): Promise<File> {
|
||||||
let mode = null;
|
let mode = null;
|
||||||
|
@ -91,7 +88,7 @@ export async function open(
|
||||||
}
|
}
|
||||||
|
|
||||||
const rid = await sendAsyncJson("op_open", {
|
const rid = await sendAsyncJson("op_open", {
|
||||||
filename,
|
path,
|
||||||
options,
|
options,
|
||||||
mode
|
mode
|
||||||
});
|
});
|
||||||
|
@ -105,8 +102,8 @@ export async function open(
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions.
|
* Requires `allow-read` and `allow-write` permissions.
|
||||||
*/
|
*/
|
||||||
export function createSync(filename: string): File {
|
export function createSync(path: string): File {
|
||||||
return openSync(filename, "w+");
|
return openSync(path, "w+");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a file if none exists or truncates an existing file and resolves to
|
/** Creates a file if none exists or truncates an existing file and resolves to
|
||||||
|
@ -116,8 +113,8 @@ export function createSync(filename: string): File {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions.
|
* Requires `allow-read` and `allow-write` permissions.
|
||||||
*/
|
*/
|
||||||
export function create(filename: string): Promise<File> {
|
export function create(path: string): Promise<File> {
|
||||||
return open(filename, "w+");
|
return open(path, "w+");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Synchronously read from a file ID into an array buffer.
|
/** Synchronously read from a file ID into an array buffer.
|
||||||
|
|
56
cli/js/lib.deno.ns.d.ts
vendored
56
cli/js/lib.deno.ns.d.ts
vendored
|
@ -435,7 +435,7 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
||||||
*/
|
*/
|
||||||
export function openSync(filename: string, options?: OpenOptions): File;
|
export function openSync(path: string, options?: OpenOptions): File;
|
||||||
|
|
||||||
/** Synchronously open a file and return an instance of the `File` object.
|
/** Synchronously open a file and return an instance of the `File` object.
|
||||||
*
|
*
|
||||||
|
@ -443,7 +443,7 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
||||||
*/
|
*/
|
||||||
export function openSync(filename: string, mode?: OpenMode): File;
|
export function openSync(path: string, mode?: OpenMode): File;
|
||||||
|
|
||||||
/** Open a file and resolve to an instance of the `File` object.
|
/** Open a file and resolve to an instance of the `File` object.
|
||||||
*
|
*
|
||||||
|
@ -451,7 +451,7 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
||||||
*/
|
*/
|
||||||
export function open(filename: string, options?: OpenOptions): Promise<File>;
|
export function open(path: string, options?: OpenOptions): Promise<File>;
|
||||||
|
|
||||||
/** Open a file and resolves to an instance of `Deno.File`.
|
/** Open a file and resolves to an instance of `Deno.File`.
|
||||||
*
|
*
|
||||||
|
@ -459,7 +459,7 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
* Requires `allow-read` and `allow-write` permissions depending on mode.
|
||||||
*/
|
*/
|
||||||
export function open(filename: string, mode?: OpenMode): Promise<File>;
|
export function open(path: string, mode?: OpenMode): Promise<File>;
|
||||||
|
|
||||||
/** Creates a file if none exists or truncates an existing file and returns
|
/** Creates a file if none exists or truncates an existing file and returns
|
||||||
* an instance of `Deno.File`.
|
* an instance of `Deno.File`.
|
||||||
|
@ -468,7 +468,7 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions.
|
* Requires `allow-read` and `allow-write` permissions.
|
||||||
*/
|
*/
|
||||||
export function createSync(filename: string): File;
|
export function createSync(path: string): File;
|
||||||
|
|
||||||
/** Creates a file if none exists or truncates an existing file and resolves to
|
/** Creates a file if none exists or truncates an existing file and resolves to
|
||||||
* an instance of `Deno.File`.
|
* an instance of `Deno.File`.
|
||||||
|
@ -477,7 +477,7 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions.
|
* Requires `allow-read` and `allow-write` permissions.
|
||||||
*/
|
*/
|
||||||
export function create(filename: string): Promise<File>;
|
export function create(path: string): Promise<File>;
|
||||||
|
|
||||||
/** Synchronously read from a file ID into an array buffer.
|
/** Synchronously read from a file ID into an array buffer.
|
||||||
*
|
*
|
||||||
|
@ -893,14 +893,14 @@ declare namespace Deno {
|
||||||
/** **UNSTABLE**: needs investigation into high precision time.
|
/** **UNSTABLE**: needs investigation into high precision time.
|
||||||
*
|
*
|
||||||
* Synchronously changes the access and modification times of a file system
|
* Synchronously changes the access and modification times of a file system
|
||||||
* object referenced by `filename`. Given times are either in seconds (UNIX
|
* object referenced by `path`. Given times are either in seconds (UNIX epoch
|
||||||
* epoch time) or as `Date` objects.
|
* time) or as `Date` objects.
|
||||||
*
|
*
|
||||||
* Deno.utimeSync("myfile.txt", 1556495550, new Date());
|
* Deno.utimeSync("myfile.txt", 1556495550, new Date());
|
||||||
*
|
*
|
||||||
* Requires `allow-write` permission. */
|
* Requires `allow-write` permission. */
|
||||||
export function utimeSync(
|
export function utimeSync(
|
||||||
filename: string,
|
path: string,
|
||||||
atime: number | Date,
|
atime: number | Date,
|
||||||
mtime: number | Date
|
mtime: number | Date
|
||||||
): void;
|
): void;
|
||||||
|
@ -908,14 +908,14 @@ declare namespace Deno {
|
||||||
/** **UNSTABLE**: needs investigation into high precision time.
|
/** **UNSTABLE**: needs investigation into high precision time.
|
||||||
*
|
*
|
||||||
* Changes the access and modification times of a file system object
|
* Changes the access and modification times of a file system object
|
||||||
* referenced by `filename`. Given times are either in seconds (UNIX epoch
|
* referenced by `path`. Given times are either in seconds (UNIX epoch time)
|
||||||
* time) or as `Date` objects.
|
* or as `Date` objects.
|
||||||
*
|
*
|
||||||
* await Deno.utime("myfile.txt", 1556495550, new Date());
|
* await Deno.utime("myfile.txt", 1556495550, new Date());
|
||||||
*
|
*
|
||||||
* Requires `allow-write` permission. */
|
* Requires `allow-write` permission. */
|
||||||
export function utime(
|
export function utime(
|
||||||
filename: string,
|
path: string,
|
||||||
atime: number | Date,
|
atime: number | Date,
|
||||||
mtime: number | Date
|
mtime: number | Date
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
@ -976,7 +976,7 @@ declare namespace Deno {
|
||||||
* console.log(decoder.decode(data));
|
* console.log(decoder.decode(data));
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function readFileSync(filename: string): Uint8Array;
|
export function readFileSync(path: string): Uint8Array;
|
||||||
|
|
||||||
/** Reads and resolves to the entire contents of a file.
|
/** Reads and resolves to the entire contents of a file.
|
||||||
*
|
*
|
||||||
|
@ -985,7 +985,7 @@ declare namespace Deno {
|
||||||
* console.log(decoder.decode(data));
|
* console.log(decoder.decode(data));
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function readFile(filename: string): Promise<Uint8Array>;
|
export function readFile(path: string): Promise<Uint8Array>;
|
||||||
|
|
||||||
// @url js/file_info.d.ts
|
// @url js/file_info.d.ts
|
||||||
|
|
||||||
|
@ -1127,52 +1127,52 @@ declare namespace Deno {
|
||||||
* const targetPath = Deno.readlinkSync("symlink/path");
|
* const targetPath = Deno.readlinkSync("symlink/path");
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function readlinkSync(name: string): string;
|
export function readlinkSync(path: string): string;
|
||||||
|
|
||||||
/** Resolves to the destination of the named symbolic link.
|
/** Resolves to the destination of the named symbolic link.
|
||||||
*
|
*
|
||||||
* const targetPath = await Deno.readlink("symlink/path");
|
* const targetPath = await Deno.readlink("symlink/path");
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function readlink(name: string): Promise<string>;
|
export function readlink(path: string): Promise<string>;
|
||||||
|
|
||||||
// @url js/stat.d.ts
|
// @url js/stat.d.ts
|
||||||
|
|
||||||
/** Resolves to a `Deno.FileInfo` for the specified path. If path is a
|
/** Resolves to a `Deno.FileInfo` for the specified `path`. If `path` is a
|
||||||
* symlink, information for the symlink will be returned.
|
* symlink, information for the symlink will be returned.
|
||||||
*
|
*
|
||||||
* const fileInfo = await Deno.lstat("hello.txt");
|
* const fileInfo = await Deno.lstat("hello.txt");
|
||||||
* assert(fileInfo.isFile());
|
* assert(fileInfo.isFile());
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function lstat(filename: string): Promise<FileInfo>;
|
export function lstat(path: string): Promise<FileInfo>;
|
||||||
|
|
||||||
/** Synchronously returns a `Deno.FileInfo` for the specified path. If
|
/** Synchronously returns a `Deno.FileInfo` for the specified `path`. If
|
||||||
* path is a symlink, information for the symlink will be returned.
|
* `path` is a symlink, information for the symlink will be returned.
|
||||||
*
|
*
|
||||||
* const fileInfo = Deno.lstatSync("hello.txt");
|
* const fileInfo = Deno.lstatSync("hello.txt");
|
||||||
* assert(fileInfo.isFile());
|
* assert(fileInfo.isFile());
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function lstatSync(filename: string): FileInfo;
|
export function lstatSync(path: string): FileInfo;
|
||||||
|
|
||||||
/** Resolves to a `Deno.FileInfo` for the specified path. Will always follow
|
/** Resolves to a `Deno.FileInfo` for the specified `path`. Will always
|
||||||
* symlinks.
|
* follow symlinks.
|
||||||
*
|
*
|
||||||
* const fileInfo = await Deno.stat("hello.txt");
|
* const fileInfo = await Deno.stat("hello.txt");
|
||||||
* assert(fileInfo.isFile());
|
* assert(fileInfo.isFile());
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function stat(filename: string): Promise<FileInfo>;
|
export function stat(path: string): Promise<FileInfo>;
|
||||||
|
|
||||||
/** Synchronously returns a `Deno.FileInfo` for the specified path. Will
|
/** Synchronously returns a `Deno.FileInfo` for the specified `path`. Will
|
||||||
* always follow symlinks.
|
* always follow symlinks.
|
||||||
*
|
*
|
||||||
* const fileInfo = Deno.statSync("hello.txt");
|
* const fileInfo = Deno.statSync("hello.txt");
|
||||||
* assert(fileInfo.isFile());
|
* assert(fileInfo.isFile());
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function statSync(filename: string): FileInfo;
|
export function statSync(path: string): FileInfo;
|
||||||
|
|
||||||
// @url js/link.d.ts
|
// @url js/link.d.ts
|
||||||
|
|
||||||
|
@ -1246,7 +1246,7 @@ declare namespace Deno {
|
||||||
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
||||||
*/
|
*/
|
||||||
export function writeFileSync(
|
export function writeFileSync(
|
||||||
filename: string,
|
path: string,
|
||||||
data: Uint8Array,
|
data: Uint8Array,
|
||||||
options?: WriteFileOptions
|
options?: WriteFileOptions
|
||||||
): void;
|
): void;
|
||||||
|
@ -1261,7 +1261,7 @@ declare namespace Deno {
|
||||||
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
||||||
*/
|
*/
|
||||||
export function writeFile(
|
export function writeFile(
|
||||||
filename: string,
|
path: string,
|
||||||
data: Uint8Array,
|
data: Uint8Array,
|
||||||
options?: WriteFileOptions
|
options?: WriteFileOptions
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
|
|
@ -9,8 +9,8 @@ import { readAll, readAllSync } from "./buffer.ts";
|
||||||
* console.log(decoder.decode(data));
|
* console.log(decoder.decode(data));
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function readFileSync(filename: string): Uint8Array {
|
export function readFileSync(path: string): Uint8Array {
|
||||||
const file = openSync(filename);
|
const file = openSync(path);
|
||||||
const contents = readAllSync(file);
|
const contents = readAllSync(file);
|
||||||
file.close();
|
file.close();
|
||||||
return contents;
|
return contents;
|
||||||
|
@ -23,8 +23,8 @@ export function readFileSync(filename: string): Uint8Array {
|
||||||
* console.log(decoder.decode(data));
|
* console.log(decoder.decode(data));
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export async function readFile(filename: string): Promise<Uint8Array> {
|
export async function readFile(path: string): Promise<Uint8Array> {
|
||||||
const file = await open(filename);
|
const file = await open(path);
|
||||||
const contents = await readAll(file);
|
const contents = await readAll(file);
|
||||||
file.close();
|
file.close();
|
||||||
return contents;
|
return contents;
|
||||||
|
|
|
@ -6,8 +6,8 @@ import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||||
* const targetPath = Deno.readlinkSync("symlink/path");
|
* const targetPath = Deno.readlinkSync("symlink/path");
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function readlinkSync(name: string): string {
|
export function readlinkSync(path: string): string {
|
||||||
return sendSync("op_read_link", { name });
|
return sendSync("op_read_link", { path });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolves to the destination of the named symbolic link.
|
/** Resolves to the destination of the named symbolic link.
|
||||||
|
@ -15,6 +15,6 @@ export function readlinkSync(name: string): string {
|
||||||
* const targetPath = await Deno.readlink("symlink/path");
|
* const targetPath = await Deno.readlink("symlink/path");
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export async function readlink(name: string): Promise<string> {
|
export async function readlink(path: string): Promise<string> {
|
||||||
return await sendAsync("op_read_link", { name });
|
return await sendAsync("op_read_link", { path });
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,61 +23,61 @@ export interface StatResponse {
|
||||||
blocks: number;
|
blocks: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolves to a `Deno.FileInfo` for the specified path. If path is a
|
/** Resolves to a `Deno.FileInfo` for the specified `path`. If `path` is a
|
||||||
* symlink, information for the symlink will be returned.
|
* symlink, information for the symlink will be returned.
|
||||||
*
|
*
|
||||||
* const fileInfo = await Deno.lstat("hello.txt");
|
* const fileInfo = await Deno.lstat("hello.txt");
|
||||||
* assert(fileInfo.isFile());
|
* assert(fileInfo.isFile());
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export async function lstat(filename: string): Promise<FileInfo> {
|
export async function lstat(path: string): Promise<FileInfo> {
|
||||||
const res = (await sendAsync("op_stat", {
|
const res = (await sendAsync("op_stat", {
|
||||||
filename,
|
path,
|
||||||
lstat: true
|
lstat: true
|
||||||
})) as StatResponse;
|
})) as StatResponse;
|
||||||
return new FileInfoImpl(res);
|
return new FileInfoImpl(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Synchronously returns a `Deno.FileInfo` for the specified path. If
|
/** Synchronously returns a `Deno.FileInfo` for the specified `path`. If
|
||||||
* path is a symlink, information for the symlink will be returned.
|
* `path` is a symlink, information for the symlink will be returned.
|
||||||
*
|
*
|
||||||
* const fileInfo = Deno.lstatSync("hello.txt");
|
* const fileInfo = Deno.lstatSync("hello.txt");
|
||||||
* assert(fileInfo.isFile());
|
* assert(fileInfo.isFile());
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function lstatSync(filename: string): FileInfo {
|
export function lstatSync(path: string): FileInfo {
|
||||||
const res = sendSync("op_stat", {
|
const res = sendSync("op_stat", {
|
||||||
filename,
|
path,
|
||||||
lstat: true
|
lstat: true
|
||||||
}) as StatResponse;
|
}) as StatResponse;
|
||||||
return new FileInfoImpl(res);
|
return new FileInfoImpl(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolves to a `Deno.FileInfo` for the specified path. Will always follow
|
/** Resolves to a `Deno.FileInfo` for the specified `path`. Will always
|
||||||
* symlinks.
|
* follow symlinks.
|
||||||
*
|
*
|
||||||
* const fileInfo = await Deno.stat("hello.txt");
|
* const fileInfo = await Deno.stat("hello.txt");
|
||||||
* assert(fileInfo.isFile());
|
* assert(fileInfo.isFile());
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export async function stat(filename: string): Promise<FileInfo> {
|
export async function stat(path: string): Promise<FileInfo> {
|
||||||
const res = (await sendAsync("op_stat", {
|
const res = (await sendAsync("op_stat", {
|
||||||
filename,
|
path,
|
||||||
lstat: false
|
lstat: false
|
||||||
})) as StatResponse;
|
})) as StatResponse;
|
||||||
return new FileInfoImpl(res);
|
return new FileInfoImpl(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Synchronously returns a `Deno.FileInfo` for the specified path. Will
|
/** Synchronously returns a `Deno.FileInfo` for the specified `path`. Will
|
||||||
* always follow symlinks.
|
* always follow symlinks.
|
||||||
*
|
*
|
||||||
* const fileInfo = Deno.statSync("hello.txt");
|
* const fileInfo = Deno.statSync("hello.txt");
|
||||||
* assert(fileInfo.isFile());
|
* assert(fileInfo.isFile());
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* Requires `allow-read` permission. */
|
||||||
export function statSync(filename: string): FileInfo {
|
export function statSync(path: string): FileInfo {
|
||||||
const res = sendSync("op_stat", {
|
const res = sendSync("op_stat", {
|
||||||
filename,
|
path,
|
||||||
lstat: false
|
lstat: false
|
||||||
}) as StatResponse;
|
}) as StatResponse;
|
||||||
return new FileInfoImpl(res);
|
return new FileInfoImpl(res);
|
||||||
|
|
|
@ -19,8 +19,8 @@ function coerceLen(len?: number): number {
|
||||||
* Deno.truncateSync("hello.txt", 10);
|
* Deno.truncateSync("hello.txt", 10);
|
||||||
*
|
*
|
||||||
* Requires `allow-write` permission. */
|
* Requires `allow-write` permission. */
|
||||||
export function truncateSync(name: string, len?: number): void {
|
export function truncateSync(path: string, len?: number): void {
|
||||||
sendSync("op_truncate", { name, len: coerceLen(len) });
|
sendSync("op_truncate", { path, len: coerceLen(len) });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Truncates or extends the specified file, to reach the specified `len`.
|
/** Truncates or extends the specified file, to reach the specified `len`.
|
||||||
|
@ -28,6 +28,6 @@ export function truncateSync(name: string, len?: number): void {
|
||||||
* await Deno.truncate("hello.txt", 10);
|
* await Deno.truncate("hello.txt", 10);
|
||||||
*
|
*
|
||||||
* Requires `allow-write` permission. */
|
* Requires `allow-write` permission. */
|
||||||
export async function truncate(name: string, len?: number): Promise<void> {
|
export async function truncate(path: string, len?: number): Promise<void> {
|
||||||
await sendAsync("op_truncate", { name, len: coerceLen(len) });
|
await sendAsync("op_truncate", { path, len: coerceLen(len) });
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,19 +8,19 @@ function toSecondsFromEpoch(v: number | Date): number {
|
||||||
/** **UNSTABLE**: needs investigation into high precision time.
|
/** **UNSTABLE**: needs investigation into high precision time.
|
||||||
*
|
*
|
||||||
* Synchronously changes the access and modification times of a file system
|
* Synchronously changes the access and modification times of a file system
|
||||||
* object referenced by `filename`. Given times are either in seconds
|
* object referenced by `path`. Given times are either in seconds (UNIX epoch
|
||||||
* (Unix epoch time) or as `Date` objects.
|
* time) or as `Date` objects.
|
||||||
*
|
*
|
||||||
* Deno.utimeSync("myfile.txt", 1556495550, new Date());
|
* Deno.utimeSync("myfile.txt", 1556495550, new Date());
|
||||||
*
|
*
|
||||||
* Requires `allow-write` permission. */
|
* Requires `allow-write` permission. */
|
||||||
export function utimeSync(
|
export function utimeSync(
|
||||||
filename: string,
|
path: string,
|
||||||
atime: number | Date,
|
atime: number | Date,
|
||||||
mtime: number | Date
|
mtime: number | Date
|
||||||
): void {
|
): void {
|
||||||
sendSync("op_utime", {
|
sendSync("op_utime", {
|
||||||
filename,
|
path,
|
||||||
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
|
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
|
||||||
atime: toSecondsFromEpoch(atime),
|
atime: toSecondsFromEpoch(atime),
|
||||||
mtime: toSecondsFromEpoch(mtime)
|
mtime: toSecondsFromEpoch(mtime)
|
||||||
|
@ -30,19 +30,19 @@ export function utimeSync(
|
||||||
/** **UNSTABLE**: needs investigation into high precision time.
|
/** **UNSTABLE**: needs investigation into high precision time.
|
||||||
*
|
*
|
||||||
* Changes the access and modification times of a file system object
|
* Changes the access and modification times of a file system object
|
||||||
* referenced by `filename`. Given times are either in seconds
|
* referenced by `path`. Given times are either in seconds (UNIX epoch time)
|
||||||
* (Unix epoch time) or as `Date` objects.
|
* or as `Date` objects.
|
||||||
*
|
*
|
||||||
* await Deno.utime("myfile.txt", 1556495550, new Date());
|
* await Deno.utime("myfile.txt", 1556495550, new Date());
|
||||||
*
|
*
|
||||||
* Requires `allow-write` permission. */
|
* Requires `allow-write` permission. */
|
||||||
export async function utime(
|
export async function utime(
|
||||||
filename: string,
|
path: string,
|
||||||
atime: number | Date,
|
atime: number | Date,
|
||||||
mtime: number | Date
|
mtime: number | Date
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await sendAsync("op_utime", {
|
await sendAsync("op_utime", {
|
||||||
filename,
|
path,
|
||||||
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
|
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
|
||||||
atime: toSecondsFromEpoch(atime),
|
atime: toSecondsFromEpoch(atime),
|
||||||
mtime: toSecondsFromEpoch(mtime)
|
mtime: toSecondsFromEpoch(mtime)
|
||||||
|
|
|
@ -26,7 +26,7 @@ export interface WriteFileOptions {
|
||||||
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
||||||
*/
|
*/
|
||||||
export function writeFileSync(
|
export function writeFileSync(
|
||||||
filename: string,
|
path: string,
|
||||||
data: Uint8Array,
|
data: Uint8Array,
|
||||||
options: WriteFileOptions = {}
|
options: WriteFileOptions = {}
|
||||||
): void {
|
): void {
|
||||||
|
@ -34,15 +34,15 @@ export function writeFileSync(
|
||||||
const create = !!options.create;
|
const create = !!options.create;
|
||||||
if (!create) {
|
if (!create) {
|
||||||
// verify that file exists
|
// verify that file exists
|
||||||
statSync(filename);
|
statSync(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const openMode = !!options.append ? "a" : "w";
|
const openMode = !!options.append ? "a" : "w";
|
||||||
const file = openSync(filename, openMode);
|
const file = openSync(path, openMode);
|
||||||
|
|
||||||
if (options.perm !== undefined && options.perm !== null) {
|
if (options.perm !== undefined && options.perm !== null) {
|
||||||
chmodSync(filename, options.perm);
|
chmodSync(path, options.perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeAllSync(file, data);
|
writeAllSync(file, data);
|
||||||
|
@ -59,7 +59,7 @@ export function writeFileSync(
|
||||||
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
||||||
*/
|
*/
|
||||||
export async function writeFile(
|
export async function writeFile(
|
||||||
filename: string,
|
path: string,
|
||||||
data: Uint8Array,
|
data: Uint8Array,
|
||||||
options: WriteFileOptions = {}
|
options: WriteFileOptions = {}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
@ -67,15 +67,15 @@ export async function writeFile(
|
||||||
const create = !!options.create;
|
const create = !!options.create;
|
||||||
if (!create) {
|
if (!create) {
|
||||||
// verify that file exists
|
// verify that file exists
|
||||||
await stat(filename);
|
await stat(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const openMode = !!options.append ? "a" : "w";
|
const openMode = !!options.append ? "a" : "w";
|
||||||
const file = await open(filename, openMode);
|
const file = await open(path, openMode);
|
||||||
|
|
||||||
if (options.perm !== undefined && options.perm !== null) {
|
if (options.perm !== undefined && options.perm !== null) {
|
||||||
await chmod(filename, options.perm);
|
await chmod(path, options.perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
await writeAll(file, data);
|
await writeAll(file, data);
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub fn init(i: &mut Isolate, s: &State) {
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct OpenArgs {
|
struct OpenArgs {
|
||||||
promise_id: Option<u64>,
|
promise_id: Option<u64>,
|
||||||
filename: String,
|
path: String,
|
||||||
options: Option<OpenOptions>,
|
options: Option<OpenOptions>,
|
||||||
mode: Option<String>,
|
mode: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -45,17 +45,17 @@ fn op_open(
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<JsonOp, OpError> {
|
) -> Result<JsonOp, OpError> {
|
||||||
let args: OpenArgs = serde_json::from_value(args)?;
|
let args: OpenArgs = serde_json::from_value(args)?;
|
||||||
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
|
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||||
let state_ = state.clone();
|
let state_ = state.clone();
|
||||||
let mut open_options = tokio::fs::OpenOptions::new();
|
let mut open_options = tokio::fs::OpenOptions::new();
|
||||||
|
|
||||||
if let Some(options) = args.options {
|
if let Some(options) = args.options {
|
||||||
if options.read {
|
if options.read {
|
||||||
state.check_read(&filename)?;
|
state.check_read(&path)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.write || options.append {
|
if options.write || options.append {
|
||||||
state.check_write(&filename)?;
|
state.check_write(&path)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
open_options
|
open_options
|
||||||
|
@ -69,14 +69,14 @@ fn op_open(
|
||||||
let mode = mode.as_ref();
|
let mode = mode.as_ref();
|
||||||
match mode {
|
match mode {
|
||||||
"r" => {
|
"r" => {
|
||||||
state.check_read(&filename)?;
|
state.check_read(&path)?;
|
||||||
}
|
}
|
||||||
"w" | "a" | "x" => {
|
"w" | "a" | "x" => {
|
||||||
state.check_write(&filename)?;
|
state.check_write(&path)?;
|
||||||
}
|
}
|
||||||
&_ => {
|
&_ => {
|
||||||
state.check_read(&filename)?;
|
state.check_read(&path)?;
|
||||||
state.check_write(&filename)?;
|
state.check_write(&path)?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ fn op_open(
|
||||||
let is_sync = args.promise_id.is_none();
|
let is_sync = args.promise_id.is_none();
|
||||||
|
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
let fs_file = open_options.open(filename).await?;
|
let fs_file = open_options.open(path).await?;
|
||||||
let mut state = state_.borrow_mut();
|
let mut state = state_.borrow_mut();
|
||||||
let rid = state.resource_table.add(
|
let rid = state.resource_table.add(
|
||||||
"fsFile",
|
"fsFile",
|
||||||
|
|
|
@ -275,7 +275,7 @@ fn get_stat_json(
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct StatArgs {
|
struct StatArgs {
|
||||||
promise_id: Option<u64>,
|
promise_id: Option<u64>,
|
||||||
filename: String,
|
path: String,
|
||||||
lstat: bool,
|
lstat: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,18 +285,18 @@ fn op_stat(
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<JsonOp, OpError> {
|
) -> Result<JsonOp, OpError> {
|
||||||
let args: StatArgs = serde_json::from_value(args)?;
|
let args: StatArgs = serde_json::from_value(args)?;
|
||||||
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
|
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||||
let lstat = args.lstat;
|
let lstat = args.lstat;
|
||||||
|
|
||||||
state.check_read(&filename)?;
|
state.check_read(&path)?;
|
||||||
|
|
||||||
let is_sync = args.promise_id.is_none();
|
let is_sync = args.promise_id.is_none();
|
||||||
blocking_json(is_sync, move || {
|
blocking_json(is_sync, move || {
|
||||||
debug!("op_stat {} {}", filename.display(), lstat);
|
debug!("op_stat {} {}", path.display(), lstat);
|
||||||
let metadata = if lstat {
|
let metadata = if lstat {
|
||||||
fs::symlink_metadata(&filename)?
|
fs::symlink_metadata(&path)?
|
||||||
} else {
|
} else {
|
||||||
fs::metadata(&filename)?
|
fs::metadata(&path)?
|
||||||
};
|
};
|
||||||
get_stat_json(metadata, None)
|
get_stat_json(metadata, None)
|
||||||
})
|
})
|
||||||
|
@ -464,7 +464,7 @@ fn op_symlink(
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct ReadLinkArgs {
|
struct ReadLinkArgs {
|
||||||
promise_id: Option<u64>,
|
promise_id: Option<u64>,
|
||||||
name: String,
|
path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_read_link(
|
fn op_read_link(
|
||||||
|
@ -473,14 +473,14 @@ fn op_read_link(
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<JsonOp, OpError> {
|
) -> Result<JsonOp, OpError> {
|
||||||
let args: ReadLinkArgs = serde_json::from_value(args)?;
|
let args: ReadLinkArgs = serde_json::from_value(args)?;
|
||||||
let name = deno_fs::resolve_from_cwd(Path::new(&args.name))?;
|
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||||
|
|
||||||
state.check_read(&name)?;
|
state.check_read(&path)?;
|
||||||
|
|
||||||
let is_sync = args.promise_id.is_none();
|
let is_sync = args.promise_id.is_none();
|
||||||
blocking_json(is_sync, move || {
|
blocking_json(is_sync, move || {
|
||||||
debug!("op_read_link {}", name.display());
|
debug!("op_read_link {}", path.display());
|
||||||
let path = fs::read_link(&name)?;
|
let path = fs::read_link(&path)?;
|
||||||
let path_str = path.to_str().unwrap();
|
let path_str = path.to_str().unwrap();
|
||||||
|
|
||||||
Ok(json!(path_str))
|
Ok(json!(path_str))
|
||||||
|
@ -491,7 +491,7 @@ fn op_read_link(
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct TruncateArgs {
|
struct TruncateArgs {
|
||||||
promise_id: Option<u64>,
|
promise_id: Option<u64>,
|
||||||
name: String,
|
path: String,
|
||||||
len: u64,
|
len: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,15 +501,15 @@ fn op_truncate(
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<JsonOp, OpError> {
|
) -> Result<JsonOp, OpError> {
|
||||||
let args: TruncateArgs = serde_json::from_value(args)?;
|
let args: TruncateArgs = serde_json::from_value(args)?;
|
||||||
let filename = deno_fs::resolve_from_cwd(Path::new(&args.name))?;
|
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||||
let len = args.len;
|
let len = args.len;
|
||||||
|
|
||||||
state.check_write(&filename)?;
|
state.check_write(&path)?;
|
||||||
|
|
||||||
let is_sync = args.promise_id.is_none();
|
let is_sync = args.promise_id.is_none();
|
||||||
blocking_json(is_sync, move || {
|
blocking_json(is_sync, move || {
|
||||||
debug!("op_truncate {} {}", filename.display(), len);
|
debug!("op_truncate {} {}", path.display(), len);
|
||||||
let f = fs::OpenOptions::new().write(true).open(&filename)?;
|
let f = fs::OpenOptions::new().write(true).open(&path)?;
|
||||||
f.set_len(len)?;
|
f.set_len(len)?;
|
||||||
Ok(json!({}))
|
Ok(json!({}))
|
||||||
})
|
})
|
||||||
|
@ -596,7 +596,7 @@ fn op_make_temp_file(
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct UtimeArgs {
|
struct UtimeArgs {
|
||||||
promise_id: Option<u64>,
|
promise_id: Option<u64>,
|
||||||
filename: String,
|
path: String,
|
||||||
atime: u64,
|
atime: u64,
|
||||||
mtime: u64,
|
mtime: u64,
|
||||||
}
|
}
|
||||||
|
@ -607,11 +607,11 @@ fn op_utime(
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<JsonOp, OpError> {
|
) -> Result<JsonOp, OpError> {
|
||||||
let args: UtimeArgs = serde_json::from_value(args)?;
|
let args: UtimeArgs = serde_json::from_value(args)?;
|
||||||
state.check_write(Path::new(&args.filename))?;
|
state.check_write(Path::new(&args.path))?;
|
||||||
let is_sync = args.promise_id.is_none();
|
let is_sync = args.promise_id.is_none();
|
||||||
blocking_json(is_sync, move || {
|
blocking_json(is_sync, move || {
|
||||||
debug!("op_utime {} {} {}", args.filename, args.atime, args.mtime);
|
debug!("op_utime {} {} {}", args.path, args.atime, args.mtime);
|
||||||
utime::set_file_times(args.filename, args.atime, args.mtime)?;
|
utime::set_file_times(args.path, args.atime, args.mtime)?;
|
||||||
Ok(json!({}))
|
Ok(json!({}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue