2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-08-21 20:42:48 -04:00
|
|
|
import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
|
2018-09-10 23:40:03 -04:00
|
|
|
|
2019-01-28 17:54:52 -05:00
|
|
|
export interface RemoveOption {
|
|
|
|
recursive?: boolean;
|
2018-09-10 23:40:03 -04:00
|
|
|
}
|
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
function req(
|
|
|
|
path: string,
|
|
|
|
options: RemoveOption
|
|
|
|
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
|
|
|
|
const builder = flatbuffers.createBuilder();
|
|
|
|
const path_ = builder.createString(path);
|
2019-04-07 20:51:43 -04:00
|
|
|
const inner = msg.Remove.createRemove(builder, path_, !!options.recursive);
|
2019-03-09 12:30:38 -05:00
|
|
|
return [builder, msg.Any.Remove, inner];
|
|
|
|
}
|
|
|
|
|
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 {
|
2019-08-21 20:42:48 -04:00
|
|
|
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> {
|
2019-08-21 20:42:48 -04:00
|
|
|
await sendAsync(...req(path, options));
|
2018-09-10 23:40:03 -04:00
|
|
|
}
|