diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-07-17 00:18:01 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-07-17 00:18:01 +0000 |
| commit | 7019724ab5c818e18fb5ee61b6b14487c47da3ec (patch) | |
| tree | 0a7d60563c56a75fcfe7ecdd66f21bdc420fc1fa /src/pkg_create.c | |
| parent | 43e35385f741a3c48cf667fd55bc1175d1d2b927 (diff) | |
more features but memory leak
Diffstat (limited to 'src/pkg_create.c')
| -rw-r--r-- | src/pkg_create.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/pkg_create.c b/src/pkg_create.c index de20038..728a955 100644 --- a/src/pkg_create.c +++ b/src/pkg_create.c @@ -7,7 +7,6 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 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 @@ -15,7 +14,6 @@ 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 <string.h> @@ -26,8 +24,11 @@ #include "files.h" #include "globs.h" #include "log.h" +#include "pkgit_lua.h" #include "str.h" +str new_arg_str; + static str get_destdir(str_slc cwd, str_slc arg) { str_slc name = str_slc_from_after_delim(arg, '/'); if (str_slc_first(arg) == '.') @@ -75,29 +76,25 @@ static void assign_pkg_target(package_t *pkg, str *new_arg_str) { if (str_find_char(&pkg->target, '@')) pkg->target.len--; str_free(&tmp_arg); pkg->name.len -= pkg->target.len + 1; + } else if (!flags.verbose) { + pkg->target = mstr("quiet"); } else pkg->target = mstr("default"); } package_t pkg_create(str_slc arg) { package_t pkg = { .is_local = false, }; - char cwd[MAX_PATH_LEN]; getcwd(cwd, MAX_PATH_LEN); str_slc cwd_slc = mstrslc(cwd); str cwd_str = mstr(cwd); str dest_dir = get_destdir(cwd_slc, arg); - str new_arg_str = str_from_str_slc(arg); + str tmp_str = str_from_str_slc(arg); + str_copy_into(&new_arg_str, &tmp_str); + str_free(&tmp_str); bool is_installed_locally = is_directory(dest_dir.data); - - bool is_in_repos = false; - // for (size_t i = 0; i < cached_repos_count; i++) { - // if (strcmp(new_arg, cached_repos[i].source_key) == 0) { - // is_in_repos = true; - // break; - // } - // } + bool is_in_repos = pkg_exists(&new_arg_str); assign_pkg_version(&pkg, &new_arg_str); assign_pkg_target(&pkg, &new_arg_str); @@ -105,12 +102,12 @@ package_t pkg_create(str_slc arg) { str tmp = str_from_after_delim(&new_arg_str, '@'); new_arg_str.len -= tmp.len + 1; str_free(&tmp); - } - if (str_find_char(&new_arg_str, ',')) { + } if (str_find_char(&new_arg_str, ',')) { str tmp = str_from_after_delim(&new_arg_str, ','); new_arg_str.len -= tmp.len + 1; str_free(&tmp); } + if (strncmp(arg.data, "http", 4) == 0 || strncmp(arg.data, "ssh", 3) == 0) { pkg.url = new_arg_str; pkg.name = str_from_after_delim(&new_arg_str, '/'); @@ -119,12 +116,9 @@ package_t pkg_create(str_slc arg) { pkg.name = str_from_after_delim(&cwd_str, '/'); pkg.is_local = true; } else if (is_in_repos) { - // for (size_t i = 0; i < cached_repos_count; i++) { - // if (strcmp(new_arg, cached_repos[i].source_key) == 0) { - // pkg.url = strdup(cached_repos[i].source_value); - // break; - // } - // } + str tmp_url = pkg_get_url(&new_arg_str); + str_copy_into(&pkg.url, &tmp_url); + str_free(&tmp_url); pkg.name = new_arg_str; } else if (is_installed_locally) { pkg.url = mstr(""); @@ -132,12 +126,17 @@ package_t pkg_create(str_slc arg) { pkg.is_local = true; } else { log_error("'%.*s' is not a valid package", str_fmt(&arg)); + str_free(&cwd_str); + str_free(&dest_dir); + str_free(&new_arg_str); exit(EXIT_FAILURE); } + if (str_find_char(&new_arg_str, ',') && str_find_char(&new_arg_str, '@') ) pkg.name.len--; pkg.src = get_pkgsrc(pkg); + str_free(&cwd_str); str_free(&dest_dir); return pkg; |
