Skip to content

Commit

Permalink
Merge commit '43ee1c6c1355c92e9d8c96fb97d816fa0d6e9950'
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Jan 22, 2024
2 parents 6a602e7 + 43ee1c6 commit f4a1087
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 98 deletions.
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.list/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MK_MAN= no

LIBADD= mport pthread

LDFLAGS += -L../libmport -lmport -lpthread
LDFLAGS += -L${.CURDIR}/../../libmport -lmport -lpthread

BINDIR=/usr/libexec

Expand Down
84 changes: 27 additions & 57 deletions contrib/mport/libexec/mport.list/mport.list.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#include <unistd.h>
#include <getopt.h>
#include <mport.h>
#include <mport_private.h>

static void usage(void);
static char * str_remove(const char *, const char);

int
main(int argc, char *argv[])
Expand Down Expand Up @@ -134,37 +134,37 @@ main(int argc, char *argv[])
while (*packs != NULL) {
if (update) {
if (mport_index_lookup_pkgname(mport, (*packs)->name, &indexEntries) != MPORT_OK) {
(void) fprintf(stderr, "Error Looking up package name %s: %d %s\n", (*packs)->name, mport_err_code(), mport_err_string());
mport_call_msg_cb(mport, "Error Looking up package name %s: %d %s", (*packs)->name, mport_err_code(), mport_err_string());
exit(mport_err_code());
}

if (indexEntries == NULL || *indexEntries == NULL) {
if (mport_moved_lookup(mport, (*packs)->name, &movedEntries) != MPORT_OK) {
(void) printf("%-25s %8s is not part of the package repository.\n", (*packs)->name, (*packs)->version);
mport_call_msg_cb(mport,"%-25s %8s is not part of the package repository.", (*packs)->name, (*packs)->version);
packs++;
continue;
}

if (movedEntries == NULL || *movedEntries == NULL) {
(void) printf("%-15s %8s is not part of the package repository.\n", (*packs)->name, (*packs)->version);
packs++;
continue;
}
mport_call_msg_cb(mport,"%-15s %8s is not part of the package repository.", (*packs)->name, (*packs)->version);
packs++;
continue;
}

if ((*movedEntries)->moved_to[0]!= '\0') {
(void) printf("%-25s %8s was moved to %s\n", (*packs)->name, (*packs)->version, (*movedEntries)->moved_to);
mport_call_msg_cb(mport,"%-25s %8s was moved to %s", (*packs)->name, (*packs)->version, (*movedEntries)->moved_to);
free(movedEntries);
movedEntries = NULL;
packs++;
continue;
packs++;
continue;
}

if ((*movedEntries)->date[0]!= '\0') {
(void) printf("%-25s %8s expired on %s\n", (*packs)->name, (*packs)->version, (*movedEntries)->date);
mport_call_msg_cb(mport,"%-25s %8s expired on %s", (*packs)->name, (*packs)->version, (*movedEntries)->date);
free(movedEntries);
movedEntries = NULL;
packs++;
continue;
packs++;
continue;
}

free(movedEntries);
Expand All @@ -176,41 +176,39 @@ main(int argc, char *argv[])
if (((*indexEntries)->version != NULL && mport_version_cmp((*packs)->version, (*indexEntries)->version) < 0)
|| ((*packs)->version != NULL && mport_version_cmp((*packs)->os_release, os_release) < 0)) {

if (verbose) {
(void) printf("%-25s %8s (%s) < %-s\n", (*packs)->name, (*packs)->version,
(*packs)->os_release, (*indexEntries)->version);
} else {
(void) printf("%-25s %8s < %-8s\n", (*packs)->name, (*packs)->version,
(*indexEntries)->version);
}
if (verbose) {
mport_call_msg_cb(mport,"%-25s %8s (%s) < %-s", (*packs)->name, (*packs)->version, (*packs)->os_release, (*indexEntries)->version);
} else {
mport_call_msg_cb(mport,"%-25s %8s < %-8s", (*packs)->name, (*packs)->version, (*indexEntries)->version);
}
}
indexEntries++;
}

mport_index_entry_free_vec(iestart);
indexEntries = NULL;
} else if (verbose) {
comment = str_remove((*packs)->comment, '\\');
comment = mport_str_remove((*packs)->comment, '\\');
snprintf(name_version, 30, "%s-%s", (*packs)->name, (*packs)->version);

(void) printf("%-30s\t%6s\t%s\n", name_version, (*packs)->os_release, comment);
mport_call_msg_cb(mport,"%-30s\t%6s\t%s", name_version, (*packs)->os_release, comment);
free(comment);
}
else if (prime && (*packs)->automatic == 0)
(void) printf("%s\n", (*packs)->name);
else if (prime && (*packs)->automatic == 0)
mport_call_msg_cb(mport,"%s", (*packs)->name);
else if (quiet && !origin)
(void) printf("%s\n", (*packs)->name);
mport_call_msg_cb(mport,"%s", (*packs)->name);
else if (quiet && origin)
(void) printf("%s\n", (*packs)->origin);
mport_call_msg_cb(mport,"%s", (*packs)->origin);
else if (origin)
(void) printf("Information for %s-%s:\n\nOrigin:\n%s\n\n",
mport_call_msg_cb(mport,"Information for %s-%s:\n\nOrigin:\n%s\n",
(*packs)->name, (*packs)->version, (*packs)->origin);
else if (locks) {
if ((*packs)->locked == 1)
(void) printf("%s-%s\n", (*packs)->name, (*packs)->version);
mport_call_msg_cb(mport,"%s-%s", (*packs)->name, (*packs)->version);

} else
(void) printf("%s-%s\n", (*packs)->name, (*packs)->version);
mport_call_msg_cb(mport, "%s-%s", (*packs)->name, (*packs)->version);
packs++;
}

