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

fix: move workspaces to Ganache/ui/workspaces #5151

Merged
merged 5 commits into from
Jan 12, 2023

Conversation

jeffsmale90
Copy link
Contributor

This changes the workspaces directory to <config>/Ganache/ui/workspaces in anticipation of all Ganache-UI configuration data being migrated to the <config>Ganache/ui directory. This means that previous versions of Ganache-UI will not have visibility to "new" workspaces.

During the "migration" phase of startup, all workspaces in the "old" location will have symlinks created in the "new" location - meaning that "old" workspaces are available in the "new" version of Ganache-UI.

Deleting workspaces in either version of Ganache-UI will cause the workspace to be deleted for both.

…egacy data being migrated to here. Symlink workspaces from 'old' workspaces directory. Use fs.readdirSync along with 'withFileTypes' to avoid additional 'stat' call.
@jeffsmale90 jeffsmale90 marked this pull request as draft December 14, 2022 22:48
@jeffsmale90 jeffsmale90 changed the title fix: hide "new" workspaces from previous versions of Ganache fix: move workspaces to Ganache/ui/workspaces Dec 14, 2022
Comment on lines -100 to 103
return spawn("cmd.exe", ["/c", "mkdir", path.join(USERDATA_PATH, "workspaces")])
return spawn("cmd.exe", ["/c", "mkdir", path.join(USERDATA_PATH, "ui/workspaces")])
})
.then(()=> {
return spawn("cmd.exe", ["/c", "mkdir", path.join(USERDATA_PATH, "default")])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This magic "spawn" logic is here to ensure that real directories are created (required to be able to execute "extras" [such as postgres] in correct context). It may be removed in a subsequent change.

@jeffsmale90 jeffsmale90 marked this pull request as ready for review December 15, 2022 01:36
Comment on lines +123 to 133
let workspaceDirectory;
if (fse.lstatSync(this.workspaceDirectory).isSymbolicLink()) {
workspaceDirectory = fse.readlinkSync(this.workspaceDirectory);
fse.unlinkSync(this.workspaceDirectory);
} else {
workspaceDirectory = this.workspaceDirectory;
}

try {
fse.removeSync(this.workspaceDirectory);
fse.removeSync(workspaceDirectory);
} catch (e) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first glance this worried me, because we unlink and delete, but we're deleting the symlink, and the directory to which that symlink points.

Comment on lines +38 to +46
if (flavor === "ethereum" || flavor === "filecoin") {
// silently ignore any workspaces that aren't of a supported flavor
const linkPath = join(newWorkspacesDirectory, legacyWorkspace.name);
if (legacyWorkspace.isDirectory() && !await exists(linkPath)) {
return symlink(fullPath, linkPath, "junction");
}
}
} catch {
// silently ignore any workspaces that fail to link
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now silently ignore any workspace that is not ethereum or filecoin, or that fails to parse.

@jeffsmale90 jeffsmale90 merged commit 55865cb into develop Jan 12, 2023
@jeffsmale90 jeffsmale90 deleted the feat/legacy_workspaces branch January 12, 2023 04:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant