Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

New project command deletes any existing contents #75

Closed
archiewood opened this issue Jun 7, 2023 · 6 comments · Fixed by #78
Closed

New project command deletes any existing contents #75

archiewood opened this issue Jun 7, 2023 · 6 comments · Fixed by #78
Labels
bug Something isn't working

Comments

@archiewood
Copy link
Member

archiewood commented Jun 7, 2023

Steps To Reproduce

  • Use the Evidence: New Evidence Project command
  • Select a folder that has existing contents

Environment

  • VSCode Extension version (Check in VSCode Marketplace): 1.1.0
  • Node version (node -v): v18.12.1
  • npm version (npm -v): 9.6.4
  • OS: MacOS Ventura

Expected Behavior

It fails and warns you that the file is not empty

Actual Behaviour

It deletes all the files in the directory

Evidence dev server and extension logging output:

Creating new project ...
- New Project Folder: /Users/archie/Projects
- Template Project Folder: /Users/archie/.vscode/extensions/evidence.evidence-vscode-1.1.0/template

Creating project from template ...
- Template Project: /Users/archie/.vscode/extensions/evidence.evidence-vscode-1.1.0/template

✔ New project created successfully.
@archiewood archiewood added bug Something isn't working review Requires additional testing and review and removed review Requires additional testing and review labels Jun 7, 2023
@archiewood
Copy link
Member Author

archiewood commented Jun 7, 2023

Something is going wrong here

export async function createNewProject(projectFolder?: Uri) {
if (!projectFolder) {
const selectedFolders: Uri[] | undefined = await showSelectFolderDialog();
if (!selectedFolders) {
// user cancelled folder selection and new Evidence project creation action
return;
}
else {
// get the first selected folder
projectFolder = selectedFolders[0];
}
}
// get the list of files and folders in the selected new project folder
const projectFiles = await workspace.findFiles(
new RelativePattern(projectFolder.fsPath, '**/*'));
console.log(projectFiles);
// check if the selected folder is empty
if (projectFiles.length > 0 ) {

@hughess
Copy link
Member

hughess commented Jun 7, 2023

Was able to reproduce. The console message I got references that the directory is not empty, but it uses options.force to override it:

CleanShot 2023-06-07 at 10 14 56@2x

@hughess
Copy link
Member

hughess commented Jun 7, 2023

After a bit of debugging, I think what's happening is the check of if(projectFiles.length > 0) is not passing because the results of await workspace.findFiles() haven't been received yet

@RandomFractals
Copy link
Contributor

RandomFractals commented Jun 7, 2023

@hughess both guesses are incorrect.

The scenario @archiewood described requires a check when the default built-in /template added in #62 is used in an open workspace from the Command Palette... and extension creating new project at the root of that open workspace (#48).

See #72 for more info and just add a check if the root open workspace folder has any files using the code snippets you have above before we copy all the files and subfolders from the built-in /template that ships with your extension to the 1st workspace folder in the open workspace. It should be added in the new src/fsUtils.ts/copyFiles() method used to copy template files to the open workspace root folder: https://github.com/evidence-dev/evidence-vscode/blob/main/src/utils/fsUtils.ts#L78 or on this line in that .ts file: https://github.com/evidence-dev/evidence-vscode/blob/main/src/utils/fsUtils.ts#L47

This was a last minute feature we flipped before releasing your v1.1.0 Evidence dev onboarding extension features and enhancements

You should be able to easily patch it and release v1.1.1 patch after bumping your ext. v. in package.json and providing the missing open workspace folder condition for one or both of the described cases (#72 & #62 while using #48 with #2).

We hope the notes shared in this comment will help your resolve this quickly as we move on to our next. 🤗

@archiewood
Copy link
Member Author

archiewood commented Jun 7, 2023

Gif showing test protocol - notice my-test folder contents are wiped and replaced

@hughess notice that console doesn't print the lines about "not empty" in this case

CleanShot 2023-06-07 at 14 33 28

@hughess
Copy link
Member

hughess commented Jun 7, 2023

@RandomFractals closed this for now - the changes fix the specific situation archie and i were running into. It seems like there might be another situation we need to cover as you've described - will open another issue for it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
3 participants