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

sys: use strstr() to detect installed packages #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ rpc_sys_packagelist(struct ubus_context *ctx, struct ubus_object *obj,
break;
case 'S':
if (is_field("Status", line))
if (sscanf(line, "Status: install %63s installed", tmp) == 1)
installed = true;
installed = !!strstr(line, " installed");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to ensure: this line can't be not installed, right?.
It would be nice to place a comment with a sample string Status: install 3 installed. But that's a minor thing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the other possible strings are half-installed or not-installed with a dash. (Although I've never seen the half- version in the wild, not sure what it does.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, to be completely correct, here's the list (I only cared about the *installed ones above):

static const enum_map_t pkg_state_status_map[] = {
	{SS_NOT_INSTALLED, "not-installed"},
	{SS_UNPACKED, "unpacked"},
	{SS_HALF_CONFIGURED, "half-configured"},
	{SS_INSTALLED, "installed"},
	{SS_HALF_INSTALLED, "half-installed"},
	{SS_CONFIG_FILES, "config-files"},
	{SS_POST_INST_FAILED, "post-inst-failed"},
	{SS_REMOVAL_FAILED, "removal-failed"}
};

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

break;
default:
if (is_blank(line)) {
Expand Down