Expand All @@ -219,34 +217,6 @@ main(int argc, char *argv[])
return (0);
}


static char *
str_remove( const char *str, const char ch )
{
size_t i;
size_t x;
size_t len;
char *output;

if (str == NULL)
return NULL;

len = strlen(str);

output = calloc(len + 1, sizeof(char));

for (i = 0, x = 0; i <= len; i++) {
if (str[i] != ch) {
output[x] = str[i];
x++;
}
}
output[len] = '\0';

return (output);
}


static void
usage(void)
{
Expand Down
4 changes: 2 additions & 2 deletions contrib/mport/libmport/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ SRCS= asset.c bundle_write.c bundle_read.c plist.c create_primative.c db.c \
update_primative.c bundle_read_update_pkg.c pkgmeta.c \
fetch.c index.c index_depends.c install.c clean.c setting.c \
stats.c update.c upgrade.c verify.c lock.c mkdir.c import_export.c \
autoremove.c audit.c ping.c message.c
autoremove.c audit.c ping.c message.c service.c
INCS= mport.h

CFLAGS+= -I${.CURDIR} -I/usr/include/private/ucl
CFLAGS+= -I${.CURDIR} -I/usr/include/private/ucl -I/usr/include/ucl
SHLIB_MAJOR= 2
MAN= mport.3

Expand Down
23 changes: 19 additions & 4 deletions contrib/mport/libmport/bundle_read_install_pkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ do_pre_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *

(void) strlcpy(cwd, pkg->prefix, sizeof(cwd));

if (mport_chdir(mport, cwd) != MPORT_OK)
goto ERROR;
if (mport_chdir(mport, cwd) != MPORT_OK) {
if (strcmp("/compat/linux", cwd) == 0) {
mport_mkdir("/compat");
mport_mkdir("/compat/linux");
} else {
mport_mkdir(cwd);
}
if (mport_chdir(mport, cwd) != MPORT_OK) {
goto ERROR;
}
}

STAILQ_FOREACH(e, alist, next)
{
Expand Down Expand Up @@ -324,8 +333,8 @@ mport_bundle_read_get_assetlist(mportInstance *mport, mportPackageMeta *pkg, mpo
}
} else if (state == POSTINSTALL) {
if (mport_db_prepare(mport->db, &stmt,
"SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type in (%d, %d, %d, %d, %d, %d)",
pkg->name, ASSET_CWD, ASSET_POSTEXEC, ASSET_LDCONFIG, ASSET_LDCONFIG_LINUX, ASSET_GLIB_SCHEMAS, ASSET_INFO) != MPORT_OK) {
"SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type in (%d, %d, %d, %d, %d, %d, %d)",
pkg->name, ASSET_CWD, ASSET_POSTEXEC, ASSET_LDCONFIG, ASSET_LDCONFIG_LINUX, ASSET_GLIB_SCHEMAS, ASSET_INFO, ASSET_TOUCH) != MPORT_OK) {
sqlite3_finalize(stmt);
RETURN_CURRENT_ERROR;
}
Expand Down Expand Up @@ -854,6 +863,8 @@ do_post_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta
if (run_pkg_install(mport, bundle, pkg, "POST-INSTALL") != MPORT_OK)
RETURN_CURRENT_ERROR;

mport_start_stop_service(mport, pack, SERVICE_START);

return mark_complete(mport, pkg);
}

