mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 23:59:59 -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.
|
||||
*/
|
||||
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.
|
||||
|
|
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.
|
||||
*/
|
||||
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>;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) });
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn init(i: &mut Isolate, s: &State) {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
struct OpenArgs {
|
||||
promise_id: Option<u64>,
|
||||
filename: String,
|
||||
path: String,
|
||||
options: Option<OpenOptions>,
|
||||
mode: Option<String>,
|
||||
}
|
||||
|
@ -45,17 +45,17 @@ fn op_open(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, OpError> {
|
||||
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 mut open_options = tokio::fs::OpenOptions::new();
|
||||
|
||||
if let Some(options) = args.options {
|
||||
if options.read {
|
||||
state.check_read(&filename)?;
|
||||
state.check_read(&path)?;
|
||||
}
|
||||
|
||||
if options.write || options.append {
|
||||
state.check_write(&filename)?;
|
||||
state.check_write(&path)?;
|
||||
}
|
||||
|
||||
open_options
|
||||
|
@ -69,14 +69,14 @@ fn op_open(
|
|||
let mode = mode.as_ref();
|
||||
match mode {
|
||||
"r" => {
|
||||
state.check_read(&filename)?;
|
||||
state.check_read(&path)?;
|
||||
}
|
||||
"w" | "a" | "x" => {
|
||||
state.check_write(&filename)?;
|
||||
state.check_write(&path)?;
|
||||
}
|
||||
&_ => {
|
||||
state.check_read(&filename)?;
|
||||
state.check_write(&filename)?;
|
||||
state.check_read(&path)?;
|
||||
state.check_write(&path)?;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -123,7 +123,7 @@ fn op_open(
|
|||
let is_sync = args.promise_id.is_none();
|
||||
|
||||
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 rid = state.resource_table.add(
|
||||
"fsFile",
|
||||
|
|
|
@ -275,7 +275,7 @@ fn get_stat_json(
|
|||
#[serde(rename_all = "camelCase")]
|
||||
struct StatArgs {
|
||||
promise_id: Option<u64>,
|
||||
filename: String,
|
||||
path: String,
|
||||
lstat: bool,
|
||||
}
|
||||
|
||||
|
@ -285,18 +285,18 @@ fn op_stat(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, OpError> {
|
||||
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;
|
||||
|
||||
state.check_read(&filename)?;
|
||||
state.check_read(&path)?;
|
||||
|
||||
let is_sync = args.promise_id.is_none();
|
||||
blocking_json(is_sync, move || {
|
||||
debug!("op_stat {} {}", filename.display(), lstat);
|
||||
debug!("op_stat {} {}", path.display(), lstat);
|
||||
let metadata = if lstat {
|
||||
fs::symlink_metadata(&filename)?
|
||||
fs::symlink_metadata(&path)?
|
||||
} else {
|
||||
fs::metadata(&filename)?
|
||||
fs::metadata(&path)?
|
||||
};
|
||||
get_stat_json(metadata, None)
|
||||
})
|
||||
|
@ -464,7 +464,7 @@ fn op_symlink(
|
|||
#[serde(rename_all = "camelCase")]
|
||||
struct ReadLinkArgs {
|
||||
promise_id: Option<u64>,
|
||||
name: String,
|
||||
path: String,
|
||||
}
|
||||
|
||||
fn op_read_link(
|
||||
|
@ -473,14 +473,14 @@ fn op_read_link(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, OpError> {
|
||||
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();
|
||||
blocking_json(is_sync, move || {
|
||||
debug!("op_read_link {}", name.display());
|
||||
let path = fs::read_link(&name)?;
|
||||
debug!("op_read_link {}", path.display());
|
||||
let path = fs::read_link(&path)?;
|
||||
let path_str = path.to_str().unwrap();
|
||||
|
||||
Ok(json!(path_str))
|
||||
|
@ -491,7 +491,7 @@ fn op_read_link(
|
|||
#[serde(rename_all = "camelCase")]
|
||||
struct TruncateArgs {
|
||||
promise_id: Option<u64>,
|
||||
name: String,
|
||||
path: String,
|
||||
len: u64,
|
||||
}
|
||||
|
||||
|
@ -501,15 +501,15 @@ fn op_truncate(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, OpError> {
|
||||
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;
|
||||
|
||||
state.check_write(&filename)?;
|
||||
state.check_write(&path)?;
|
||||
|
||||
let is_sync = args.promise_id.is_none();
|
||||
blocking_json(is_sync, move || {
|
||||
debug!("op_truncate {} {}", filename.display(), len);
|
||||
let f = fs::OpenOptions::new().write(true).open(&filename)?;
|
||||
debug!("op_truncate {} {}", path.display(), len);
|
||||
let f = fs::OpenOptions::new().write(true).open(&path)?;
|
||||
f.set_len(len)?;
|
||||
Ok(json!({}))
|
||||
})
|
||||
|
@ -596,7 +596,7 @@ fn op_make_temp_file(
|
|||
#[serde(rename_all = "camelCase")]
|
||||
struct UtimeArgs {
|
||||
promise_id: Option<u64>,
|
||||
filename: String,
|
||||
path: String,
|
||||
atime: u64,
|
||||
mtime: u64,
|
||||
}
|
||||
|
@ -607,11 +607,11 @@ fn op_utime(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, OpError> {
|
||||
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();
|
||||
blocking_json(is_sync, move || {
|
||||
debug!("op_utime {} {} {}", args.filename, args.atime, args.mtime);
|
||||
utime::set_file_times(args.filename, args.atime, args.mtime)?;
|
||||
debug!("op_utime {} {} {}", args.path, args.atime, args.mtime);
|
||||
utime::set_file_times(args.path, args.atime, args.mtime)?;
|
||||
Ok(json!({}))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue