summaryrefslogtreecommitdiff
path: root/fs/move.ts
diff options
context:
space:
mode:
authorAxetroy <troy450409405@gmail.com>2019-03-18 00:34:55 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-03-17 12:34:55 -0400
commit942df0be0d8bb37862195c438017df7746b0f3f0 (patch)
tree8d52e754c60944c7cc4fc825558b5f6d64deadc0 /fs/move.ts
parent8acdecd72da494044065cb0615d9db3ce0a39a1c (diff)
extract internal method isSubdir to fs/utils.ts (denoland/deno_std#285)
Original: https://github.com/denoland/deno_std/commit/da4abcd9a3a5775939c3941a884d1c6f4d287d0f
Diffstat (limited to 'fs/move.ts')
-rw-r--r--fs/move.ts14
1 files changed, 3 insertions, 11 deletions
diff --git a/fs/move.ts b/fs/move.ts
index eb6352bd5..007e4520b 100644
--- a/fs/move.ts
+++ b/fs/move.ts
@@ -1,20 +1,12 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as path from "./path/mod.ts";
import { exists, existsSync } from "./exists.ts";
+import { isSubdir } from "./utils.ts";
interface MoveOptions {
overwrite?: boolean;
}
-function isSrcSubdir(src: string, dest: string): boolean {
- const srcArray = src.split(path.sep);
- const destArray = dest.split(path.sep);
-
- return srcArray.reduce((acc, current, i) => {
- return acc && destArray[i] === current;
- }, true);
-}
-
/** Moves a file or directory */
export async function move(
src: string,
@@ -26,7 +18,7 @@ export async function move(
const srcStat = await Deno.stat(src);
- if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
+ if (srcStat.isDirectory() && isSubdir(src, dest)) {
throw new Error(
`Cannot move '${src}' to a subdirectory of itself, '${dest}'.`
);
@@ -56,7 +48,7 @@ export function moveSync(
const srcStat = Deno.statSync(src);
- if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
+ if (srcStat.isDirectory() && isSubdir(src, dest)) {
throw new Error(
`Cannot move '${src}' to a subdirectory of itself, '${dest}'.`
);