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:
dubiousjim 2020-03-06 11:29:23 -05:00 committed by GitHub
parent bb3d9c8280
commit acf0958e94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 111 additions and 114 deletions

View file

@ -27,7 +27,7 @@ let OP_WRITE = -1;
*
* 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.
*
@ -35,11 +35,11 @@ export function openSync(filename: string, mode?: OpenOptions): File;
*
* 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*/
export function openSync(
filename: string,
path: string,
modeOrOptions: OpenOptions | OpenMode = "r"
): File {
let mode = null;
@ -52,7 +52,7 @@ export function openSync(
options = modeOrOptions;
}
const rid = sendSyncJson("op_open", { filename, options, mode });
const rid = sendSyncJson("op_open", { path, options, mode });
return new File(rid);
}
@ -62,10 +62,7 @@ export function openSync(
*
* Requires `allow-read` and `allow-write` permissions depending on mode.
*/
export async function open(
filename: string,
options?: OpenOptions
): Promise<File>;
export async function open(path: string, options?: OpenOptions): Promise<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.
*/
export async function open(filename: string, mode?: OpenMode): Promise<File>;
export async function open(path: string, mode?: OpenMode): Promise<File>;
/**@internal*/
export async function open(
filename: string,
path: string,
modeOrOptions: OpenOptions | OpenMode = "r"
): Promise<File> {
let mode = null;
@ -91,7 +88,7 @@ export async function open(
}
const rid = await sendAsyncJson("op_open", {
filename,
path,
options,
mode
});
@ -105,8 +102,8 @@ export async function open(
*
* Requires `allow-read` and `allow-write` permissions.
*/
export function createSync(filename: string): File {
return openSync(filename, "w+");
export function createSync(path: string): File {
return openSync(path, "w+");
}
/** 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.
*/
export function create(filename: string): Promise<File> {
return open(filename, "w+");
export function create(path: string): Promise<File> {
return open(path, "w+");
}
/** Synchronously read from a file ID into an array buffer.

View file

@ -435,7 +435,7 @@ declare namespace Deno {
*
* 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.
*
@ -443,7 +443,7 @@ declare namespace Deno {
*
* 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.
*
@ -451,7 +451,7 @@ declare namespace Deno {
*
* 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`.
*
@ -459,7 +459,7 @@ declare namespace Deno {
*
* 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
* an instance of `Deno.File`.
@ -468,7 +468,7 @@ declare namespace Deno {
*
* 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
* an instance of `Deno.File`.
@ -477,7 +477,7 @@ declare namespace Deno {
*
* 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.
*
@ -893,14 +893,14 @@ declare namespace Deno {
/** **UNSTABLE**: needs investigation into high precision time.
*
* Synchronously changes the access and modification times of a file system
* object referenced by `filename`. Given times are either in seconds (UNIX
* epoch time) or as `Date` objects.
* object referenced by `path`. Given times are either in seconds (UNIX epoch
* time) or as `Date` objects.
*
* Deno.utimeSync("myfile.txt", 1556495550, new Date());
*
* Requires `allow-write` permission. */
export function utimeSync(
filename: string,
path: string,
atime: number | Date,
mtime: number | Date
): void;
@ -908,14 +908,14 @@ declare namespace Deno {
/** **UNSTABLE**: needs investigation into high precision time.
*
* Changes the access and modification times of a file system object
* referenced by `filename`. Given times are either in seconds (UNIX epoch
* time) or as `Date` objects.
* referenced by `path`. Given times are either in seconds (UNIX epoch time)
* or as `Date` objects.
*
* await Deno.utime("myfile.txt", 1556495550, new Date());
*
* Requires `allow-write` permission. */
export function utime(
filename: string,
path: string,
atime: number | Date,
mtime: number | Date
): Promise<void>;
@ -976,7 +976,7 @@ declare namespace Deno {
* console.log(decoder.decode(data));
*
* 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.
*
@ -985,7 +985,7 @@ declare namespace Deno {
* console.log(decoder.decode(data));
*
* Requires `allow-read` permission. */
export function readFile(filename: string): Promise<Uint8Array>;
export function readFile(path: string): Promise<Uint8Array>;
// @url js/file_info.d.ts
@ -1127,52 +1127,52 @@ declare namespace Deno {
* const targetPath = Deno.readlinkSync("symlink/path");
*
* 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.
*
* const targetPath = await Deno.readlink("symlink/path");
*
* Requires `allow-read` permission. */
export function readlink(name: string): Promise<string>;
export function readlink(path: string): Promise<string>;
// @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.
*
* const fileInfo = await Deno.lstat("hello.txt");
* assert(fileInfo.isFile());
*
* 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
* path is a symlink, information for the symlink will be returned.
/** Synchronously returns a `Deno.FileInfo` for the specified `path`. If
* `path` is a symlink, information for the symlink will be returned.
*
* const fileInfo = Deno.lstatSync("hello.txt");
* assert(fileInfo.isFile());
*
* 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
* symlinks.
/** Resolves to a `Deno.FileInfo` for the specified `path`. Will always
* follow symlinks.
*
* const fileInfo = await Deno.stat("hello.txt");
* assert(fileInfo.isFile());
*
* 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.
*
* const fileInfo = Deno.statSync("hello.txt");
* assert(fileInfo.isFile());
*
* Requires `allow-read` permission. */
export function statSync(filename: string): FileInfo;
export function statSync(path: string): FileInfo;
// @url js/link.d.ts
@ -1246,7 +1246,7 @@ declare namespace Deno {
* Requires `allow-write` permission, and `allow-read` if create is `false`.
*/
export function writeFileSync(
filename: string,
path: string,
data: Uint8Array,
options?: WriteFileOptions
): void;
@ -1261,7 +1261,7 @@ declare namespace Deno {
* Requires `allow-write` permission, and `allow-read` if create is `false`.
*/
export function writeFile(
filename: string,
path: string,
data: Uint8Array,
options?: WriteFileOptions
): Promise<void>;

View file

@ -9,8 +9,8 @@ import { readAll, readAllSync } from "./buffer.ts";
* console.log(decoder.decode(data));
*
* Requires `allow-read` permission. */
export function readFileSync(filename: string): Uint8Array {
const file = openSync(filename);
export function readFileSync(path: string): Uint8Array {
const file = openSync(path);
const contents = readAllSync(file);
file.close();
return contents;
@ -23,8 +23,8 @@ export function readFileSync(filename: string): Uint8Array {
* console.log(decoder.decode(data));
*
* Requires `allow-read` permission. */
export async function readFile(filename: string): Promise<Uint8Array> {
const file = await open(filename);
export async function readFile(path: string): Promise<Uint8Array> {
const file = await open(path);
const contents = await readAll(file);
file.close();
return contents;

View file

@ -6,8 +6,8 @@ import { sendSync, sendAsync } from "./dispatch_json.ts";
* const targetPath = Deno.readlinkSync("symlink/path");
*
* Requires `allow-read` permission. */
export function readlinkSync(name: string): string {
return sendSync("op_read_link", { name });
export function readlinkSync(path: string): string {
return sendSync("op_read_link", { path });
}
/** 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");
*
* Requires `allow-read` permission. */
export async function readlink(name: string): Promise<string> {
return await sendAsync("op_read_link", { name });
export async function readlink(path: string): Promise<string> {
return await sendAsync("op_read_link", { path });
}

View file

@ -23,61 +23,61 @@ export interface StatResponse {
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.
*
* const fileInfo = await Deno.lstat("hello.txt");
* assert(fileInfo.isFile());
*
* 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", {
filename,
path,
lstat: true
})) as StatResponse;
return new FileInfoImpl(res);
}
/** Synchronously returns a `Deno.FileInfo` for the specified path. If
* path is a symlink, information for the symlink will be returned.
/** Synchronously returns a `Deno.FileInfo` for the specified `path`. If
* `path` is a symlink, information for the symlink will be returned.
*
* const fileInfo = Deno.lstatSync("hello.txt");
* assert(fileInfo.isFile());
*
* Requires `allow-read` permission. */
export function lstatSync(filename: string): FileInfo {
export function lstatSync(path: string): FileInfo {
const res = sendSync("op_stat", {
filename,
path,
lstat: true
}) as StatResponse;
return new FileInfoImpl(res);
}
/** Resolves to a `Deno.FileInfo` for the specified path. Will always follow
* symlinks.
/** Resolves to a `Deno.FileInfo` for the specified `path`. Will always
* follow symlinks.
*
* const fileInfo = await Deno.stat("hello.txt");
* assert(fileInfo.isFile());
*
* 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", {
filename,
path,
lstat: false
})) as StatResponse;
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.
*
* const fileInfo = Deno.statSync("hello.txt");
* assert(fileInfo.isFile());
*
* Requires `allow-read` permission. */
export function statSync(filename: string): FileInfo {
export function statSync(path: string): FileInfo {
const res = sendSync("op_stat", {
filename,
path,
lstat: false
}) as StatResponse;
return new FileInfoImpl(res);

View file

@ -19,8 +19,8 @@ function coerceLen(len?: number): number {
* Deno.truncateSync("hello.txt", 10);
*
* Requires `allow-write` permission. */
export function truncateSync(name: string, len?: number): void {
sendSync("op_truncate", { name, len: coerceLen(len) });
export function truncateSync(path: string, len?: number): void {
sendSync("op_truncate", { path, len: coerceLen(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);
*
* Requires `allow-write` permission. */
export async function truncate(name: string, len?: number): Promise<void> {
await sendAsync("op_truncate", { name, len: coerceLen(len) });
export async function truncate(path: string, len?: number): Promise<void> {
await sendAsync("op_truncate", { path, len: coerceLen(len) });
}

View file

@ -8,19 +8,19 @@ function toSecondsFromEpoch(v: number | Date): number {
/** **UNSTABLE**: needs investigation into high precision time.
*
* Synchronously changes the access and modification times of a file system
* object referenced by `filename`. Given times are either in seconds
* (Unix epoch time) or as `Date` objects.
* object referenced by `path`. Given times are either in seconds (UNIX epoch
* time) or as `Date` objects.
*
* Deno.utimeSync("myfile.txt", 1556495550, new Date());
*
* Requires `allow-write` permission. */
export function utimeSync(
filename: string,
path: string,
atime: number | Date,
mtime: number | Date
): void {
sendSync("op_utime", {
filename,
path,
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
atime: toSecondsFromEpoch(atime),
mtime: toSecondsFromEpoch(mtime)
@ -30,19 +30,19 @@ export function utimeSync(
/** **UNSTABLE**: needs investigation into high precision time.
*
* Changes the access and modification times of a file system object
* referenced by `filename`. Given times are either in seconds
* (Unix epoch time) or as `Date` objects.
* referenced by `path`. Given times are either in seconds (UNIX epoch time)
* or as `Date` objects.
*
* await Deno.utime("myfile.txt", 1556495550, new Date());
*
* Requires `allow-write` permission. */
export async function utime(
filename: string,
path: string,
atime: number | Date,
mtime: number | Date
): Promise<void> {
await sendAsync("op_utime", {
filename,
path,
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
atime: toSecondsFromEpoch(atime),
mtime: toSecondsFromEpoch(mtime)

View file

@ -26,7 +26,7 @@ export interface WriteFileOptions {
* Requires `allow-write` permission, and `allow-read` if create is `false`.
*/
export function writeFileSync(
filename: string,
path: string,
data: Uint8Array,
options: WriteFileOptions = {}
): void {
@ -34,15 +34,15 @@ export function writeFileSync(
const create = !!options.create;
if (!create) {
// verify that file exists
statSync(filename);
statSync(path);
}
}
const openMode = !!options.append ? "a" : "w";
const file = openSync(filename, openMode);
const file = openSync(path, openMode);
if (options.perm !== undefined && options.perm !== null) {
chmodSync(filename, options.perm);
chmodSync(path, options.perm);
}
writeAllSync(file, data);
@ -59,7 +59,7 @@ export function writeFileSync(
* Requires `allow-write` permission, and `allow-read` if create is `false`.
*/
export async function writeFile(
filename: string,
path: string,
data: Uint8Array,
options: WriteFileOptions = {}
): Promise<void> {
@ -67,15 +67,15 @@ export async function writeFile(
const create = !!options.create;
if (!create) {
// verify that file exists
await stat(filename);
await stat(path);
}
}
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) {
await chmod(filename, options.perm);
await chmod(path, options.perm);
}
await writeAll(file, data);