From e7d6dc08e08cbea305fc7e1a5547dc8ec01f24ff Mon Sep 17 00:00:00 2001 From: Neta London Date: Tue, 17 Sep 2024 16:06:41 +0300 Subject: [PATCH] Don't override existing files --- projects/src/full.ts | 2 +- projects/src/reset.ts | 12 ++++++++++-- web/src/shell/settings.tsx | 1 - 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/projects/src/full.ts b/projects/src/full.ts index 08a272572..e3b35a8d6 100644 --- a/projects/src/full.ts +++ b/projects/src/full.ts @@ -72,7 +72,7 @@ export const resetTests = async (fs: FileSystem, projects?: number[]) => { }; export const createFiles = async (fs: FileSystem) => { - await reset(fs, ProjectFiles); + await reset(fs, ProjectFiles, "/", false); }; export const Assignments = { diff --git a/projects/src/reset.ts b/projects/src/reset.ts index f423de30a..6f54f996e 100644 --- a/projects/src/reset.ts +++ b/projects/src/reset.ts @@ -19,11 +19,19 @@ export async function resetBySuffix( } } -export async function reset(fs: FileSystem, tree: Tree, base?: string) { +export async function reset( + fs: FileSystem, + tree: Tree, + base?: string, + override = true, +) { + const items = (await fs.scandir(base ?? "/")).map((item) => item.name); for (const [key, value] of Object.entries(tree)) { const path = `${base ? `${base}/` : ""}${key}`; if (typeof value === "string") { - await fs.writeFile(path, value); + if (override || !items.includes(key)) { + await fs.writeFile(path, value); + } } else { await fs.mkdir(path); await reset(fs, value as Tree, path); diff --git a/web/src/shell/settings.tsx b/web/src/shell/settings.tsx index 4317e9ef6..11abc1d04 100644 --- a/web/src/shell/settings.tsx +++ b/web/src/shell/settings.tsx @@ -10,7 +10,6 @@ import "../pico/button-group.scss"; import "../pico/property.scss"; import { TrackingDisclosure } from "../tracking"; import { getVersion, setVersion } from "../versions"; -// import { useDialog } from "./dialog"; const showUpgradeFs = true;