mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(ext/node): cp
into non-existent parent directory (#23469)
Fixes https://github.com/denoland/deno/issues/20604
This commit is contained in:
parent
e0554ac4a2
commit
04c6785fae
2 changed files with 17 additions and 1 deletions
|
@ -576,6 +576,12 @@ fn cp(from: &Path, to: &Path) -> FsResult<()> {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure parent destination directory exists
|
||||
if let Some(parent) = to.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
|
||||
copy_file(from, to)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import * as path from "@std/path/mod.ts";
|
||||
import { assert } from "@std/assert/mod.ts";
|
||||
import { assertCallbackErrorUncaught } from "../_test_utils.ts";
|
||||
import { copyFile, copyFileSync, existsSync } from "node:fs";
|
||||
import { copyFile, copyFileSync, cpSync, existsSync } from "node:fs";
|
||||
|
||||
const destFile = "./destination.txt";
|
||||
|
||||
|
@ -50,3 +50,13 @@ Deno.test("[std/node/fs] copyFile callback isn't called twice if error is thrown
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("[std/node/fs] cp creates destination directory", async () => {
|
||||
const tempDir = await Deno.makeTempDir();
|
||||
const tempFile1 = path.join(tempDir, "file1.txt");
|
||||
const tempFile2 = path.join(tempDir, "dir", "file2.txt");
|
||||
await Deno.writeTextFile(tempFile1, "hello world");
|
||||
cpSync(tempFile1, tempFile2);
|
||||
assert(existsSync(tempFile2));
|
||||
await Deno.remove(tempDir, { recursive: true });
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue