Skip to content

Commit

Permalink
fix(FileItem): ensure file exists before deleting it
Browse files Browse the repository at this point in the history
  • Loading branch information
sleistner committed Jan 15, 2020
1 parent 9452f22 commit 7a44326
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ node_modules
out

.vscode-test
.idea
4 changes: 3 additions & 1 deletion src/FileItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class FileItem {
public async create(mkDir?: boolean): Promise<FileItem> {
this.ensureTargetPath();

await workspace.fs.delete(this.targetPath!, { recursive: true });
if (this.exists) {
await workspace.fs.delete(this.targetPath!, { recursive: true });
}

if (mkDir === true || this.isDir) {
await workspace.fs.createDirectory(this.targetPath!);
Expand Down
9 changes: 7 additions & 2 deletions test/helper/callbacks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { existsSync } from 'fs';
import { workspace } from 'vscode';
import { editorFile1, editorFile2, fixtureFile1, fixtureFile2, tmpDir } from './environment';

export async function beforeEach(): Promise<void> {
await workspace.fs.delete(tmpDir, { recursive: true });
if (existsSync(tmpDir.fsPath)) {
await workspace.fs.delete(tmpDir, { recursive: true });
}
await workspace.fs.copy(fixtureFile1, editorFile1, { overwrite: true });
await workspace.fs.copy(fixtureFile2, editorFile2, { overwrite: true });
}

export async function afterEach(): Promise<void> {
await workspace.fs.delete(tmpDir, { recursive: true });
if (existsSync(tmpDir.fsPath)) {
await workspace.fs.delete(tmpDir, { recursive: true });
}
}
13 changes: 11 additions & 2 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@
],
"trailing-comma": [
true,
"never"
],
{
"singleline": "never",
"multiline": {
"objects": "never",
"arrays": "never",
"functions": "never",
"typeLiterals": "never"
}
}
],
"object-literal-sort-keys": false,
"no-implicit-dependencies": [
true,
"dev",
Expand Down

0 comments on commit 7a44326

Please sign in to comment.