Skip to content

Commit

Permalink
add cloning to CLI, fix install state on OSC packages, fix ZipUtils o…
Browse files Browse the repository at this point in the history
…n mac
  • Loading branch information
vgmoose committed Nov 25, 2023
1 parent 1b03f12 commit d2a6911
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
12 changes: 10 additions & 2 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char** args)
// list available remote packages
printf("--> Listing available remotes and packages\n");

printf("%d repo%s loaded!\n", repos.size(), plural(repos.size()));
printf("%zu repo%s loaded!\n", repos.size(), plural(repos.size()));
int enabledCount = 0;
for (int x = 0; x < repos.size(); x++) {
printf("\t%s\n", repos[x]->toString().c_str());
Expand All @@ -75,7 +75,7 @@ int main(int argc, char** args)
break;
}

printf("%d package%s available!\n", packages.size(), plural(packages.size()));
printf("%zu package%s available!\n", packages.size(), plural(packages.size()));
for (int x = 0; x < packages.size(); x++)
printf("\t%s %s\n", packages[x]->statusString(), packages[x]->toString().c_str());

Expand All @@ -97,6 +97,14 @@ int main(int argc, char** args)
repos = get.getRepos();
packages = get.getPackages();
}
else if (cur == "-c" || cur == "--clone") {
// download all packages directly (TODO: save repo json)
printf("--> Cloning all packages...\n");
for (auto & cur_package: packages) {
get.install(*cur_package);
}
printf("--> Cloned %zu packages!\n", packages.size());
}
else // assume argument is a package
{
// try to find the package in a local repo
Expand Down
14 changes: 12 additions & 2 deletions src/Package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,22 @@ bool Package::install(const std::string& pkg_path, const std::string& tmp_path)
#ifndef NETWORK_MOCK
printf("--> Manifest invalid/doesn't exist but recoverable, generating pseudo-manifest\n");
this->manifest = Manifest(HomebrewZip.PathDump(), ROOT_PATH);

// write the pseudo-manifest to the internal package .get directory
mkpath((pkg_path + this->pkg_name).c_str());

std::ofstream pseudomanifest(ManifestPath);
for (const auto& entry : manifest.getEntries())
{
printf("--> Writing pseudo-manifest to %s\n", ManifestPath.c_str());
for (const auto& entry : manifest.getEntries()) {
pseudomanifest << entry.raw << std::endl;
}
pseudomanifest.close();

// write a pseudo-info.json here too
// TODO: load other attributes from the package, besides version
std::ofstream pseudojson(jsonPath);
pseudojson << "{\"version\":\"" << this->version << "\"}" << std::endl;
pseudojson.close();
#endif
}

Expand Down
13 changes: 12 additions & 1 deletion src/ZipUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <cstdint>
#include <dirent.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdlib.h>
#include <memory>
#include <optional>
#include <stdio.h>
Expand All @@ -26,6 +26,17 @@
#define cross_free free
#endif

// on macos, wrap posix_memalign
// https://stackoverflow.com/a/45182325/4953343
#ifdef __APPLE__
void *memalign(size_t blocksize, size_t bytes)
{
void *m;
errno = posix_memalign(&m, blocksize, bytes);
return errno ? NULL : m;
}
#endif

// void info(const char* format, ...);

Zip::Zip(const std::string& zipPath)
Expand Down

0 comments on commit d2a6911

Please sign in to comment.