Skip to content

Commit 1014182

Browse files
authored
Merge pull request #5 from RefactorSecurity/fix-local-persistence
Fix local file persistence
2 parents ae9fdcc + 5e08699 commit 1014182

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Security Notes",
44
"description": "Create notes during a security code review. Import your favorite SAST tool results and collaborate with others.",
55
"icon": "resources/security_notes_logo.png",
6-
"version": "1.0.0",
6+
"version": "1.0.1",
77
"publisher": "refactor-security",
88
"private": false,
99
"license": "MIT",

src/persistence/local-db/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { Serializer } from '../serialization/serializer';
55
import { Deserializer } from '../serialization/deserializer';
66
import { CommentThread } from 'vscode';
77
import { getSetting } from '../../helpers';
8+
import { getLocalDbFilePath } from '../../utils';
89

9-
const persistenceFile = getSetting('localDatabase');
10+
const persistenceFile = getLocalDbFilePath();
1011

1112
export const saveCommentsToFile = (noteList: Map<string, CommentThread>) => {
1213
fs.writeFileSync(persistenceFile, JSON.stringify(Serializer.serialize(noteList)));

src/persistence/serialization/serializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class Serializer {
4949
thread.comments.forEach((comment) => {
5050
serializedComments.push(this.serializeComment(comment));
5151
});
52-
let uri = fullPathToRelative(thread.uri.path);
52+
let uri = fullPathToRelative(thread.uri.fsPath);
5353
if (isWindows()) {
5454
uri = pathToPosix(uri);
5555
}

src/utils/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as vscode from 'vscode';
44
import * as path from 'path';
55
import { platform } from 'os';
6+
import { getSetting } from '../helpers';
67

78
export const isWindows = () => {
89
return platform() === 'win32';
@@ -18,12 +19,21 @@ export const pathToWin32 = (aPath: string) => {
1819

1920
export const getWorkspacePath = () => {
2021
if (vscode.workspace.workspaceFolders) {
21-
return vscode.workspace.workspaceFolders[0].uri.path;
22+
return vscode.workspace.workspaceFolders[0].uri.fsPath;
2223
} else {
2324
return '';
2425
}
2526
};
2627

28+
export const getLocalDbFilePath = () => {
29+
const localDbFilePath = getSetting('localDatabase');
30+
if (path.isAbsolute(localDbFilePath)) {
31+
return localDbFilePath;
32+
} else {
33+
return relativePathToFull(localDbFilePath);
34+
}
35+
};
36+
2737
export const relativePathToFull = (aPath: string, basePath?: string) => {
2838
if (basePath) {
2939
return path.join(basePath, aPath);

0 commit comments

Comments
 (0)