Skip to content

Commit

Permalink
Add remove(), removeAll().
Browse files Browse the repository at this point in the history
and removeSync(), removeAllSync().
  • Loading branch information
kevinkassimo authored and ry committed Sep 12, 2018
1 parent 7c50c11 commit 1ffae65
Show file tree
Hide file tree
Showing 8 changed files with 441 additions and 7 deletions.
5 changes: 5 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ main_extern = [
"$rust_build:rand",
"$rust_build:tokio",
"$rust_build:url",
"$rust_build:remove_dir_all",
"//build_extra/flatbuffers/rust:flatbuffers",
":msg_rs",
]
Expand Down Expand Up @@ -198,13 +199,15 @@ run_node("gen_declarations") {
"js/mkdir.ts",
"js/os.ts",
"js/read_file.ts",
"js/remove.ts",
"js/stat.ts",
"js/text_encoding.ts",
"js/timers.ts",
"js/tsconfig.generated.json",
"js/types.ts",
"js/util.ts",
"js/v8_source_maps.ts",
"js/write_file.ts",
]
outputs = [
"$out_dir/types/globals.d.ts",
Expand Down Expand Up @@ -239,12 +242,14 @@ run_node("bundle") {
"js/os.ts",
"js/plugins.d.ts",
"js/read_file.ts",
"js/remove.ts",
"js/stat.ts",
"js/text_encoding.ts",
"js/timers.ts",
"js/types.ts",
"js/util.ts",
"js/v8_source_maps.ts",
"js/write_file.ts",
"rollup.config.js",
"src/msg.fbs",
"tsconfig.json",
Expand Down
8 changes: 2 additions & 6 deletions js/deno.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// Public deno module.
/// <amd-module name="deno"/>
export {
env,
exit,
makeTempDirSync,
renameSync,
} from "./os";
export { env, exit, makeTempDirSync, renameSync } from "./os";
export { mkdirSync, mkdir } from "./mkdir";
export { removeSync, remove, removeAllSync, removeAll } from "./remove";
export { readFileSync, readFile } from "./read_file";
export { FileInfo, statSync, lstatSync, stat, lstat } from "./stat";
export { writeFileSync, writeFile } from "./write_file";
Expand Down
63 changes: 63 additions & 0 deletions js/remove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import * as fbs from "gen/msg_generated";
import { flatbuffers } from "flatbuffers";
import * as dispatch from "./dispatch";

/**
* Removes the named file or (empty) directory synchronously.
* Would throw error if permission denied, not found, or
* directory not empty.
*
* import { removeSync } from "deno";
* removeSync("/path/to/empty_dir/or/file");
*/
export function removeSync(path: string): void {
dispatch.sendSync(...req(path, false));
}

/**
* Removes the named file or (empty) directory.
* Would throw error if permission denied, not found, or
* directory not empty.
*
* import { remove } from "deno";
* await remove("/path/to/empty_dir/or/file");
*/
export async function remove(path: string): Promise<void> {
await dispatch.sendAsync(...req(path, false));
}

/**
* Recursively removes the named file or directory synchronously.
* Would throw error if permission denied or not found
*
* import { removeAllSync } from "deno";
* removeAllSync("/path/to/dir/or/file");
*/
export function removeAllSync(path: string): void {
dispatch.sendSync(...req(path, true));
}

/**
* Recursively removes the named file or directory.
* Would throw error if permission denied or not found
*
* import { removeAll } from "deno";
* await removeAll("/path/to/dir/or/file");
*/
export async function removeAll(path: string): Promise<void> {
await dispatch.sendAsync(...req(path, true));
}

function req(
path: string,
recursive: boolean
): [flatbuffers.Builder, fbs.Any, flatbuffers.Offset] {
const builder = new flatbuffers.Builder();
const path_ = builder.createString(path);
fbs.Remove.startRemove(builder);
fbs.Remove.addPath(builder, path_);
fbs.Remove.addRecursive(builder, recursive);
const msg = fbs.Remove.endRemove(builder);
return [builder, fbs.Any.Remove, msg];
}
Loading

0 comments on commit 1ffae65

Please sign in to comment.