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

Refactor, update, remove-repo #2

Merged
merged 9 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions compile_flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
-std=c11
-DHTMC_CGI_INTF
-DEXT_TARMAN_BUILD="\"PLACEHOLDER\""
-xc
3 changes: 0 additions & 3 deletions include/archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,3 @@

bool archive_tar_extract(const char *dst, const char *src);
bool archive_extract(const char *dst, const char *src, const char *file_type);
bool archive_dycreate(const char **archive_path,
const char *filename,
const char *filetype);
7 changes: 5 additions & 2 deletions include/package.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ typedef struct {
bool add_to_tarman;
} recipe_t;

// "Runtime" recepie
// "Runtime" recipe
typedef struct {
recipe_t recepie;
recipe_t recipe;
const char *pkg_name;
bool is_remote;
} rt_recipe_t;
Expand All @@ -58,3 +58,6 @@ cfg_parse_status_t pkg_parse_tmrcp(recipe_t *rcp, const char *rcp_file_path);

bool pkg_dump_frcp(FILE *fp, recipe_t recipe);
bool pkg_dump_rcp(const char *file_path, recipe_t recipe);

void pkg_free_pkg(pkg_info_t pkg_info);
void pkg_free_rcp(recipe_t recipe);
27 changes: 27 additions & 0 deletions include/util/misc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*************************************************************************
| tarman |
| Copyright (C) 2024 Alessandro Salerno |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program. If not, see <https://www.gnu.org/licenses/>. |
*************************************************************************/

#include <stdlib.h>

size_t util_misc_dyfile(char **dst,
const char *base_path,
const char *filename,
const char *filetype);

size_t
util_misc_dytmpfile(char **dst, const char *filename, const char *filetype);
61 changes: 61 additions & 0 deletions include/util/pkg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*************************************************************************
| tarman |
| Copyright (C) 2024 Alessandro Salerno |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program. If not, see <https://www.gnu.org/licenses/>. |
*************************************************************************/

#pragma once

#include <stdbool.h>

#include "package.h"

#define LOG_ON true
#define LOG_QUIET false

#define INPUT_ON true
#define INPUT_OFF false

bool util_pkg_fetch_archive(char **dst_file,
const char *pkg_name,
const char *pkg_fmt,
const char *url,
bool log);
bool util_pkg_create_directory_from_path(const char *path, bool log, bool in);
bool util_pkg_create_directory(char **path,
const char *pkg_name,
bool log,
bool in);
bool util_pkg_add_to_path(const char *exec_full_path, bool log);
bool util_pkg_add_to_desktop(const char *pkg_path,
const char *app_name,
const char *exec_full_path,
const char *wrk_dir,
const char *icon,
bool log);
bool util_pkg_parse_config(pkg_info_t *pkg,
char **cfg_path,
const char *pkg_path,
bool log);
bool util_pkg_load_config(pkg_info_t *pkg, const char *pkg_path, bool log);
bool util_pkg_parse_recipe(recipe_t *recipe,
char **rcp_path,
const char *repo,
const char *rcp_name,
bool log);
bool util_pkg_load_recipe(recipe_t *recipe,
const char *repo,
const char *rcp_name,
bool log);
21 changes: 0 additions & 21 deletions src/common/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,3 @@ bool archive_extract(const char *dst, const char *src, const char *file_type) {

return false;
}

bool archive_dycreate(const char **archive_path,
const char *filename,
const char *filetype) {
bool ret = false;

size_t bufsz = strlen(filename) + 1 + strlen(filetype) + 1;
char *repo_fname = (char *)malloc(bufsz * sizeof(char));
mem_chkoom(repo_fname);
snprintf(repo_fname, bufsz, "%s.%s", filename, filetype);

if (0 == os_fs_tm_dycached((char **)archive_path, repo_fname)) {
goto cleanup;
}

ret = true;

cleanup:
mem_safe_free(repo_fname);
return ret;
}
14 changes: 4 additions & 10 deletions src/common/cli/directives/commands/add-repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
#include "download.h"
#include "os/fs.h"
#include "tm-mem.h"
#include "util/misc.h"

int cli_cmd_add_repo(cli_info_t info) {
if (NULL == info.input) {
cli_out_error("Must specify a package to install'");
return EXIT_FAILURE;
}

const char *archive_path = NULL;
char *archive_path = NULL;
const char *repo_url = info.input;
const char *repo_fmt = info.pkg_fmt;
const char *repos_path = NULL;
Expand All @@ -46,21 +47,14 @@ int cli_cmd_add_repo(cli_info_t info) {
goto cleanup;
}

if (0 == os_fs_tm_dyrepos((char **)&repos_path)) {
cli_out_error("Unable to determine path to repos directory");
goto cleanup;
}
os_fs_tm_dyrepos((char **)&repos_path);

if (NULL == repo_fmt) {
cli_out_warning("Repository format not specified, using 'tar.gz'");
repo_fmt = "tar.gz";
}

if (!archive_dycreate(&archive_path, "__downloaded_repo", repo_fmt)) {
cli_out_error("Unable to determine path to temporary archive");
goto cleanup;
}

util_misc_dytmpfile(&archive_path, "__downloaded_repo", repo_fmt);
cli_out_progress("Fetching repository from '%s'", repo_url);

if (!download(archive_path, repo_url)) {
Expand Down
Loading