Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
apk-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
14
Merge Requests
14
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpine
apk-tools
Commits
fe41ae07
Commit
fe41ae07
authored
Jun 18, 2013
by
Timo Teräs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apk: use string array in applet mains, separate apk_name_foreach_matching
parent
c51d82f8
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
284 additions
and
214 deletions
+284
-214
src/add.c
src/add.c
+9
-8
src/apk.c
src/apk.c
+6
-1
src/apk_applet.h
src/apk_applet.h
+1
-1
src/apk_database.h
src/apk_database.h
+11
-2
src/audit.c
src/audit.c
+22
-21
src/cache.c
src/cache.c
+7
-6
src/database.c
src/database.c
+77
-0
src/del.c
src/del.c
+13
-11
src/dot.c
src/dot.c
+5
-5
src/fetch.c
src/fetch.c
+7
-6
src/fix.c
src/fix.c
+8
-7
src/index.c
src/index.c
+11
-10
src/info.c
src/info.c
+37
-47
src/package.c
src/package.c
+9
-6
src/search.c
src/search.c
+27
-53
src/update.c
src/update.c
+1
-1
src/upgrade.c
src/upgrade.c
+1
-1
src/ver.c
src/ver.c
+23
-20
src/verify.c
src/verify.c
+9
-8
No files found.
src/add.c
View file @
fe41ae07
...
...
@@ -58,13 +58,14 @@ static int non_repository_check(struct apk_database *db)
return
1
;
}
static
int
add_main
(
void
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
add_main
(
void
*
ctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
struct
add_ctx
*
actx
=
(
struct
add_ctx
*
)
ctx
;
struct
apk_package
*
virtpkg
=
NULL
;
struct
apk_dependency
virtdep
;
struct
apk_dependency_array
*
world
=
NULL
;
int
i
,
r
=
0
;
char
**
parg
;
int
r
=
0
;
apk_dependency_array_copy
(
&
world
,
db
->
world
);
...
...
@@ -96,10 +97,10 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
virtpkg
=
apk_db_pkg_add
(
db
,
virtpkg
);
}
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
each_array_item
(
parg
,
args
)
{
struct
apk_dependency
dep
;
if
(
strstr
(
argv
[
i
]
,
".apk"
)
!=
NULL
)
{
if
(
strstr
(
*
parg
,
".apk"
)
!=
NULL
)
{
struct
apk_package
*
pkg
=
NULL
;
struct
apk_sign_ctx
sctx
;
...
...
@@ -108,20 +109,20 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
apk_sign_ctx_init
(
&
sctx
,
APK_SIGN_VERIFY_AND_GENERATE
,
NULL
,
db
->
keys_fd
);
r
=
apk_pkg_read
(
db
,
argv
[
i
]
,
&
sctx
,
&
pkg
);
r
=
apk_pkg_read
(
db
,
*
parg
,
&
sctx
,
&
pkg
);
apk_sign_ctx_free
(
&
sctx
);
if
(
r
!=
0
)
{
apk_error
(
"%s: %s"
,
argv
[
i
]
,
apk_error_str
(
r
));
apk_error
(
"%s: %s"
,
*
parg
,
apk_error_str
(
r
));
return
-
1
;
}
apk_dep_from_pkg
(
&
dep
,
db
,
pkg
);
}
else
{
apk_blob_t
b
=
APK_BLOB_STR
(
argv
[
i
]
);
apk_blob_t
b
=
APK_BLOB_STR
(
*
parg
);
apk_blob_pull_dep
(
&
b
,
db
,
&
dep
);
if
(
APK_BLOB_IS_NULL
(
b
)
||
b
.
len
>
0
)
{
apk_error
(
"'%s' is not a valid dependency, format is name(@tag)([<>=]version)"
,
argv
[
i
]
);
*
parg
);
return
-
1
;
}
}
...
...
src/apk.c
View file @
fe41ae07
...
...
@@ -291,6 +291,7 @@ int main(int argc, char **argv)
struct
apk_repository_list
*
repo
=
NULL
;
struct
apk_database
db
;
struct
apk_db_options
dbopts
;
struct
apk_string_array
*
args
;
#ifdef TEST_MODE
const
char
*
test_installed_db
=
NULL
;
const
char
*
test_world
=
NULL
;
...
...
@@ -495,7 +496,11 @@ int main(int argc, char **argv)
}
#endif
r
=
applet
->
main
(
ctx
,
&
db
,
argc
,
argv
);
apk_string_array_init
(
&
args
);
apk_string_array_resize
(
&
args
,
argc
);
memcpy
(
args
->
item
,
argv
,
argc
*
sizeof
(
*
argv
));
r
=
applet
->
main
(
ctx
,
&
db
,
args
);
apk_db_close
(
&
db
);
if
(
r
==
-
EINVAL
)
...
...
src/apk_applet.h
View file @
fe41ae07
...
...
@@ -36,7 +36,7 @@ struct apk_applet {
int
(
*
parse
)(
void
*
ctx
,
struct
apk_db_options
*
dbopts
,
int
optch
,
int
optindex
,
const
char
*
optarg
);
int
(
*
main
)(
void
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
);
int
(
*
main
)(
void
*
ctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
);
};
extern
struct
apk_applet
*
__start_apkapplets
,
*
__stop_apkapplets
;
...
...
src/apk_database.h
View file @
fe41ae07
...
...
@@ -90,8 +90,13 @@ struct apk_name {
union
{
struct
apk_solver_name_state
ss
;
void
*
state_ptr
;
int
state_int
;
struct
{
unsigned
int
foreach_genid
;
union
{
void
*
state_ptr
;
int
state_int
;
};
};
};
};
...
...
@@ -239,4 +244,8 @@ int apk_db_install_pkg(struct apk_database *db,
struct
apk_package
*
newpkg
,
apk_progress_cb
cb
,
void
*
cb_ctx
);
void
apk_name_foreach_matching
(
struct
apk_database
*
db
,
struct
apk_string_array
*
filter
,
unsigned
int
match
,
void
(
*
cb
)(
struct
apk_database
*
db
,
const
char
*
match
,
struct
apk_name
*
name
,
void
*
ctx
),
void
*
ctx
);
#endif
src/audit.c
View file @
fe41ae07
...
...
@@ -236,39 +236,40 @@ done:
return
reason
<
0
?
reason
:
0
;
}
static
int
audit_main
(
void
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
audit_main
(
void
*
ctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
struct
audit_tree_ctx
atctx
;
int
i
,
r
=
0
;
char
**
parg
,
*
arg
;
int
r
=
0
;
atctx
.
db
=
db
;
atctx
.
actx
=
(
struct
audit_ctx
*
)
ctx
;
atctx
.
pathlen
=
0
;
atctx
.
path
[
0
]
=
0
;
if
(
arg
c
==
0
)
{
if
(
arg
s
->
num
==
0
)
{
atctx
.
dir
=
apk_db_dir_get
(
db
,
APK_BLOB_PTR_LEN
(
atctx
.
path
,
atctx
.
pathlen
));
r
=
apk_dir_foreach_file
(
dup
(
db
->
root_fd
),
audit_directory_tree_item
,
&
atctx
);
apk_db_dir_unref
(
db
,
atctx
.
dir
,
FALSE
);
}
else
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
if
(
argv
[
i
][
0
]
!=
'/'
)
{
apk_warning
(
"%s: relative path skipped.
\n
"
,
argv
[
i
]);
continue
;
}
argv
[
i
]
++
;
atctx
.
pathlen
=
strlen
(
argv
[
i
]);
memcpy
(
atctx
.
path
,
argv
[
i
],
atctx
.
pathlen
);
if
(
atctx
.
path
[
atctx
.
pathlen
-
1
]
!=
'/'
)
atctx
.
path
[
atctx
.
pathlen
++
]
=
'/'
;
atctx
.
dir
=
apk_db_dir_get
(
db
,
APK_BLOB_PTR_LEN
(
atctx
.
path
,
atctx
.
pathlen
));
r
|=
apk_dir_foreach_file
(
openat
(
db
->
root_fd
,
argv
[
i
],
O_RDONLY
|
O_CLOEXEC
),
audit_directory_tree_item
,
&
atctx
);
apk_db_dir_unref
(
db
,
atctx
.
dir
,
FALSE
);
return
r
;
}
foreach_array_item
(
parg
,
args
)
{
arg
=
*
parg
;
if
(
arg
[
0
]
!=
'/'
)
{
apk_warning
(
"%s: relative path skipped.
\n
"
,
arg
);
continue
;
}
arg
++
;
atctx
.
pathlen
=
strlen
(
arg
);
memcpy
(
atctx
.
path
,
arg
,
atctx
.
pathlen
);
if
(
atctx
.
path
[
atctx
.
pathlen
-
1
]
!=
'/'
)
atctx
.
path
[
atctx
.
pathlen
++
]
=
'/'
;
atctx
.
dir
=
apk_db_dir_get
(
db
,
APK_BLOB_PTR_LEN
(
atctx
.
path
,
atctx
.
pathlen
));
r
|=
apk_dir_foreach_file
(
openat
(
db
->
root_fd
,
arg
,
O_RDONLY
|
O_CLOEXEC
),
audit_directory_tree_item
,
&
atctx
);
apk_db_dir_unref
(
db
,
atctx
.
dir
,
FALSE
);
}
return
r
;
}
...
...
src/cache.c
View file @
fe41ae07
...
...
@@ -111,18 +111,20 @@ static int cache_clean(struct apk_database *db)
return
apk_db_cache_foreach_item
(
db
,
cache_clean_item
);
}
static
int
cache_main
(
void
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
cache_main
(
void
*
ctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
char
*
arg
;
int
r
=
0
,
actions
=
0
;
if
(
arg
c
!=
1
)
if
(
arg
s
->
num
!=
1
)
return
-
EINVAL
;
if
(
strcmp
(
argv
[
0
],
"sync"
)
==
0
)
arg
=
args
->
item
[
0
];
if
(
strcmp
(
arg
,
"sync"
)
==
0
)
actions
=
CACHE_CLEAN
|
CACHE_DOWNLOAD
;
else
if
(
strcmp
(
arg
v
[
0
]
,
"clean"
)
==
0
)
else
if
(
strcmp
(
arg
,
"clean"
)
==
0
)
actions
=
CACHE_CLEAN
;
else
if
(
strcmp
(
arg
v
[
0
]
,
"download"
)
==
0
)
else
if
(
strcmp
(
arg
,
"download"
)
==
0
)
actions
=
CACHE_DOWNLOAD
;
else
return
-
EINVAL
;
...
...
@@ -137,7 +139,6 @@ static int cache_main(void *ctx, struct apk_database *db, int argc, char **argv)
r
=
cache_clean
(
db
);
if
(
r
==
0
&&
(
actions
&
CACHE_DOWNLOAD
))
r
=
cache_download
(
db
);
err:
return
r
;
}
...
...
src/database.c
View file @
fe41ae07
...
...
@@ -2673,3 +2673,80 @@ ret_r:
free
(
script_args
[
2
]);
return
r
;
}
struct
match_ctx
{
struct
apk_database
*
db
;
struct
apk_string_array
*
filter
;
unsigned
int
match
;
void
(
*
cb
)(
struct
apk_database
*
db
,
const
char
*
match
,
struct
apk_name
*
name
,
void
*
ctx
);
void
*
cb_ctx
;
};
static
int
match_names
(
apk_hash_item
item
,
void
*
pctx
)
{
struct
match_ctx
*
ctx
=
(
struct
match_ctx
*
)
pctx
;
struct
apk_name
*
name
=
(
struct
apk_name
*
)
item
;
unsigned
int
genid
=
ctx
->
match
&
APK_FOREACH_GENID_MASK
;
char
**
pmatch
;
if
(
genid
)
{
if
(
name
->
foreach_genid
>=
genid
)
return
0
;
name
->
foreach_genid
=
genid
;
}
if
(
ctx
->
filter
->
num
==
0
)
{
ctx
->
cb
(
ctx
->
db
,
NULL
,
name
,
ctx
->
cb_ctx
);
return
0
;
}
foreach_array_item
(
pmatch
,
ctx
->
filter
)
{
if
(
fnmatch
(
*
pmatch
,
name
->
name
,
FNM_CASEFOLD
)
==
0
)
{
ctx
->
cb
(
ctx
->
db
,
*
pmatch
,
name
,
ctx
->
cb_ctx
);
if
(
genid
)
break
;
}
}
return
0
;
}
void
apk_name_foreach_matching
(
struct
apk_database
*
db
,
struct
apk_string_array
*
filter
,
unsigned
int
match
,
void
(
*
cb
)(
struct
apk_database
*
db
,
const
char
*
match
,
struct
apk_name
*
name
,
void
*
ctx
),
void
*
ctx
)
{
char
**
pmatch
;
unsigned
int
genid
=
match
&
APK_FOREACH_GENID_MASK
;
struct
apk_name
*
name
;
struct
match_ctx
mctx
=
{
.
db
=
db
,
.
filter
=
filter
,
.
match
=
match
,
.
cb
=
cb
,
.
cb_ctx
=
ctx
,
};
if
(
filter
==
NULL
||
filter
->
num
==
0
)
{
apk_string_array_init
(
&
mctx
.
filter
);
goto
all
;
}
foreach_array_item
(
pmatch
,
filter
)
if
(
strchr
(
*
pmatch
,
'*'
)
!=
NULL
)
goto
all
;
foreach_array_item
(
pmatch
,
filter
)
{
name
=
(
struct
apk_name
*
)
apk_hash_get
(
&
db
->
available
.
names
,
APK_BLOB_STR
(
*
pmatch
));
if
(
name
==
NULL
)
continue
;
if
(
genid
)
{
if
(
name
->
foreach_genid
>=
genid
)
continue
;
name
->
foreach_genid
=
genid
;
}
cb
(
db
,
*
pmatch
,
name
,
ctx
);
}
return
;
all:
apk_hash_foreach
(
&
db
->
available
.
names
,
match_names
,
&
mctx
);
}
src/del.c
View file @
fe41ae07
...
...
@@ -75,22 +75,24 @@ static void delete_from_world(
delete_from_world
,
pctx
);
}
static
int
del_main
(
void
*
pctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
del_main
(
void
*
pctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
struct
del_ctx
*
ctx
=
(
struct
del_ctx
*
)
pctx
;
struct
not_deleted_ctx
ndctx
=
{};
struct
apk_name
**
name
;
struct
apk_name_array
*
names
;
struct
apk_name
**
pname
;
struct
apk_changeset
changeset
=
{};
struct
apk_change
*
change
;
struct
apk_provider
*
p
;
int
i
,
r
=
0
;
int
r
=
0
,
i
;
apk_name_array_init
(
&
names
);
apk_name_array_resize
(
&
names
,
args
->
num
);
apk_dependency_array_copy
(
&
ctx
->
world
,
db
->
world
);
name
=
alloca
(
argc
*
sizeof
(
struct
apk_name
*
));
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
name
[
i
]
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
argv
[
i
]));
delete_from_world
(
apk_pkg_get_installed
(
name
[
i
]),
NULL
,
NULL
,
ctx
);
for
(
i
=
0
;
i
<
args
->
num
;
i
++
)
{
names
->
item
[
i
]
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
args
->
item
[
i
]));
delete_from_world
(
apk_pkg_get_installed
(
names
->
item
[
i
]),
NULL
,
NULL
,
ctx
);
}
r
=
apk_solver_solve
(
db
,
0
,
ctx
->
world
,
&
changeset
);
...
...
@@ -102,11 +104,11 @@ static int del_main(void *pctx, struct apk_database *db, int argc, char **argv)
continue
;
pkg
->
marked
=
1
;
}
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
each_array_item
(
pname
,
names
)
{
ndctx
.
indent
.
indent
=
0
;
ndctx
.
name
=
name
[
i
]
;
ndctx
.
name
=
*
pname
;
ndctx
.
matches
=
apk_foreach_genid
()
|
APK_FOREACH_MARKED
|
APK_DEP_SATISFIES
;
foreach_array_item
(
p
,
name
[
i
]
->
providers
)
{
foreach_array_item
(
p
,
(
*
pname
)
->
providers
)
{
if
(
!
p
->
pkg
->
marked
)
continue
;
print_not_deleted_message
(
p
->
pkg
,
NULL
,
NULL
,
&
ndctx
);
...
...
@@ -122,6 +124,7 @@ static int del_main(void *pctx, struct apk_database *db, int argc, char **argv)
apk_solver_print_errors
(
db
,
&
changeset
,
ctx
->
world
);
}
apk_dependency_array_free
(
&
ctx
->
world
);
apk_name_array_free
(
&
names
);
return
r
;
}
...
...
@@ -144,4 +147,3 @@ static struct apk_applet apk_del = {
};
APK_DEFINE_APPLET
(
apk_del
);
src/dot.c
View file @
fe41ae07
...
...
@@ -120,15 +120,15 @@ static int foreach_pkg(apk_hash_item item, void *ctx)
return
0
;
}
static
int
dot_main
(
void
*
pctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
dot_main
(
void
*
pctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
struct
dot_ctx
*
ctx
=
(
struct
dot_ctx
*
)
pctx
;
struct
apk_provider
*
p
;
int
i
;
char
**
parg
;
if
(
arg
c
)
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
struct
apk_name
*
name
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
argv
[
i
]
));
if
(
arg
s
->
num
)
{
for
each_array_item
(
parg
,
args
)
{
struct
apk_name
*
name
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
*
parg
));
if
(
!
name
)
continue
;
foreach_array_item
(
p
,
name
->
providers
)
...
...
src/fetch.c
View file @
fe41ae07
...
...
@@ -190,26 +190,27 @@ static void mark_package(struct fetch_ctx *ctx, struct apk_package *pkg)
pkg
->
marked
=
1
;
}
static
int
fetch_main
(
void
*
pctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
fetch_main
(
void
*
pctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
struct
fetch_ctx
*
ctx
=
(
struct
fetch_ctx
*
)
pctx
;
struct
apk_dependency_array
*
world
;
struct
apk_change
*
change
;
int
r
=
0
,
i
;
char
**
parg
;
int
r
=
0
;
if
(
ctx
->
outdir_fd
==
0
)
ctx
->
outdir_fd
=
AT_FDCWD
;
if
((
arg
c
>
0
)
&&
(
strcmp
(
argv
[
0
],
"coffee"
)
==
0
))
{
if
((
arg
s
->
num
==
1
)
&&
(
strcmp
(
args
->
item
[
0
],
"coffee"
)
==
0
))
{
if
(
apk_flags
&
APK_FORCE
)
return
cup
();
apk_message
(
"Go and fetch your own coffee."
);
return
0
;
}
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
each_array_item
(
parg
,
args
)
{
struct
apk_dependency
dep
=
(
struct
apk_dependency
)
{
.
name
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
argv
[
i
]
)),
.
name
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
*
parg
)),
.
version
=
apk_blob_atomize
(
APK_BLOB_NULL
),
.
result_mask
=
APK_DEPMASK_ANY
,
};
...
...
@@ -222,7 +223,7 @@ static int fetch_main(void *pctx, struct apk_database *db, int argc, char **argv
r
=
apk_solver_solve
(
db
,
0
,
world
,
&
changeset
);
apk_dependency_array_free
(
&
world
);
if
(
r
!=
0
)
{
apk_error
(
"%s: unable to get dependencies"
,
argv
[
i
]
);
apk_error
(
"%s: unable to get dependencies"
,
dep
.
name
->
name
);
ctx
->
errors
++
;
}
else
{
foreach_array_item
(
change
,
changeset
.
changes
)
...
...
src/fix.c
View file @
fe41ae07
...
...
@@ -52,12 +52,13 @@ static int mark_recalculate(apk_hash_item item, void *ctx)
return
0
;
}
static
int
fix_main
(
void
*
pctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
fix_main
(
void
*
pctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
struct
fix_ctx
*
ctx
=
(
struct
fix_ctx
*
)
pctx
;
struct
apk_name
*
name
;
struct
apk_package
*
pkg
;
int
r
=
0
,
i
;
char
**
parg
;
int
r
=
0
;
if
(
!
ctx
->
solver_flags
)
ctx
->
solver_flags
=
APK_SOLVERF_REINSTALL
;
...
...
@@ -65,22 +66,22 @@ static int fix_main(void *pctx, struct apk_database *db, int argc, char **argv)
if
(
ctx
->
fix_directory_permissions
)
apk_hash_foreach
(
&
db
->
installed
.
dirs
,
mark_recalculate
,
db
);
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
each_array_item
(
parg
,
args
)
{
pkg
=
NULL
;
if
(
strstr
(
argv
[
i
]
,
".apk"
)
!=
NULL
)
{
if
(
strstr
(
*
parg
,
".apk"
)
!=
NULL
)
{
struct
apk_sign_ctx
sctx
;
apk_sign_ctx_init
(
&
sctx
,
APK_SIGN_VERIFY_AND_GENERATE
,
NULL
,
db
->
keys_fd
);
r
=
apk_pkg_read
(
db
,
argv
[
i
]
,
&
sctx
,
&
pkg
);
r
=
apk_pkg_read
(
db
,
*
parg
,
&
sctx
,
&
pkg
);
apk_sign_ctx_free
(
&
sctx
);
if
(
r
!=
0
)
{
apk_error
(
"%s: %s"
,
argv
[
i
]
,
apk_error_str
(
r
));
apk_error
(
"%s: %s"
,
*
parg
,
apk_error_str
(
r
));
goto
err
;
}
name
=
pkg
->
name
;
}
else
{
name
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
argv
[
i
]
));
name
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
*
parg
));
pkg
=
apk_pkg_get_installed
(
name
);
}
if
(
pkg
==
NULL
||
pkg
->
ipkg
==
NULL
)
{
...
...
src/index.c
View file @
fe41ae07
...
...
@@ -87,14 +87,15 @@ static int warn_if_no_providers(apk_hash_item item, void *ctx)
return
0
;
}
static
int
index_main
(
void
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
index_main
(
void
*
ctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
struct
counts
counts
=
{
0
};
struct
apk_ostream
*
os
;
struct
apk_file_info
fi
;
int
total
,
r
,
i
,
found
,
newpkgs
=
0
,
errors
=
0
;
int
total
,
r
,
found
,
newpkgs
=
0
,
errors
=
0
;
struct
index_ctx
*
ictx
=
(
struct
index_ctx
*
)
ctx
;
struct
apk_package
*
pkg
;
char
**
parg
;
if
(
isatty
(
STDOUT_FILENO
)
&&
ictx
->
output
==
NULL
&&
!
(
apk_flags
&
APK_FORCE
))
{
...
...
@@ -111,9 +112,9 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
return
r
;
}
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
if
(
apk_file_get_info
(
AT_FDCWD
,
argv
[
i
]
,
APK_CHECKSUM_NONE
,
&
fi
)
<
0
)
{
apk_warning
(
"File '%s' is unaccessible"
,
argv
[
i
]
);
for
each_array_item
(
parg
,
args
)
{
if
(
apk_file_get_info
(
AT_FDCWD
,
*
parg
,
APK_CHECKSUM_NONE
,
&
fi
)
<
0
)
{
apk_warning
(
"File '%s' is unaccessible"
,
*
parg
);
continue
;
}
...
...
@@ -129,9 +130,9 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
break
;
/* Check that it looks like a package name */
fname
=
strrchr
(
argv
[
i
]
,
'/'
);
fname
=
strrchr
(
*
parg
,
'/'
);
if
(
fname
==
NULL
)
fname
=
argv
[
i
]
;
fname
=
*
parg
;
else
fname
++
;
fend
=
strstr
(
fname
,
".apk"
);
...
...
@@ -154,7 +155,7 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
continue
;
if
(
pkg
->
size
!=
fi
.
size
)
continue
;
pkg
->
filename
=
strdup
(
argv
[
i
]
);
pkg
->
filename
=
strdup
(
*
parg
);
if
(
ictx
->
rewrite_arch
!=
NULL
)
pkg
->
arch
=
ictx
->
rewrite_arch
;
found
=
TRUE
;
...
...
@@ -165,9 +166,9 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
if
(
!
found
)
{
struct
apk_sign_ctx
sctx
;
apk_sign_ctx_init
(
&
sctx
,
ictx
->
method
,
NULL
,
db
->
keys_fd
);
r
=
apk_pkg_read
(
db
,
argv
[
i
]
,
&
sctx
,
&
pkg
);
r
=
apk_pkg_read
(
db
,
*
parg
,
&
sctx
,
&
pkg
);
if
(
r
<
0
)
{
apk_error
(
"%s: %s"
,
argv
[
i
]
,
apk_error_str
(
r
));
apk_error
(
"%s: %s"
,
*
parg
,
apk_error_str
(
r
));
errors
++
;
}
else
{
newpkgs
++
;
...
...
src/info.c
View file @
fe41ae07
...
...
@@ -19,8 +19,7 @@
struct
info_ctx
{
struct
apk_database
*
db
;
int
(
*
action
)(
struct
info_ctx
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
);
int
(
*
action
)(
struct
info_ctx
*
ctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
);
int
subaction_mask
;
};
...
...
@@ -55,27 +54,17 @@ static void verbose_print_pkg(struct apk_package *pkg, int minimal_verbosity)
printf
(
"
\n
"
);
}
static
int
info_list
(
struct
info_ctx
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
{
struct
apk_installed_package
*
ipkg
;
list_for_each_entry
(
ipkg
,
&
db
->
installed
.
packages
,
installed_pkgs_list
)
verbose_print_pkg
(
ipkg
->
pkg
,
1
);
return
0
;
}
static
int
info_exists
(
struct
info_ctx
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
struct
apk_string_array
*
args
)
{
struct
apk_name
*
name
;
struct
apk_dependency
dep
;
struct
apk_provider
*
p
;
int
i
,
ok
,
rc
=
0
;
char
**
parg
;
int
ok
,
errors
=
0
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
apk_blob_t
b
=
APK_BLOB_STR
(
argv
[
i
]
);
for
each_array_item
(
parg
,
args
)
{
apk_blob_t
b
=
APK_BLOB_STR
(
*
parg
);
apk_blob_pull_dep
(
&
b
,
db
,
&
dep
);
if
(
APK_BLOB_IS_NULL
(
b
)
||
b
.
len
>
0
)
...
...
@@ -93,26 +82,28 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
ok
=
1
;
}
if
(
!
ok
)
rc
++
;
errors
++
;
}
return
rc
;
return
errors
;
}
static
int
info_who_owns
(
struct
info_ctx
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
struct
apk_string_array
*
args
)
{
struct
apk_package
*
pkg
;
struct
apk_dependency_array
*
deps
;
struct
apk_dependency
dep
;
int
i
,
r
=
0
;
struct
apk_ostream
*
os
;
char
**
parg
;
int
errors
=
0
;
apk_dependency_array_init
(
&
deps
);
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
pkg
=
apk_db_get_file_owner
(
db
,
APK_BLOB_STR
(
argv
[
i
]
));
for
each_array_item
(
parg
,
args
)
{
pkg
=
apk_db_get_file_owner
(
db
,
APK_BLOB_STR
(
*
parg
));
if
(
pkg
==
NULL
)
{
apk_error
(
"%s: Could not find owner package"
,
argv
[
i
]
);
r
++
;
apk_error
(
"%s: Could not find owner package"
,
*
parg
);
errors
++
;
continue
;
}
...
...
@@ -125,12 +116,10 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
apk_deps_add
(
&
deps
,
&
dep
);
}
else
{
printf
(
"%s is owned by "
PKG_VER_FMT
"
\n
"
,
argv
[
i
]
,
PKG_VER_PRINTF
(
pkg
));
*
parg
,
PKG_VER_PRINTF
(
pkg
));
}
}
if
(
apk_verbosity
<
1
&&
deps
->
num
!=
0
)
{
struct
apk_ostream
*
os
;
os
=
apk_ostream_to_fd
(
STDOUT_FILENO
);
apk_deps_write
(
db
,
deps
,
os
,
APK_BLOB_PTR_LEN
(
" "
,
1
));
os
->
write
(
os
,
"
\n
"
,
1
);
...
...
@@ -138,7 +127,7 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
}
apk_dependency_array_free
(
&
deps
);
return
r
;
return
errors
;
}
static
void
info_print_description
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
...
...
@@ -332,16 +321,16 @@ static void info_subaction(struct info_ctx *ctx, struct apk_package *pkg)
}
static
int
info_package
(
struct
info_ctx
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
struct
apk_string_array
*
args
)
{
struct
apk_name
*
name
;
struct
apk_provider
*
p
;
int
i
;
char
**
parg
;