Skip to content

Fix 52: "EEXIST:file already exists" raises during creating java project - #61

Merged
Andy Xu(devdiv) (andxu) merged 10 commits into
masterfrom
andy_error_create_project
Oct 17, 2018
Merged

Andy Xu(devdiv) (andxu) merged 10 commits into
masterfrom
andy_error_create_project

Conversation

@andxu

Copy link
Copy Markdown
Contributor

…project, using Promise.all will cause the racing of creating the target folder.

Fix #52

…project, using Promise.all will cause the racing of creating the target folder.
@andxu Andy Xu(devdiv) (andxu) changed the title Fix bug 52: "EEXIST:file already exists" raises during creating java … Fix 52: "EEXIST:file already exists" raises during creating java project Oct 16, 2018
const projectFile: string = path.join(basePath, projectName, ".project");
const extensionPath: string = this.context.extensionPath;
try {
await Promise.all([

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe ensure the directory first and put all the copy work in one Promise.all()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no perf issue copying some small files, so the only concern is about the code cleanness, await Promise.all and the array of the fs operations make the code complex.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Summer (@SummerSun) and disagree with the proposed solution. Promise.all is well known so it does not make things harder to understand. The performance downgrade is definitely noticeable when you work with larger projects. Triggering multiple copy task and let them run in parallel will make the most of modern hardware like SSD. Running them in serial manner does not make any sense.

Comment thread src/controllers/projectController.ts Outdated
fse.copy(path.join(extensionPath, "templates", ".project"), projectFile),
fse.ensureDir(path.join(basePath, projectName, "bin")),
]);
await fse.ensureDir(path.join(basePath, projectName, "bin"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two has very different meanings. The later makes it a serial operation. I don't see a problem with Promise.all. Please keep that one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EEXIST:file already exists error will be thrown and the await Promise.all will reject since the fs operations will all call mkdirs on basePath + projectName

const projectFile: string = path.join(basePath, projectName, ".project");
const extensionPath: string = this.context.extensionPath;
try {
await Promise.all([

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Summer (@SummerSun) and disagree with the proposed solution. Promise.all is well known so it does not make things harder to understand. The performance downgrade is definitely noticeable when you work with larger projects. Triggering multiple copy task and let them run in parallel will make the most of modern hardware like SSD. Running them in serial manner does not make any sense.

Comment thread templates/App.java.sample
}

public static void main(String[] args) throws Exception {
System.out.println("Hello Java");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any change of this code snippet?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing tab with spaces

Comment thread src/controllers/projectController.ts Outdated
const templateRoot: string = path.join(this.context.extensionPath, "templates");
const projectFile: string = path.join(projectRoot, ".project");
try {
fse.ensureDirSync(projectRoot);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread src/controllers/projectController.ts Outdated
const templateRoot: string = path.join(this.context.extensionPath, "templates");
const projectFile: string = path.join(projectRoot, ".project");
try {
fse.ensureDirSync(projectRoot);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just await fse.ensureDir?
A sync operation blocks others especially when there is potential retry logic.

@andxu
Andy Xu(devdiv) (andxu) merged commit c54e52c into master Oct 17, 2018
@andxu
Andy Xu(devdiv) (andxu) deleted the andy_error_create_project branch October 17, 2018 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants