2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-10-03 21:18:23 -04:00
|
|
|
import * as msg from "gen/msg_generated";
|
2018-10-17 13:04:28 -04:00
|
|
|
import * as flatbuffers from "./flatbuffers";
|
2018-09-10 23:40:03 -04:00
|
|
|
import * as dispatch from "./dispatch";
|
|
|
|
|
2019-01-28 17:54:52 -05:00
|
|
|
export interface RemoveOption {
|
|
|
|
recursive?: boolean;
|
2018-09-10 23:40:03 -04:00
|
|
|
}
|
|
|
|
|
2019-01-28 17:54:52 -05:00
|
|
|
/** Removes the named file or directory synchronously. Would throw
|
|
|
|
* error if permission denied, not found, or directory not empty if `recursive`
|
|
|
|
* set to false.
|
|
|
|
* `recursive` is set to false by default.
|
2018-09-10 23:40:03 -04:00
|
|
|
*
|
2019-02-12 10:08:56 -05:00
|
|
|
* Deno.removeSync("/path/to/dir/or/file", {recursive: false});
|
2018-09-10 23:40:03 -04:00
|
|
|
*/
|
2019-01-28 17:54:52 -05:00
|
|
|
export function removeSync(path: string, options: RemoveOption = {}): void {
|
|
|
|
dispatch.sendSync(...req(path, options));
|
2018-09-10 23:40:03 -04:00
|
|
|
}
|
|
|
|
|
2019-01-28 17:54:52 -05:00
|
|
|
/** Removes the named file or directory. Would throw error if
|
|
|
|
* permission denied, not found, or directory not empty if `recursive` set
|
|
|
|
* to false.
|
|
|
|
* `recursive` is set to false by default.
|
2018-09-10 23:40:03 -04:00
|
|
|
*
|
2019-02-12 10:08:56 -05:00
|
|
|
* await Deno.remove("/path/to/dir/or/file", {recursive: false});
|
2018-09-10 23:40:03 -04:00
|
|
|
*/
|
2019-01-28 17:54:52 -05:00
|
|
|
export async function remove(
|
|
|
|
path: string,
|
|
|
|
options: RemoveOption = {}
|
|
|
|
): Promise<void> {
|
|
|
|
await dispatch.sendAsync(...req(path, options));
|
2018-09-10 23:40:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function req(
|
|
|
|
path: string,
|
2019-01-28 17:54:52 -05:00
|
|
|
options: RemoveOption
|
2018-10-03 21:18:23 -04:00
|
|
|
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
|
2018-10-17 13:04:28 -04:00
|
|
|
const builder = flatbuffers.createBuilder();
|
2018-09-10 23:40:03 -04:00
|
|
|
const path_ = builder.createString(path);
|
2018-10-03 21:18:23 -04:00
|
|
|
msg.Remove.startRemove(builder);
|
|
|
|
msg.Remove.addPath(builder, path_);
|
2019-01-28 17:54:52 -05:00
|
|
|
msg.Remove.addRecursive(builder, !!options.recursive);
|
2018-10-03 21:18:23 -04:00
|
|
|
const inner = msg.Remove.endRemove(builder);
|
|
|
|
return [builder, msg.Any.Remove, inner];
|
2018-09-10 23:40:03 -04:00
|
|
|
}
|