-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ccrma/chump
# Please enter …
…a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
- Loading branch information
Showing
15 changed files
with
239 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "uninstaller.h" | ||
#include "util.h" | ||
|
||
Uninstaller::Uninstaller(PackageList* pkg_list) { | ||
package_list = pkg_list; | ||
} | ||
|
||
bool Uninstaller::uninstall(std::string package_name) { | ||
// lookup package name (default to latest version) | ||
auto pkg = package_list->lookup(package_name); | ||
|
||
if (!pkg) { | ||
std::cerr << "BADBADBAD" << std::endl; | ||
return false; | ||
} | ||
|
||
auto package = pkg.value(); | ||
|
||
fs::path package_dir = packagePath(package); | ||
|
||
// validate that it's actually a directory | ||
if (!fs::exists(package_dir) || !fs::is_directory(package_dir)) { | ||
std::cerr << "Package " << package.name << " was not found." << std::endl; | ||
return false; | ||
} | ||
|
||
std::string os = whichOS(); | ||
|
||
// only delete files that chump knows about | ||
for (auto file: package.files[os]) { | ||
fs::path filename = fs::path(file).filename(); | ||
|
||
fs::path filepath = package_dir / filename; | ||
|
||
if (!fs::remove(filepath)) { | ||
std::cerr << "File " << filepath << " not found." << std::endl; | ||
} | ||
} | ||
|
||
// If the package directory still has files, don't remove it. | ||
if (!fs::remove(package_dir)) { | ||
std::cerr << "Directory " << package_dir << " not removed." << std::endl; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef __UNINSTALLER_H__ | ||
#define __UNINSTALLER_H__ | ||
|
||
#include "package.h" | ||
#include "package_list.h" | ||
|
||
using std::optional; | ||
|
||
namespace fs = std::filesystem; | ||
|
||
// Abstract base class | ||
class UninstallerBase { | ||
public: | ||
virtual ~UninstallerBase() = default; | ||
virtual bool uninstall(std::string package_name) = 0; | ||
}; | ||
|
||
|
||
class Uninstaller : public UninstallerBase { | ||
public: | ||
Uninstaller(PackageList* package_list); | ||
|
||
public: | ||
bool uninstall(std::string package_name); | ||
|
||
private: | ||
PackageList* package_list; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "util.h" | ||
|
||
// Returns the path to the directory where a package will be installed | ||
fs::path packagePath(Package p) { | ||
const char* env_p = std::getenv("HOME"); | ||
fs::path home = fs::path(env_p); | ||
fs::path package_dir = home / ".chuck/lib" / p.name; | ||
|
||
return package_dir; | ||
} | ||
|
||
std::string whichOS() { | ||
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) | ||
return "windows"; | ||
#elif defined(__APPLE__) | ||
return "mac"; | ||
#elif defined(__linux__) | ||
return "linux"; | ||
#else | ||
std::cerr << "Unknown operating system" << std::endl; | ||
return ""; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef __UTIL_H__ | ||
#define __UTIL_H__ | ||
|
||
#include "package.h" | ||
|
||
namespace fs = std::filesystem; | ||
|
||
fs::path packagePath(Package p); | ||
|
||
std::string whichOS(); | ||
|
||
#endif |