refactor: move code from fs.rs into ops/fs.rs (#4428)

This a complex boring PR that shifts around code (primarily) in cli/fs.rs and
cli/ops/fs.rs. The gain of this refactoring is to ease the way for #4188 and
#4017, and also to avoid some future development pain.

Mostly there is no change in functionality. Except:
* squashed bugs where op_utime and op_chown weren't using `resolve_from_cwd`
* eliminated the use of the external `remove_dir_all` crate.
* op_chmod now only queries metadata to verify file/dir exists on Windows (it
  will already fail on Unix if it doesn't)
* op_chown now verifies the file/dir's existence on Windows like chmod does.
This commit is contained in:
dubiousjim 2020-03-20 09:46:26 -04:00 committed by GitHub
parent 798904b0f2
commit 69303e2149
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 196 additions and 209 deletions

View file

@ -1291,25 +1291,25 @@ declare namespace Deno {
// @url js/link.d.ts
/** Creates `newname` as a hard link to `oldname`.
/** Creates `newpath` as a hard link to `oldpath`.
*
* Deno.linkSync("old/name", "new/name");
*
* Requires `allow-read` and `allow-write` permissions. */
export function linkSync(oldname: string, newname: string): void;
export function linkSync(oldpath: string, newpath: string): void;
/** Creates `newname` as a hard link to `oldname`.
/** Creates `newpath` as a hard link to `oldpath`.
*
* await Deno.link("old/name", "new/name");
*
* Requires `allow-read` and `allow-write` permissions. */
export function link(oldname: string, newname: string): Promise<void>;
export function link(oldpath: string, newpath: string): Promise<void>;
// @url js/symlink.d.ts
/** **UNSTABLE**: `type` argument type may be changed to `"dir" | "file"`.
*
* Creates `newname` as a symbolic link to `oldname`. The type argument can be
* Creates `newpath` as a symbolic link to `oldpath`. The type argument can be
* set to `dir` or `file`. Is only available on Windows and ignored on other
* platforms.
*
@ -1317,14 +1317,14 @@ declare namespace Deno {
*
* Requires `allow-read` and `allow-write` permissions. */
export function symlinkSync(
oldname: string,
newname: string,
oldpath: string,
newpath: string,
type?: string
): void;
/** **UNSTABLE**: `type` argument may be changed to "dir" | "file"
*
* Creates `newname` as a symbolic link to `oldname`. The type argument can be
* Creates `newpath` as a symbolic link to `oldpath`. The type argument can be
* set to `dir` or `file`. Is only available on Windows and ignored on other
* platforms.
*
@ -1332,8 +1332,8 @@ declare namespace Deno {
*
* Requires `allow-read` and `allow-write` permissions. */
export function symlink(
oldname: string,
newname: string,
oldpath: string,
newpath: string,
type?: string
): Promise<void>;

View file

@ -1,10 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
export function linkSync(oldname: string, newname: string): void {
sendSync("op_link", { oldname, newname });
export function linkSync(oldpath: string, newpath: string): void {
sendSync("op_link", { oldpath, newpath });
}
export async function link(oldname: string, newname: string): Promise<void> {
await sendAsync("op_link", { oldname, newname });
export async function link(oldpath: string, newpath: string): Promise<void> {
await sendAsync("op_link", { oldpath, newpath });
}

View file

@ -4,23 +4,23 @@ import * as util from "../../util.ts";
import { build } from "../../build.ts";
export function symlinkSync(
oldname: string,
newname: string,
oldpath: string,
newpath: string,
type?: string
): void {
if (build.os === "win" && type) {
return util.notImplemented();
}
sendSync("op_symlink", { oldname, newname });
sendSync("op_symlink", { oldpath, newpath });
}
export async function symlink(
oldname: string,
newname: string,
oldpath: string,
newpath: string,
type?: string
): Promise<void> {
if (build.os === "win" && type) {
return util.notImplemented();
}
await sendAsync("op_symlink", { oldname, newname });
await sendAsync("op_symlink", { oldpath, newpath });
}