Expand Down Expand Up @@ -933,6 +944,10 @@ run_postexec(mportInstance *mport, mportPackageMeta *pkg)
goto ERROR;
}
break;
case ASSET_TOUCH:
if (mport_xsystem(mport, "/usr/bin/touch %s", file)!= MPORT_OK) {
goto ERROR;
}
default:
/* do nothing */
break;
Expand Down
24 changes: 21 additions & 3 deletions contrib/mport/libmport/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static int mport_upgrade_master_schema_7to8(sqlite3 *);
static int mport_upgrade_master_schema_8to9(sqlite3 *);
static int mport_upgrade_master_schema_9to10(sqlite3 *);
static int mport_upgrade_master_schema_10to11(sqlite3 *);
static int mport_upgrade_master_schema_11to12(sqlite3 *);

/* mport_db_do(sqlite3 *db, const char *sql, ...)
*
Expand Down Expand Up @@ -281,6 +282,9 @@ mport_upgrade_master_schema(sqlite3 *db, int databaseVersion)
mport_upgrade_master_schema_6to7(db);
mport_upgrade_master_schema_7to8(db);
mport_upgrade_master_schema_8to9(db);
mport_upgrade_master_schema_9to10(db);
mport_upgrade_master_schema_10to11(db);
mport_upgrade_master_schema_11to12(db);
mport_set_database_version(db);
break;
case 2:
Expand All @@ -306,13 +310,15 @@ mport_upgrade_master_schema(sqlite3 *db, int databaseVersion)
case 9:
/* falls through */
mport_upgrade_master_schema_9to10(db);
mport_set_database_version(db);
case 10:
/* falls through */
mport_upgrade_master_schema_10to11(db);
mport_set_database_version(db);
case 11:
break;
/* falls through */
mport_upgrade_master_schema_11to12(db);
mport_set_database_version(db);
case 12:
break;
default:
RETURN_ERROR(MPORT_ERR_FATAL, "Invalid master database version");
}
Expand Down Expand Up @@ -415,6 +421,15 @@ mport_upgrade_master_schema_10to11(sqlite3 *db)
return (MPORT_OK);
}

static int
mport_upgrade_master_schema_11to12(sqlite3 *db)
{
RUN_SQL(db, "INSERT INTO settings VALUES (\"" MPORT_SETTING_HANDLE_RC_SCRIPTS "\", \"yes\")");
RUN_SQL(db, "INSERT INTO settings VALUES (\"" MPORT_SETTING_REPO_AUTOUPDATE "\", \"yes\")");

return (MPORT_OK);
}

