Skip to content

Commit 08b420a

Browse files
committed
be more robust when destRobotsTxt == srcRobotsTxt
1 parent 6aa81a5 commit 08b420a

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/project/types/website/website-sitemap.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (C) 2020-2022 Posit Software, PBC
55
*/
66

7-
import { existsSync } from "../../../deno_ral/fs.ts";
7+
import { existsSync, safeRemoveDirSync, safeRemoveSync } from "../../../deno_ral/fs.ts";
88
import { basename, join, relative } from "../../../deno_ral/path.ts";
99

1010
import { ElementInfo, SAXParser } from "xmlp/mod.ts";
@@ -57,7 +57,10 @@ export async function updateSitemap(
5757
const robotsTxtPath = join(context.dir, "robots.txt");
5858
const srcRobotsTxt = existsSync(robotsTxtPath) ? robotsTxtPath : undefined;
5959
const destRobotsTxt = join(outputDir, "robots.txt");
60-
if (srcRobotsTxt) {
60+
if (srcRobotsTxt && destRobotsTxt !== srcRobotsTxt) {
61+
if (existsSync(destRobotsTxt)) {
62+
safeRemoveSync(destRobotsTxt);
63+
}
6164
copyTo(srcRobotsTxt, destRobotsTxt);
6265
}
6366

0 commit comments

Comments
 (0)