Skip to content

Commit b390a91

Browse files
authored
Feature/elevated fs access (#157)
1 parent ac9de85 commit b390a91

File tree

12 files changed

+468
-42
lines changed

12 files changed

+468
-42
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
"@sentry/browser": "^8.34.0",
262262
"@sentry/electron": "^5.6.0",
263263
"@sinclair/typebox": "^0.34.25",
264+
"@vscode/sudo-prompt": "^9.3.1",
264265
"address": "^2.0.3",
265266
"assert": "^2.0.0",
266267
"async": "^3.2.1",

release/app/package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/actions/local-sync/common-utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,12 @@ export function removeUndefinedFromRoot(
178178
}
179179
});
180180
}
181+
182+
/**
183+
* Checks whether given value has a then function.
184+
* @param wat A value to be checked.
185+
*/
186+
export function isThenable(wat: any): wat is Promise<any> {
187+
// eslint-disable-next-line
188+
return Boolean(wat?.then && typeof wat.then === "function");
189+
}

src/renderer/actions/local-sync/fs-manager.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { type Static } from "@sinclair/typebox";
2-
3-
import fs from "node:fs";
4-
import fsp from "node:fs/promises";
52
import { v4 as uuidv4 } from "uuid";
63
import {
74
appendPath,
@@ -67,6 +64,7 @@ import {
6764
ReadmeRecordFileType,
6865
} from "./file-types/file-types";
6966
import { isEmpty } from "lodash";
67+
import { FsService } from "./fs/fs.service";
7068

7169
export class FsManager {
7270
private rootPath: string;
@@ -83,7 +81,7 @@ export class FsManager {
8381
id: getIdFromPath(appendPath(this.rootPath, CONFIG_FILE)),
8482
type: "file",
8583
});
86-
const rawConfig = fs.readFileSync(configFile.path).toString();
84+
const rawConfig = FsService.readFileSync(configFile.path).toString();
8785
const parsedConfig = parseJsonContent(rawConfig, Config);
8886
if (parsedConfig.type === "error") {
8987
throw new Error(
@@ -112,11 +110,11 @@ export class FsManager {
112110
private async parseFolder(rootPath: string, type: APIEntity["type"]) {
113111
const container: FsResource[] = [];
114112
const recursiveParser = async (path: string) => {
115-
const children = await fsp.readdir(path);
113+
const children = await FsService.readdir(path);
116114
// eslint-disable-next-line
117115
for (const child of children) {
118116
const resourcePath = appendPath(path, child);
119-
const resourceMetadata = await fsp.stat(resourcePath);
117+
const resourceMetadata = await FsService.stat(resourcePath);
120118

121119
if (resourceMetadata.isDirectory()) {
122120
container.push(
@@ -251,7 +249,6 @@ export class FsManager {
251249
this.rootPath,
252250
"environment"
253251
);
254-
console.log("ENV CONTAINER", { resourceContainer });
255252
const entities: Environment[] = [];
256253
const erroredRecords: ErroredRecord[] = [];
257254
// eslint-disable-next-line
@@ -416,7 +413,9 @@ export class FsManager {
416413
path,
417414
type: "folder",
418415
});
419-
const createResult = await createFolder(resource, true);
416+
const createResult = await createFolder(resource, {
417+
errorIfDoesNotExist: true,
418+
});
420419
if (createResult.type === "error") {
421420
return createResult;
422421
}
@@ -517,21 +516,17 @@ export class FsManager {
517516
},
518517
};
519518
}
520-
console.log("rename 1", id);
521519
const folderResource = this.createResource({
522520
id,
523521
type: "folder",
524522
});
525523
const parentPath = getParentFolderPath(folderResource);
526-
console.log("rename 2", parentPath, newName);
527524

528525
const newFolderResource = this.createResource({
529526
id: getIdFromPath(appendPath(parentPath, newName)),
530527
type: "folder",
531528
});
532529

533-
console.log("rename 3", newFolderResource);
534-
535530
const renameResult = await rename(folderResource, newFolderResource);
536531
if (renameResult.type === "error") {
537532
return renameResult;

0 commit comments

Comments
 (0)