int
mport_generate_master_schema(sqlite3 *db)
{
Expand Down Expand Up @@ -443,6 +458,9 @@ mport_generate_master_schema(sqlite3 *db)
RUN_SQL(db, "CREATE TABLE IF NOT EXISTS settings (name text NOT NULL, val text NOT NULL)");
RUN_SQL(db, "CREATE INDEX IF NOT EXISTS settings_name ON settings (name)");

RUN_SQL(db, "INSERT INTO settings VALUES (\"" MPORT_SETTING_HANDLE_RC_SCRIPTS "\", \"yes\")");
RUN_SQL(db, "INSERT INTO settings VALUES (\"" MPORT_SETTING_REPO_AUTOUPDATE "\", \"yes\")");

mport_set_database_version(db);

return (MPORT_OK);
Expand Down
4 changes: 3 additions & 1 deletion contrib/mport/libmport/default_cbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ int mport_default_confirm_cb(const char *msg, const char *yes, const char *no, i
/* user just hit return */
return def == 1 ? MPORT_OK : -1;
}

bool answer = mport_check_answer_bool(ans);

if (*ans == 'Y' || *ans == 'y')
if (answer)
return (MPORT_OK);
if (*ans == 'N' || *ans == 'n')
return (-1);
Expand Down
40 changes: 18 additions & 22 deletions contrib/mport/libmport/delete_primative.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mport_delete_primative(mportInstance *mport, mportPackageMeta *pack, int force)
sqlite3_stmt *stmt;
int ret, current, total;
mportAssetListEntryType type;
const char *data, *checksum, *cwd, *service, *rc_script;
const char *data, *checksum, *cwd;
struct stat st;
char hash[65];

Expand All @@ -69,26 +69,7 @@ mport_delete_primative(mportInstance *mport, mportPackageMeta *pack, int force)

mport_call_progress_init_cb(mport, "Deleting %s-%s", pack->name, pack->version);

/* stop any services that might exist; this replaces @stopdaemon */
if (mport_db_prepare(mport->db, &stmt,
"select * from assets where data like '/usr/local/etc/rc.d/%%' and type=%i and pkg=%Q",
ASSET_FILE, pack->name) != MPORT_OK)
RETURN_CURRENT_ERROR;

while (1) {
ret = sqlite3_step(stmt);
if (ret != SQLITE_ROW) {
break;
}

rc_script = sqlite3_column_text(stmt, 0);
if (rc_script == NULL)
continue;
service = basename((char *)rc_script);
if (mport_xsystem(mport, "/usr/sbin/service %s onestop", service) != 0) {
mport_call_msg_cb(mport, "Unable to stop service %s\n", service);
}
}
mport_start_stop_service(mport, pack, SERVICE_STOP);

/* get the file count for the progress meter */
if (mport_db_prepare(mport->db, &stmt,
Expand Down Expand Up @@ -293,6 +274,7 @@ mport_delete_primative(mportInstance *mport, mportPackageMeta *pack, int force)
case ASSET_DIRRMTRY:
case ASSET_DIR_OWNER_MODE:
if (is_safe_to_delete_dir(mport, pack, file)) {
mport_removeflags(mport->root, file);
if (mport_rmdir(file, type == ASSET_DIRRMTRY ? 1 : 0) != MPORT_OK) {
mport_call_msg_cb(mport, "Could not remove directory '%s': %s",
file, mport_err_string());
Expand Down Expand Up @@ -358,11 +340,25 @@ bool is_safe_to_delete_dir(mportInstance *mport, mportPackageMeta *pack, const c
{
sqlite3_stmt *stmt;
int count;

if (mport == NULL || pack == NULL || path == NULL) {
return false;
}

/* Don't delete the root or the package prefix directories */
if (mport->root != NULL && strcmp(mport->root, path) == 0) {
mport_call_msg_cb(mport, "Skipping removal of root (DESTDIR) directory: '%s'", path);
return false;
}
if (pack->prefix != NULL && strcmp(pack->prefix, path) == 0) {
mport_call_msg_cb(mport, "Skipping removal of package prefix directory: '%s'", path);
return false;
}

if (mport_db_prepare(mport->db, &stmt,
"SELECT count(*) from assets where pkg!=%Q and type in (%d, %d, %d, %d) and data=%Q",
pack->name, ASSET_DIR, ASSET_DIRRM, ASSET_DIRRMTRY, ASSET_DIR_OWNER_MODE, path) != MPORT_OK) {
RETURN_CURRENT_ERROR;
return false;
}

switch (sqlite3_step(stmt)) {
Expand Down
2 changes: 2 additions & 0 deletions contrib/mport/libmport/mport.3
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ If the proxy is an FTP proxy,
.It Ev ASSUME_ALWAYS_YES
If set to a non empty value, will assume any question should be answered
with a yes.
.It Ev HANDLE_RC_SCRIPTS
If set to a non empty value, will start/stop rc.d scripts included in the package.
.Sh SEE ALSO
.Xr mport 1 ,
.Xr mports 7
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libmport/mport.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ enum _AssetListEntryType {
ASSET_FILE_OWNER_MODE, ASSET_DIR_OWNER_MODE,
ASSET_SAMPLE_OWNER_MODE, ASSET_LDCONFIG, ASSET_LDCONFIG_LINUX,
ASSET_RMEMPTY, ASSET_GLIB_SCHEMAS, ASSET_KLD, ASSET_DESKTOP_FILE_UTILS,
ASSET_INFO
ASSET_INFO, ASSET_TOUCH
};

typedef enum _AssetListEntryType mportAssetListEntryType;
Expand Down
Loading

0 comments on commit f4a1087

Please sign in to comment.