Skip to content

Commit

Permalink
Don't override existing files
Browse files Browse the repository at this point in the history
  • Loading branch information
netalondon committed Sep 17, 2024
1 parent dcfabf2 commit e7d6dc0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion projects/src/full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
12 changes: 10 additions & 2 deletions projects/src/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion web/src/shell/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e7d6dc0

Please sign in to comment.