Skip to content

Commit 1a85c84

Browse files
Refactor
1 parent 40bc300 commit 1a85c84

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

packages/cursorless-vscode/src/migrateSnippets.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ async function migrateFile(targetDirectory: string, filePath: string) {
5757
}
5858
}
5959

60-
let destinationPath = path.join(targetDirectory, `${fileName}.snippet`);
61-
if (await fileExists(destinationPath)) {
62-
destinationPath = path.join(
60+
try {
61+
const destinationPath = path.join(targetDirectory, `${fileName}.snippet`);
62+
await writeCommunityFile(communitySnippetFile, destinationPath);
63+
} catch (_error) {
64+
const destinationPath = path.join(
6365
targetDirectory,
6466
`${fileName}_CONFLICT.snippet`,
6567
);
68+
await writeCommunityFile(communitySnippetFile, destinationPath);
6669
}
67-
await writeCommunityFile(communitySnippetFile, destinationPath);
6870
}
6971

7072
function parseVariables(
@@ -84,15 +86,6 @@ function parseVariables(
8486
);
8587
}
8688

87-
async function fileExists(filePath: string): Promise<boolean> {
88-
try {
89-
await fs.access(filePath);
90-
return true;
91-
} catch (_e) {
92-
return false;
93-
}
94-
}
95-
9689
async function readLegacyFile(filePath: string): Promise<SnippetMap> {
9790
const content = await fs.readFile(filePath, "utf8");
9891
if (content.length === 0) {
@@ -103,7 +96,7 @@ async function readLegacyFile(filePath: string): Promise<SnippetMap> {
10396

10497
async function writeCommunityFile(snippetFile: SnippetFile, filePath: string) {
10598
const snippetText = serializeSnippetFile(snippetFile);
106-
const file = await fs.open(filePath, "w");
99+
const file = await fs.open(filePath, "wx");
107100
await file.write(snippetText);
108101
await file.close();
109102
}

0 commit comments

Comments
 (0)