Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for attempting to remove a lib when dev is set #644

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified run.n
Binary file not shown.
8 changes: 6 additions & 2 deletions src/haxelib/api/Repository.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package haxelib.api;

import haxelib.client.Cli;
import haxelib.VersionData.VcsData;
import sys.FileSystem;
import sys.io.File;
Expand Down Expand Up @@ -169,8 +170,8 @@ class Repository {
throw 'Library $name version $version is not installed';

final current = getCurrentFileContent(name);
if (current == version)
throw 'Cannot remove current version of library $name';
if (getDevPath(name) == null && current == version)
throw 'Cannot remove current version of library $name, it\'s set as the current version';

try {
confirmRemovalAgainstDev(name, versionPath);
Expand All @@ -180,6 +181,9 @@ class Repository {
}

FsUtils.deleteRec(versionPath);

var versions = getProjectInstallationInfo(name).versions.pop();
setCurrentVersion(name, versions);
Copy link
Contributor

Choose a reason for hiding this comment

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

We really don't want that. Especially since you're also doing it when removing a version that is not the current version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I was incorrect with this one yes.
The intention was for the case of using a dev version and if you were to remove the current version, it doesn't change anything in the .current file.

If you're on say flixel 5.0.0 (cat flixel/.current -> 5.0.0), begin using a dev directory for flixel, do something like haxelib remove flixel 5.0.0, we want to properly update .current so if you disable the dev, it leads to whatever the most recent directory is versions.pop().

However you're right, my implementation is incorrect since we don't want to remove / set the current version unconditionally!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how does something like

FsUtils.deleteRec(versionPath);
		
if (current == version)
{
	var versions = getProjectInstallationInfo(name).versions.pop();
	setCurrentVersion(name, versions);
}

shake out? Unless I'm still misunderstanding 🙇‍♂️
In this snippet, the code will run if .dev DOES exist (otherwise we would have thrown an error earlier). So if we have a .dev haxelib, and we just removed our .current set haxelib, we update the .current file to the most recent version we have installed. Again, only if we are:

  • uninstalling our "current" version
  • we are using a haxelib dev based haxelib
  • there are other versions installed

}

/** Throws an error if removing `versionPath` conflicts with the dev path of library `name` **/
Expand Down