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 7e1100f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 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
14 changes: 7 additions & 7 deletions web/src/shell/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { i18n } from "@lingui/core";
import { Trans, t } from "@lingui/macro";
import { Trans } from "@lingui/macro";
import { BaseContext } from "@nand2tetris/components/stores/base.context.js";
import { useContext, useEffect, useMemo, useState } from "react";
import { AppContext } from "../App.context";
Expand Down Expand Up @@ -34,12 +34,12 @@ export const Settings = () => {

const upgradeFsAction = async (createFiles?: boolean) => {
setUpgrading(true);
try {
await upgradeFs(localFsRoot != undefined, createFiles);
} catch (err) {
console.error("Failed to upgrade FS", { err });
setStatus(t`Failed to load local file system.`);
}
// try {
await upgradeFs(localFsRoot != undefined, createFiles);
// } catch (err) {
// console.error("Failed to upgrade FS", { err });
// setStatus(t`Failed to load local file system.`);
// }
setUpgrading(false);
};

Expand Down

0 comments on commit 7e1100f

Please sign in to comment.