mpm

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

commit 38e01e370867ca25df90c4b0882953f3a1a1075a
parent 9bac3c442f5ab7fd90cfc14ace2de1f8845ca856
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 13 Oct 2015 04:56:39 +0200

Fix(Exec): Fix cast problems on i386 systems

Diffstat:
Minc/Download.hpp | 2+-
Minc/Exec.hpp | 3+--
Minc/Package.hpp | 2++
Msrc/Download.cpp | 8+++++---
Msrc/Exec.cpp | 21++++++---------------
Msrc/Package.cpp | 18++++++++++++------
Msrc/main.cpp | 2++
7 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/inc/Download.hpp b/inc/Download.hpp @@ -7,7 +7,7 @@ #ifndef __DOWNLOAD__ # define __DOWNLOAD__ -# define BASE_URL 127.0.0.1 +# define BASE_URL "http://api.morphux.org/" # include <list> # include <iostream> diff --git a/inc/Exec.hpp b/inc/Exec.hpp @@ -9,6 +9,7 @@ # include <stdlib.h> # include <string> +# include <string.h> # include <sys/stat.h> # include <sys/types.h> # include <sys/wait.h> @@ -28,8 +29,6 @@ class Exec { void execute(std::list<std::string> args); private: - const char **_listToArray(std::list<std::string> args); - std::list<std::string> _path; }; diff --git a/inc/Package.hpp b/inc/Package.hpp @@ -48,6 +48,7 @@ class Package { std::string getVersion(void); std::string getName(void); std::string getUrl(void); + std::string getError(void); std::list<std::string> getNeededDeps(void); std::list<std::string> getOptionnalDeps(void); float getSize(void); @@ -61,6 +62,7 @@ class Package { float _size; std::string _archive; std::string _dir; + std::string _error; std::list<std::string> _neededDeps; std::list<std::string> _optDeps; int _toDownload; diff --git a/src/Download.cpp b/src/Download.cpp @@ -36,10 +36,9 @@ std::string Download::_getPackagesInfo(std::string url) { CURLcode res; std::string result; - (void)url; curl = curl_easy_init(); if (curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1/response.json"); + curl_easy_setopt(curl, CURLOPT_URL, std::string(BASE_URL + std::string("get/") + url).c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Download::_curlCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result); res = curl_easy_perform(curl); @@ -80,7 +79,10 @@ void Download::_addPackage(std::string name) { return ; p = new Package(name, this->_response[name]); if (p->getToInstall()) { - Error::warning("Package " + name + " already installed, skipping it"); + if (p->getError() == "") + Error::warning("Package " + name + " already installed, skipping it"); + else + Error::warning("Package " + name + " can not be found, skipping it"); delete p; return ; } else if (!p->getToDownload()) { diff --git a/src/Exec.cpp b/src/Exec.cpp @@ -8,6 +8,7 @@ extern char **environ; + Exec::Exec(void) { this->_path = split(std::string(getenv("PATH")), ':'); // Need to add this by-hand, for local binaries @@ -20,8 +21,8 @@ Exec::~Exec(void) { void Exec::execute(std::list<std::string> args) { struct stat buffer; - const char **execArguments; - int pid, status, fd; + const char *execArguments[1024]; + int pid, status, fd, i; std::list<std::string>::iterator it; for (it = this->_path.begin(); it != this->_path.end(); it++) { @@ -31,7 +32,9 @@ void Exec::execute(std::list<std::string> args) { if (it == this->_path.end()) Error::error("The program " + args.front() + " can't be found."); *(args.begin()) = *it + "/" + args.front(); - execArguments = this->_listToArray(args); + for (i = 0, it = args.begin(); (size_t)i < args.size(); i++, it++) + execArguments[i] = strdup((*it).c_str()); + execArguments[i] = NULL; fd = open("/var/log/mpm.log", O_WRONLY | O_APPEND | O_CREAT, 0444); Error::log("========================[ " + args.front() + " ]========================\n"); if (!(pid = fork())) { @@ -48,15 +51,3 @@ void Exec::execute(std::list<std::string> args) { Error::error("Execution error"); } } - -const char **Exec::_listToArray(std::list<std::string> args) { - const char **ret; - int i; - std::list<std::string>::iterator it; - - ret = (const char **)malloc(sizeof(char *) * args.size() + 1); - for (i = 0, it = args.begin(); (size_t)i < args.size(); i++, it++) - ret[i] = (*it).c_str(); - ret[i] = NULL; - return ret; -} diff --git a/src/Package.cpp b/src/Package.cpp @@ -6,22 +6,27 @@ # include "Package.hpp" -Package::Package(std::string name, Json::Value init) : _name(name), _toDownload(0), _toInstall(0) { +Package::Package(std::string name, Json::Value init) : _name(name), _error(""), _toDownload(0), _toInstall(0) { Json::ValueIterator it; std::string path; struct stat buffer; int i; + if (init.isMember("Error")) { + this->_toInstall = 1; + this->_error = init["Error"].asString(); + return ; + } path = "/etc/mpm/packages/" + std::string(1, name[0]) + "/" + name; if (!(stat(path.c_str(), &buffer))) this->_toInstall = 1; this->_version = init["version"].asString(); this->_size = init["size"].asFloat(); this->_packageUrl = init["package"].asString(); - for (it = init["dependencies"]["needed"].begin(); it != init["dependencies"]["needed"].end(); it++) - this->_neededDeps.push_back(it->asString()); - for (it = init["dependencies"]["optionnal"].begin(); it != init["dependencies"]["optionnal"].end(); it++) - this->_optDeps.push_back(it->asString()); + /* for (it = init["dependencies"]["needed"].begin(); it != init["dependencies"]["needed"].end(); it++)*/ + //this->_neededDeps.push_back(it->asString()); + //for (it = init["dependencies"]["optionnal"].begin(); it != init["dependencies"]["optionnal"].end(); it++) + /*this->_optDeps.push_back(it->asString());*/ for (i = this->_packageUrl.length() - 1; i > 0 && this->_packageUrl[i - 1] != '/'; i--); path = "/tmp/" + this->_packageUrl.substr(i, this->_packageUrl.length() - i); if (!(stat(path.c_str(), &buffer))) { @@ -67,7 +72,7 @@ void Package::decompress(void) { struct archive_entry *entry; int fd, r, i; size_t size; - # ifdef __i383__ + # ifdef __i386__ long long int offset; # else off_t offset; @@ -256,6 +261,7 @@ void Package::setExec(Exec *e) { this->_exec = e; }; std::string Package::getVersion(void) { return this->_version; }; std::string Package::getName(void) { return this->_name; }; std::string Package::getUrl(void) { return this->_packageUrl; }; +std::string Package::getError(void) { return this->_error; }; std::list<std::string> Package::getNeededDeps(void) { return this->_neededDeps; }; std::list<std::string> Package::getOptionnalDeps(void) { return this->_optDeps; }; float Package::getSize(void) { return this->_size; }; diff --git a/src/main.cpp b/src/main.cpp @@ -36,6 +36,8 @@ void execute(void) { Options::args.remove(*(Options::args.begin())); if (cmd == "install") { + if (getuid()) + Error::error("Installation needs to be launch as root !"); Download *d = new Download(Options::args); d->getAllPackages(); d->installAll();