mpm

morphux package manager
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/mpm

commit 45889c900067a9b6ac0b4f8f4b742c2461e75876
parent ddcb20bf1dec761eca7dc69822a7bf42b8dec507
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 13 Dec 2015 20:32:41 +0000

Add(Developer Interface):

You can create a basic morphux package with `mpm create package-version
url.tar`

Diffstat:
Minc/Download.hpp | 2++
Asrc/Developer.cpp | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/Download.cpp | 6+++++-
Msrc/Makefile.am | 3++-
Msrc/Package.cpp | 16+++++++++-------
Msrc/main.cpp | 5+++++
6 files changed, 127 insertions(+), 9 deletions(-)

diff --git a/inc/Download.hpp b/inc/Download.hpp @@ -20,9 +20,11 @@ # include "Error.hpp" # include "Package.hpp" # include "Exec.hpp" +# include "Developer.hpp" class Download { public: + Download(void); Download(std::list<std::string>); Download(std::string); ~Download(void); diff --git a/src/Developer.cpp b/src/Developer.cpp @@ -0,0 +1,104 @@ +/* + * Developer.cpp + * By: Louis Solofrizzo <louis@ne02ptzero.me> + * 2015-13-12 19:17 + */ + +#include "Developer.hpp" + +Developer::Developer(void) { + return ; +} + +Developer::~Developer(void) { + return ; +} + +void Developer::createPackage(std::list<std::string> lst) { + std::list<std::string>::iterator it = lst.begin(); + std::string path, archive, name = *it++, url = *it; + std::ofstream file; + + mkdir(name.c_str(), 0775); + chdir(name.c_str()); + path = this->getArchive(url); + archive = this->extract(path); + rename(archive.c_str(), "srcs"); + file.open("package.json"); + file << BASIC_FILE << std::endl; + file.close(); + remove(path.c_str()); +} + +std::string Developer::getArchive(std::string url) { + int i; + std::string path; + CURL *curl; + CURLcode res; + FILE *fd; + + for (i = url.length() - 1; i > 0 && url[i - 1] != '/'; i--); + path = url.substr(i, url.length() - i); + fd = fopen(path.c_str(), "wb"); + curl = curl_easy_init(); + if (curl) { + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, fd); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); + res = curl_easy_perform(curl); + if (fd) + fclose(fd); + if (res != CURLE_OK) { + std::cout << std::endl; + Error::warning(curl_easy_strerror(res)); + Error::error("Download failed."); + } + curl_easy_cleanup(curl); + } else { + Error::error("Can not initialize curl"); + } + return path; +} + +std::string Developer::extract(std::string archive) { + struct archive *a, *ext; + struct archive_entry *entry; + int fd, r, i; + size_t size; + # ifdef __i386__ + long long int offset; + # else + off_t offset; + #endif + const void *buff; + std::string path, dir; + + Error::info("Extracting " + archive); + a = archive_read_new(); + ext = archive_write_disk_new(); + archive_write_disk_set_options(ext, ARCHIVE_EXTRACT_TIME); + archive_read_support_format_all(a); + archive_read_support_filter_all(a); + if ((fd = archive_read_open_filename(a, archive.c_str(), 10240))) + Error::error(std::string(archive_error_string(a))); + fd = archive_read_next_header(a, &entry); + for (i = 0, path = "./"; fd != ARCHIVE_EOF; fd = archive_read_next_header(a, &entry), path = "./", i++) { + if (fd != ARCHIVE_OK) + Error::error(std::string(archive_error_string(a))); + path += std::string(archive_entry_pathname(entry)); + if (i == 0) + dir = path; + archive_entry_set_pathname(entry, path.c_str()); + fd = archive_write_header(ext, entry); + if (fd != ARCHIVE_OK) { + Error::warning(std::string(archive_error_string(a))); + } else { + for (r = ARCHIVE_OK; r != ARCHIVE_EOF && r == ARCHIVE_OK; r = archive_read_data_block(a, &buff, &size, &offset)) + r = archive_write_data_block(ext, buff, size, offset); + if (r != ARCHIVE_OK && r != ARCHIVE_EOF) + Error::warning(std::string(archive_error_string(ext))); + fd = archive_write_finish_entry(ext); + } + } + return dir; +} diff --git a/src/Download.cpp b/src/Download.cpp @@ -6,6 +6,10 @@ #include "Download.hpp" +Download::Download(void) { + return ; +} + Download::Download(std::list<std::string> pack) : _packages(pack) { if (this->_packages.size() > 0) this->_getInfo(); @@ -129,7 +133,7 @@ void Download::_addPackage(std::string name) { this->_addPackage(*it); } this->_packTreated.push_back(p); - this->_packList.push_front(p); + this->_packList.push_back(p); } size_t Download::_curlCallback(void *contents, size_t size, size_t nmemb, void *userp) { diff --git a/src/Makefile.am b/src/Makefile.am @@ -7,6 +7,7 @@ mpm_SOURCES = Download.cpp \ Manager.cpp \ Options.cpp \ Package.cpp \ - jsoncpp.cpp + jsoncpp.cpp \ + Developer.cpp AM_CXXFLAGS = -Wall -Wextra -Werror -std=c++0x -g -I../inc/ mpm_LDADD = -lcurl -larchive diff --git a/src/Package.cpp b/src/Package.cpp @@ -85,8 +85,10 @@ void Package::install(void) { chdir("srcs/"); this->make(); this->minstall(); - if (this->_infos["compilation"]["after"].size()) + if (this->_infos["compilation"]["after"].size()) { + chdir(".."); this->after(); + } this->save(); this->clean(); @@ -96,15 +98,15 @@ void Package::install(void) { void Package::decompress(void) { struct archive *a, *ext; struct archive_entry *entry; - int fd, r, i; - size_t size; + int fd, r, i; + size_t size; # ifdef __i386__ - long long int offset; + long long int offset; # else - off_t offset; + off_t offset; #endif - const void *buff; - std::string path; + const void *buff; + std::string path; Error::info("Extracting " + this->_archive); a = archive_read_new(); diff --git a/src/main.cpp b/src/main.cpp @@ -47,6 +47,11 @@ void execute(void) { } else if (cmd == "test") { Download *d = new Download(Options::args.front()); d->installAll(); + } else if (cmd == "create") { + Developer *d = new Developer(); + if (Options::args.size() != 2) + Error::error("Create usage <package> <url>"); + d->createPackage(Options::args); } else { Error::error("Unknown action: " + cmd); }