Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
alpine
apk-tools
Commits
54509e7a
Commit
54509e7a
authored
Jun 18, 2013
by
Timo Teräs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
all: various conversions to foreach_array_item, and simplifications of code
parent
72139b82
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
109 additions
and
189 deletions
+109
-189
src/apk_package.h
src/apk_package.h
+2
-4
src/commit.c
src/commit.c
+9
-15
src/database.c
src/database.c
+25
-33
src/dot.c
src/dot.c
+9
-9
src/hash.c
src/hash.c
+4
-3
src/info.c
src/info.c
+37
-93
src/package.c
src/package.c
+23
-32
No files found.
src/apk_package.h
View file @
54509e7a
...
@@ -154,10 +154,8 @@ void apk_blob_pull_deps(apk_blob_t *from, struct apk_database *, struct apk_depe
...
@@ -154,10 +154,8 @@ void apk_blob_pull_deps(apk_blob_t *from, struct apk_database *, struct apk_depe
int
apk_deps_write
(
struct
apk_database
*
db
,
struct
apk_dependency_array
*
deps
,
int
apk_deps_write
(
struct
apk_database
*
db
,
struct
apk_dependency_array
*
deps
,
struct
apk_ostream
*
os
,
apk_blob_t
separator
);
struct
apk_ostream
*
os
,
apk_blob_t
separator
);
int
apk_deps_add
(
struct
apk_dependency_array
**
depends
,
void
apk_deps_add
(
struct
apk_dependency_array
**
depends
,
struct
apk_dependency
*
dep
);
struct
apk_dependency
*
dep
);
void
apk_deps_del
(
struct
apk_dependency_array
**
deps
,
struct
apk_name
*
name
);
void
apk_deps_del
(
struct
apk_dependency_array
**
deps
,
struct
apk_name
*
name
);
int
apk_script_type
(
const
char
*
name
);
int
apk_script_type
(
const
char
*
name
);
struct
apk_package
*
apk_pkg_get_installed
(
struct
apk_name
*
name
);
struct
apk_package
*
apk_pkg_get_installed
(
struct
apk_name
*
name
);
...
...
src/commit.c
View file @
54509e7a
...
@@ -147,10 +147,9 @@ static int dump_packages(struct apk_changeset *changeset,
...
@@ -147,10 +147,9 @@ static int dump_packages(struct apk_changeset *changeset,
struct
apk_change
*
change
;
struct
apk_change
*
change
;
struct
apk_name
*
name
;
struct
apk_name
*
name
;
struct
apk_indent
indent
=
{
.
indent
=
2
};
struct
apk_indent
indent
=
{
.
indent
=
2
};
int
match
=
0
,
i
;
int
match
=
0
;
for
(
i
=
0
;
i
<
changeset
->
changes
->
num
;
i
++
)
{
foreach_array_item
(
change
,
changeset
->
changes
)
{
change
=
&
changeset
->
changes
->
item
[
i
];
if
(
!
cmp
(
change
))
if
(
!
cmp
(
change
))
continue
;
continue
;
if
(
match
==
0
)
if
(
match
==
0
)
...
@@ -207,18 +206,16 @@ static int cmp_upgrade(struct apk_change *change)
...
@@ -207,18 +206,16 @@ static int cmp_upgrade(struct apk_change *change)
static
void
run_triggers
(
struct
apk_database
*
db
,
struct
apk_changeset
*
changeset
)
static
void
run_triggers
(
struct
apk_database
*
db
,
struct
apk_changeset
*
changeset
)
{
{
int
i
;
struct
apk_change
*
change
;
struct
apk_installed_package
*
ipkg
;
if
(
apk_db_fire_triggers
(
db
)
==
0
)
if
(
apk_db_fire_triggers
(
db
)
==
0
)
return
;
return
;
for
(
i
=
0
;
i
<
changeset
->
changes
->
num
;
i
++
)
{
foreach_array_item
(
change
,
changeset
->
changes
)
{
struct
apk_package
*
pkg
=
changeset
->
changes
->
item
[
i
].
new_pkg
;
struct
apk_package
*
pkg
=
change
->
new_pkg
;
struct
apk_installed_package
*
ipkg
;
if
(
pkg
==
NULL
)
if
(
pkg
==
NULL
)
continue
;
continue
;
ipkg
=
pkg
->
ipkg
;
ipkg
=
pkg
->
ipkg
;
if
(
ipkg
->
pending_triggers
->
num
==
0
)
if
(
ipkg
->
pending_triggers
->
num
==
0
)
continue
;
continue
;
...
@@ -236,7 +233,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
...
@@ -236,7 +233,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
{
{
struct
progress
prog
;
struct
progress
prog
;
struct
apk_change
*
change
;
struct
apk_change
*
change
;
int
i
,
r
=
0
,
size_diff
=
0
,
size_unit
;
int
r
=
0
,
size_diff
=
0
,
size_unit
;
if
(
apk_db_check_world
(
db
,
world
)
!=
0
)
{
if
(
apk_db_check_world
(
db
,
world
)
!=
0
)
{
apk_error
(
"Not committing changes due to missing repository tags. Use --force to override."
);
apk_error
(
"Not committing changes due to missing repository tags. Use --force to override."
);
...
@@ -248,8 +245,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
...
@@ -248,8 +245,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
/* Count what needs to be done */
/* Count what needs to be done */
memset
(
&
prog
,
0
,
sizeof
(
prog
));
memset
(
&
prog
,
0
,
sizeof
(
prog
));
for
(
i
=
0
;
i
<
changeset
->
changes
->
num
;
i
++
)
{
foreach_array_item
(
change
,
changeset
->
changes
)
{
change
=
&
changeset
->
changes
->
item
[
i
];
count_change
(
change
,
&
prog
.
total
);
count_change
(
change
,
&
prog
.
total
);
if
(
change
->
new_pkg
)
if
(
change
->
new_pkg
)
size_diff
+=
change
->
new_pkg
->
installed_size
;
size_diff
+=
change
->
new_pkg
->
installed_size
;
...
@@ -291,9 +287,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
...
@@ -291,9 +287,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
/* Go through changes */
/* Go through changes */
r
=
0
;
r
=
0
;
for
(
i
=
0
;
i
<
changeset
->
changes
->
num
;
i
++
)
{
foreach_array_item
(
change
,
changeset
->
changes
)
{
change
=
&
changeset
->
changes
->
item
[
i
];
if
(
print_change
(
db
,
change
,
prog
.
done
.
changes
,
prog
.
total
.
changes
))
{
if
(
print_change
(
db
,
change
,
prog
.
done
.
changes
,
prog
.
total
.
changes
))
{
prog
.
pkg
=
change
->
new_pkg
;
prog
.
pkg
=
change
->
new_pkg
;
prog
.
flags
=
APK_PRINT_PROGRESS_FORCE
;
prog
.
flags
=
APK_PRINT_PROGRESS_FORCE
;
...
...
src/database.c
View file @
54509e7a
...
@@ -293,10 +293,10 @@ struct apk_db_dir *apk_db_dir_get(struct apk_database *db, apk_blob_t name)
...
@@ -293,10 +293,10 @@ struct apk_db_dir *apk_db_dir_get(struct apk_database *db, apk_blob_t name)
{
{
struct
apk_db_dir
*
dir
;
struct
apk_db_dir
*
dir
;
struct
apk_protected_path_array
*
ppaths
;
struct
apk_protected_path_array
*
ppaths
;
struct
apk_protected_path
*
ppath
;
apk_blob_t
bparent
;
apk_blob_t
bparent
;
unsigned
long
hash
=
apk_hash_from_key
(
&
db
->
installed
.
dirs
,
name
);
unsigned
long
hash
=
apk_hash_from_key
(
&
db
->
installed
.
dirs
,
name
);
char
*
relative_name
;
char
*
relative_name
;
int
i
;
if
(
name
.
len
&&
name
.
ptr
[
name
.
len
-
1
]
==
'/'
)
if
(
name
.
len
&&
name
.
ptr
[
name
.
len
-
1
]
==
'/'
)
name
.
len
--
;
name
.
len
--
;
...
@@ -338,11 +338,8 @@ struct apk_db_dir *apk_db_dir_get(struct apk_database *db, apk_blob_t name)
...
@@ -338,11 +338,8 @@ struct apk_db_dir *apk_db_dir_get(struct apk_database *db, apk_blob_t name)
return
dir
;
return
dir
;
relative_name
=
strrchr
(
dir
->
rooted_name
,
'/'
)
+
1
;
relative_name
=
strrchr
(
dir
->
rooted_name
,
'/'
)
+
1
;
for
(
i
=
0
;
i
<
ppaths
->
num
;
i
++
)
{
foreach_array_item
(
ppath
,
ppaths
)
{
struct
apk_protected_path
*
ppath
=
&
ppaths
->
item
[
i
];
char
*
slash
=
strchr
(
ppath
->
relative_pattern
,
'/'
);
char
*
slash
;
slash
=
strchr
(
ppath
->
relative_pattern
,
'/'
);
if
(
slash
!=
NULL
)
{
if
(
slash
!=
NULL
)
{
*
slash
=
0
;
*
slash
=
0
;
if
(
fnmatch
(
ppath
->
relative_pattern
,
relative_name
,
FNM_PATHNAME
)
!=
0
)
{
if
(
fnmatch
(
ppath
->
relative_pattern
,
relative_name
,
FNM_PATHNAME
)
!=
0
)
{
...
@@ -529,7 +526,7 @@ static inline void add_provider(struct apk_name *name, struct apk_provider p)
...
@@ -529,7 +526,7 @@ static inline void add_provider(struct apk_name *name, struct apk_provider p)
struct
apk_package
*
apk_db_pkg_add
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
struct
apk_package
*
apk_db_pkg_add
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
{
{
struct
apk_package
*
idb
;
struct
apk_package
*
idb
;
int
i
;
struct
apk_dependency
*
dep
;
if
(
pkg
->
license
==
NULL
)
if
(
pkg
->
license
==
NULL
)
pkg
->
license
=
apk_blob_atomize
(
APK_BLOB_NULL
);
pkg
->
license
=
apk_blob_atomize
(
APK_BLOB_NULL
);
...
@@ -544,10 +541,8 @@ struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *
...
@@ -544,10 +541,8 @@ struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *
idb
=
pkg
;
idb
=
pkg
;
apk_hash_insert
(
&
db
->
available
.
packages
,
pkg
);
apk_hash_insert
(
&
db
->
available
.
packages
,
pkg
);
add_provider
(
pkg
->
name
,
APK_PROVIDER_FROM_PACKAGE
(
pkg
));
add_provider
(
pkg
->
name
,
APK_PROVIDER_FROM_PACKAGE
(
pkg
));
for
(
i
=
0
;
i
<
pkg
->
provides
->
num
;
i
++
)
{
foreach_array_item
(
dep
,
pkg
->
provides
)
struct
apk_dependency
*
dep
=
&
pkg
->
provides
->
item
[
i
];
add_provider
(
dep
->
name
,
APK_PROVIDER_FROM_PROVIDES
(
pkg
,
dep
));
add_provider
(
dep
->
name
,
APK_PROVIDER_FROM_PROVIDES
(
pkg
,
dep
));
}
apk_db_pkg_rdepends
(
db
,
pkg
);
apk_db_pkg_rdepends
(
db
,
pkg
);
}
else
{
}
else
{
idb
->
repos
|=
pkg
->
repos
;
idb
->
repos
|=
pkg
->
repos
;
...
@@ -1057,7 +1052,7 @@ static void apk_db_triggers_write(struct apk_database *db, struct apk_ostream *o
...
@@ -1057,7 +1052,7 @@ static void apk_db_triggers_write(struct apk_database *db, struct apk_ostream *o
struct
apk_installed_package
*
ipkg
;
struct
apk_installed_package
*
ipkg
;
char
buf
[
APK_BLOB_CHECKSUM_BUF
];
char
buf
[
APK_BLOB_CHECKSUM_BUF
];
apk_blob_t
bfn
;
apk_blob_t
bfn
;
int
i
;
char
**
trigger
;
list_for_each_entry
(
ipkg
,
&
db
->
installed
.
triggers
,
trigger_pkgs_list
)
{
list_for_each_entry
(
ipkg
,
&
db
->
installed
.
triggers
,
trigger_pkgs_list
)
{
bfn
=
APK_BLOB_BUF
(
buf
);
bfn
=
APK_BLOB_BUF
(
buf
);
...
@@ -1065,9 +1060,9 @@ static void apk_db_triggers_write(struct apk_database *db, struct apk_ostream *o
...
@@ -1065,9 +1060,9 @@ static void apk_db_triggers_write(struct apk_database *db, struct apk_ostream *o
bfn
=
apk_blob_pushed
(
APK_BLOB_BUF
(
buf
),
bfn
);
bfn
=
apk_blob_pushed
(
APK_BLOB_BUF
(
buf
),
bfn
);
os
->
write
(
os
,
bfn
.
ptr
,
bfn
.
len
);
os
->
write
(
os
,
bfn
.
ptr
,
bfn
.
len
);
for
(
i
=
0
;
i
<
ipkg
->
triggers
->
num
;
i
++
)
{
for
each_array_item
(
trigger
,
ipkg
->
triggers
)
{
os
->
write
(
os
,
" "
,
1
);
os
->
write
(
os
,
" "
,
1
);
apk_ostream_write_string
(
os
,
ipkg
->
trigger
s
->
item
[
i
]
);
apk_ostream_write_string
(
os
,
*
trigger
);
}
}
os
->
write
(
os
,
"
\n
"
,
1
);
os
->
write
(
os
,
"
\n
"
,
1
);
}
}
...
@@ -1728,6 +1723,7 @@ void apk_db_close(struct apk_database *db)
...
@@ -1728,6 +1723,7 @@ void apk_db_close(struct apk_database *db)
{
{
struct
apk_installed_package
*
ipkg
;
struct
apk_installed_package
*
ipkg
;
struct
apk_db_dir_instance
*
diri
;
struct
apk_db_dir_instance
*
diri
;
struct
apk_protected_path
*
ppath
;
struct
hlist_node
*
dc
,
*
dn
;
struct
hlist_node
*
dc
,
*
dn
;
int
i
;
int
i
;
...
@@ -1746,8 +1742,8 @@ void apk_db_close(struct apk_database *db)
...
@@ -1746,8 +1742,8 @@ void apk_db_close(struct apk_database *db)
free
(
db
->
repos
[
i
].
url
);
free
(
db
->
repos
[
i
].
url
);
free
(
db
->
repos
[
i
].
description
.
ptr
);
free
(
db
->
repos
[
i
].
description
.
ptr
);
}
}
for
(
i
=
0
;
i
<
db
->
protected_paths
->
num
;
i
++
)
for
each_array_item
(
ppath
,
db
->
protected_paths
)
free
(
db
->
protected_
path
s
->
item
[
i
].
relative_pattern
);
free
(
p
path
->
relative_pattern
);
apk_protected_path_array_free
(
&
db
->
protected_paths
);
apk_protected_path_array_free
(
&
db
->
protected_paths
);
apk_dependency_array_free
(
&
db
->
world
);
apk_dependency_array_free
(
&
db
->
world
);
...
@@ -1849,8 +1845,8 @@ static int foreach_cache_file(void *pctx, int dirfd, const char *name)
...
@@ -1849,8 +1845,8 @@ static int foreach_cache_file(void *pctx, int dirfd, const char *name)
struct
foreach_cache_item_ctx
*
ctx
=
(
struct
foreach_cache_item_ctx
*
)
pctx
;
struct
foreach_cache_item_ctx
*
ctx
=
(
struct
foreach_cache_item_ctx
*
)
pctx
;
struct
apk_database
*
db
=
ctx
->
db
;
struct
apk_database
*
db
=
ctx
->
db
;
struct
apk_package
*
pkg
=
NULL
;
struct
apk_package
*
pkg
=
NULL
;
struct
apk_provider
*
p0
;
apk_blob_t
b
=
APK_BLOB_STR
(
name
),
bname
,
bver
;
apk_blob_t
b
=
APK_BLOB_STR
(
name
),
bname
,
bver
;
int
i
;
if
(
apk_pkg_parse_name
(
b
,
&
bname
,
&
bver
)
==
0
)
{
if
(
apk_pkg_parse_name
(
b
,
&
bname
,
&
bver
)
==
0
)
{
/* Package - search for it */
/* Package - search for it */
...
@@ -1859,15 +1855,13 @@ static int foreach_cache_file(void *pctx, int dirfd, const char *name)
...
@@ -1859,15 +1855,13 @@ static int foreach_cache_file(void *pctx, int dirfd, const char *name)
if
(
name
==
NULL
)
if
(
name
==
NULL
)
goto
no_pkg
;
goto
no_pkg
;
for
(
i
=
0
;
i
<
name
->
providers
->
num
;
i
++
)
{
foreach_array_item
(
p0
,
name
->
providers
)
{
struct
apk_package
*
pkg0
=
name
->
providers
->
item
[
i
].
pkg
;
if
(
p0
->
pkg
->
name
!=
name
)
if
(
pkg0
->
name
!=
name
)
continue
;
continue
;
apk_pkg_format_cache_pkg
(
APK_BLOB_BUF
(
tmp
),
pkg
0
);
apk_pkg_format_cache_pkg
(
APK_BLOB_BUF
(
tmp
),
p0
->
pkg
);
if
(
apk_blob_compare
(
b
,
APK_BLOB_STR
(
tmp
))
==
0
)
{
if
(
apk_blob_compare
(
b
,
APK_BLOB_STR
(
tmp
))
==
0
)
{
pkg
=
pkg
0
;
pkg
=
p0
->
pkg
;
break
;
break
;
}
}
}
}
...
@@ -1892,15 +1886,14 @@ int apk_db_permanent(struct apk_database *db)
...
@@ -1892,15 +1886,14 @@ int apk_db_permanent(struct apk_database *db)
int
apk_db_check_world
(
struct
apk_database
*
db
,
struct
apk_dependency_array
*
world
)
int
apk_db_check_world
(
struct
apk_database
*
db
,
struct
apk_dependency_array
*
world
)
{
{
int
i
,
bad
=
0
;
struct
apk_dependency
*
dep
;
int
bad
=
0
,
tag
;
if
(
apk_flags
&
APK_FORCE
)
if
(
apk_flags
&
APK_FORCE
)
return
0
;
return
0
;
for
(
i
=
0
;
i
<
world
->
num
;
i
++
)
{
foreach_array_item
(
dep
,
world
)
{
struct
apk_dependency
*
dep
=
&
world
->
item
[
i
];
tag
=
dep
->
repository_tag
;
int
tag
=
dep
->
repository_tag
;
if
(
tag
==
0
||
db
->
repo_tags
[
tag
].
allowed_repos
!=
0
)
if
(
tag
==
0
||
db
->
repo_tags
[
tag
].
allowed_repos
!=
0
)
continue
;
continue
;
...
@@ -2213,6 +2206,7 @@ static int apk_db_install_archive_entry(void *_ctx,
...
@@ -2213,6 +2206,7 @@ static int apk_db_install_archive_entry(void *_ctx,
struct
install_ctx
*
ctx
=
(
struct
install_ctx
*
)
_ctx
;
struct
install_ctx
*
ctx
=
(
struct
install_ctx
*
)
_ctx
;
struct
apk_database
*
db
=
ctx
->
db
;
struct
apk_database
*
db
=
ctx
->
db
;
struct
apk_package
*
pkg
=
ctx
->
pkg
,
*
opkg
;
struct
apk_package
*
pkg
=
ctx
->
pkg
,
*
opkg
;
struct
apk_dependency
*
dep
;
struct
apk_installed_package
*
ipkg
=
pkg
->
ipkg
;
struct
apk_installed_package
*
ipkg
=
pkg
->
ipkg
;
apk_blob_t
name
=
APK_BLOB_STR
(
ae
->
name
),
bdir
,
bfile
;
apk_blob_t
name
=
APK_BLOB_STR
(
ae
->
name
),
bdir
,
bfile
;
struct
apk_db_dir_instance
*
diri
=
ctx
->
diri
;
struct
apk_db_dir_instance
*
diri
=
ctx
->
diri
;
...
@@ -2274,8 +2268,6 @@ static int apk_db_install_archive_entry(void *_ctx,
...
@@ -2274,8 +2268,6 @@ static int apk_db_install_archive_entry(void *_ctx,
opkg
=
NULL
;
opkg
=
NULL
;
file
=
apk_db_file_query
(
db
,
bdir
,
bfile
);
file
=
apk_db_file_query
(
db
,
bdir
,
bfile
);
if
(
file
!=
NULL
)
{
if
(
file
!=
NULL
)
{
int
i
;
opkg
=
file
->
diri
->
pkg
;
opkg
=
file
->
diri
->
pkg
;
do
{
do
{
int
opkg_prio
=
-
1
,
pkg_prio
=
-
1
;
int
opkg_prio
=
-
1
,
pkg_prio
=
-
1
;
...
@@ -2287,15 +2279,15 @@ static int apk_db_install_archive_entry(void *_ctx,
...
@@ -2287,15 +2279,15 @@ static int apk_db_install_archive_entry(void *_ctx,
if
(
opkg
->
name
==
pkg
->
name
)
if
(
opkg
->
name
==
pkg
->
name
)
break
;
break
;
/* Does the original package replace the new one? */
/* Does the original package replace the new one? */
for
(
i
=
0
;
i
<
opkg
->
ipkg
->
replaces
->
num
;
i
++
)
{
for
each_array_item
(
dep
,
opkg
->
ipkg
->
replaces
)
{
if
(
apk_dep_is_materialized
(
&
opkg
->
ipkg
->
replaces
->
item
[
i
]
,
pkg
))
{
if
(
apk_dep_is_materialized
(
dep
,
pkg
))
{
opkg_prio
=
opkg
->
ipkg
->
replaces_priority
;
opkg_prio
=
opkg
->
ipkg
->
replaces_priority
;
break
;
break
;
}
}
}
}
/* Does the new package replace the original one? */
/* Does the new package replace the original one? */
for
(
i
=
0
;
i
<
ctx
->
ipkg
->
replaces
->
num
;
i
++
)
{
for
each_array_item
(
dep
,
ctx
->
ipkg
->
replaces
)
{
if
(
apk_dep_is_materialized
(
&
ctx
->
ipkg
->
replaces
->
item
[
i
]
,
opkg
))
{
if
(
apk_dep_is_materialized
(
dep
,
opkg
))
{
pkg_prio
=
ctx
->
ipkg
->
replaces_priority
;
pkg_prio
=
ctx
->
ipkg
->
replaces_priority
;
break
;
break
;
}
}
...
...
src/dot.c
View file @
54509e7a
...
@@ -64,7 +64,9 @@ static void dump_name(struct dot_ctx *ctx, struct apk_name *name)
...
@@ -64,7 +64,9 @@ static void dump_name(struct dot_ctx *ctx, struct apk_name *name)
static
int
dump_pkg
(
struct
dot_ctx
*
ctx
,
struct
apk_package
*
pkg
)
static
int
dump_pkg
(
struct
dot_ctx
*
ctx
,
struct
apk_package
*
pkg
)
{
{
int
i
,
j
,
r
,
ret
=
0
;
struct
apk_dependency
*
dep
;
struct
apk_provider
*
p0
;
int
r
,
ret
=
0
;
if
(
pkg
->
state_int
==
S_EVALUATED
)
if
(
pkg
->
state_int
==
S_EVALUATED
)
return
0
;
return
0
;
...
@@ -75,8 +77,7 @@ static int dump_pkg(struct dot_ctx *ctx, struct apk_package *pkg)
...
@@ -75,8 +77,7 @@ static int dump_pkg(struct dot_ctx *ctx, struct apk_package *pkg)
}
}
pkg
->
state_int
=
S_EVALUATING
;
pkg
->
state_int
=
S_EVALUATING
;
for
(
i
=
0
;
i
<
pkg
->
depends
->
num
;
i
++
)
{
foreach_array_item
(
dep
,
pkg
->
depends
)
{
struct
apk_dependency
*
dep
=
&
pkg
->
depends
->
item
[
i
];
struct
apk_name
*
name
=
dep
->
name
;
struct
apk_name
*
name
=
dep
->
name
;
dump_name
(
ctx
,
name
);
dump_name
(
ctx
,
name
);
...
@@ -87,9 +88,7 @@ static int dump_pkg(struct dot_ctx *ctx, struct apk_package *pkg)
...
@@ -87,9 +88,7 @@ static int dump_pkg(struct dot_ctx *ctx, struct apk_package *pkg)
continue
;
continue
;
}
}
for
(
j
=
0
;
j
<
name
->
providers
->
num
;
j
++
)
{
foreach_array_item
(
p0
,
name
->
providers
)
{
struct
apk_provider
*
p0
=
&
name
->
providers
->
item
[
j
];
if
(
!
apk_dep_is_provided
(
dep
,
p0
))
if
(
!
apk_dep_is_provided
(
dep
,
p0
))
continue
;
continue
;
...
@@ -124,15 +123,16 @@ static int foreach_pkg(apk_hash_item item, void *ctx)
...
@@ -124,15 +123,16 @@ static int foreach_pkg(apk_hash_item item, void *ctx)
static
int
dot_main
(
void
*
pctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
static
int
dot_main
(
void
*
pctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
{
{
struct
dot_ctx
*
ctx
=
(
struct
dot_ctx
*
)
pctx
;
struct
dot_ctx
*
ctx
=
(
struct
dot_ctx
*
)
pctx
;
int
i
,
j
;
struct
apk_provider
*
p
;
int
i
;
if
(
argc
)
{
if
(
argc
)
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
struct
apk_name
*
name
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
argv
[
i
]));
struct
apk_name
*
name
=
apk_db_get_name
(
db
,
APK_BLOB_STR
(
argv
[
i
]));
if
(
!
name
)
if
(
!
name
)
continue
;
continue
;
for
(
j
=
0
;
j
<
name
->
providers
->
num
;
j
++
)
for
each_array_item
(
p
,
name
->
providers
)
dump_pkg
(
ctx
,
name
->
providers
->
item
[
j
].
pkg
);
dump_pkg
(
ctx
,
p
->
pkg
);
}
}
}
else
{
}
else
{
apk_hash_foreach
(
&
db
->
available
.
packages
,
foreach_pkg
,
pctx
);
apk_hash_foreach
(
&
db
->
available
.
packages
,
foreach_pkg
,
pctx
);
...
...
src/hash.c
View file @
54509e7a
...
@@ -29,12 +29,13 @@ void apk_hash_free(struct apk_hash *h)
...
@@ -29,12 +29,13 @@ void apk_hash_free(struct apk_hash *h)
int
apk_hash_foreach
(
struct
apk_hash
*
h
,
apk_hash_enumerator_f
e
,
void
*
ctx
)
int
apk_hash_foreach
(
struct
apk_hash
*
h
,
apk_hash_enumerator_f
e
,
void
*
ctx
)
{
{
struct
hlist_head
*
bucket
;
apk_hash_node
*
pos
,
*
n
;
apk_hash_node
*
pos
,
*
n
;
ptrdiff_t
offset
=
h
->
ops
->
node_offset
;
ptrdiff_t
offset
=
h
->
ops
->
node_offset
;
int
i
,
r
;
int
r
;
for
(
i
=
0
;
i
<
h
->
buckets
->
num
;
i
++
)
{
for
each_array_item
(
bucket
,
h
->
buckets
)
{
hlist_for_each_safe
(
pos
,
n
,
&
h
->
bucket
s
->
item
[
i
]
)
{
hlist_for_each_safe
(
pos
,
n
,
bucket
)
{
r
=
e
(((
void
*
)
pos
)
-
offset
,
ctx
);
r
=
e
(((
void
*
)
pos
)
-
offset
,
ctx
);
if
(
r
!=
0
&&
ctx
!=
NULL
)
if
(
r
!=
0
&&
ctx
!=
NULL
)
return
r
;
return
r
;
...
...
src/info.c
View file @
54509e7a
...
@@ -71,7 +71,8 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
...
@@ -71,7 +71,8 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
{
{
struct
apk_name
*
name
;
struct
apk_name
*
name
;
struct
apk_dependency
dep
;
struct
apk_dependency
dep
;
int
i
,
j
,
ok
,
rc
=
0
;
struct
apk_provider
*
p
;
int
i
,
ok
,
rc
=
0
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
apk_blob_t
b
=
APK_BLOB_STR
(
argv
[
i
]);
apk_blob_t
b
=
APK_BLOB_STR
(
argv
[
i
]);
...
@@ -85,11 +86,8 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
...
@@ -85,11 +86,8 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
continue
;
continue
;
ok
=
0
;
ok
=
0
;
for
(
j
=
0
;
j
<
name
->
providers
->
num
;
j
++
)
{
foreach_array_item
(
p
,
name
->
providers
)
{
struct
apk_provider
*
p
=
&
name
->
providers
->
item
[
j
];
if
(
p
->
pkg
->
ipkg
==
NULL
||
!
apk_dep_is_provided
(
&
dep
,
p
))
if
(
p
->
pkg
->
ipkg
==
NULL
)
continue
;
if
(
!
apk_dep_is_provided
(
&
dep
,
p
))
continue
;
continue
;
verbose_print_pkg
(
p
->
pkg
,
0
);
verbose_print_pkg
(
p
->
pkg
,
0
);
ok
=
1
;
ok
=
1
;
...
@@ -173,96 +171,56 @@ static void info_print_size(struct apk_database *db, struct apk_package *pkg)
...
@@ -173,96 +171,56 @@ static void info_print_size(struct apk_database *db, struct apk_package *pkg)
pkg
->
installed_size
);
pkg
->
installed_size
);
}
}
static
void
info_print_depends
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
static
void
info_print_dep_array
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
,
struct
apk_dependency_array
*
deps
,
const
char
*
dep_text
)
{
{
struct
apk_dependency
*
d
;
apk_blob_t
separator
=
APK_BLOB_STR
(
apk_verbosity
>
1
?
" "
:
"
\n
"
);
apk_blob_t
separator
=
APK_BLOB_STR
(
apk_verbosity
>
1
?
" "
:
"
\n
"
);
char
dep
[
256
];
char
buf
[
256
];
int
i
;
if
(
apk_verbosity
==
1
)
if
(
apk_verbosity
==
1
)
printf
(
PKG_VER_FMT
" depends on:
\n
"
,
printf
(
PKG_VER_FMT
" %s:
\n
"
,
PKG_VER_PRINTF
(
pkg
),
dep_text
);
PKG_VER_PRINTF
(
pkg
));
if
(
apk_verbosity
>
1
)
if
(
apk_verbosity
>
1
)
printf
(
"%s: "
,
pkg
->
name
->
name
);
printf
(
"%s: "
,
pkg
->
name
->
name
);
for
(
i
=
0
;
i
<
pkg
->
depends
->
num
;
i
++
)
{
for
each_array_item
(
d
,
deps
)
{
apk_blob_t
b
=
APK_BLOB_BUF
(
dep
);
apk_blob_t
b
=
APK_BLOB_BUF
(
buf
);
apk_blob_push_dep
(
&
b
,
db
,
&
pkg
->
depends
->
item
[
i
]
);
apk_blob_push_dep
(
&
b
,
db
,
d
);
apk_blob_push_blob
(
&
b
,
separator
);
apk_blob_push_blob
(
&
b
,
separator
);
b
=
apk_blob_pushed
(
APK_BLOB_BUF
(
dep
),
b
);
b
=
apk_blob_pushed
(
APK_BLOB_BUF
(
buf
),
b
);
fwrite
(
b
.
ptr
,
b
.
len
,
1
,
stdout
);
fwrite
(
b
.
ptr
,
b
.
len
,
1
,
stdout
);
}
}
}
}
static
void
info_print_depends
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
{
info_print_dep_array
(
db
,
pkg
,
pkg
->
depends
,
"depends on"
);
}
static
void
info_print_provides
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
static
void
info_print_provides
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
{
{
apk_blob_t
separator
=
APK_BLOB_STR
(
apk_verbosity
>
1
?
" "
:
"
\n
"
);
info_print_dep_array
(
db
,
pkg
,
pkg
->
provides
,
"provides"
);
char
dep
[
256
];
}
int
i
;
if
(
apk_verbosity
==
1
)
static
void
print_rdep_pkg
(
struct
apk_package
*
pkg0
,
struct
apk_dependency
*
dep0
,
struct
apk_package
*
pkg
,
void
*
pctx
)
printf
(
PKG_VER_FMT
" provides:
\n
"
,
{
PKG_VER_PRINTF
(
pkg
));
printf
(
PKG_VER_FMT
"%s"
,
PKG_VER_PRINTF
(
pkg0
),
apk_verbosity
>
1
?
" "
:
"
\n
"
);
if
(
apk_verbosity
>
1
)
printf
(
"%s: "
,
pkg
->
name
->
name
);
for
(
i
=
0
;
i
<
pkg
->
provides
->
num
;
i
++
)
{
apk_blob_t
b
=
APK_BLOB_BUF
(
dep
);
apk_blob_push_dep
(
&
b
,
db
,
&
pkg
->
provides
->
item
[
i
]);
apk_blob_push_blob
(
&
b
,
separator
);
b
=
apk_blob_pushed
(
APK_BLOB_BUF
(
dep
),
b
);
fwrite
(
b
.
ptr
,
b
.
len
,
1
,
stdout
);
}
}
}
static
void
info_print_required_by
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
static
void
info_print_required_by
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
)
{
{
int
i
,
j
;
char
*
separator
=
apk_verbosity
>
1
?
" "
:
"
\n
"
;
if
(
apk_verbosity
==
1
)
if
(
apk_verbosity
==
1
)
printf
(
PKG_VER_FMT
" is required by:
\n
"
,
printf
(
PKG_VER_FMT
" is required by:
\n
"
,
PKG_VER_PRINTF
(
pkg
));
PKG_VER_PRINTF
(
pkg
));
if
(
apk_verbosity
>
1
)
if
(
apk_verbosity
>
1
)
printf
(
"%s: "
,
pkg
->
name
->
name
);
printf
(
"%s: "
,
pkg
->
name
->
name
);
for
(
i
=
0
;
i
<
pkg
->
name
->
rdepends
->
num
;
i
++
)
{
apk_pkg_foreach_reverse_dependency
(
struct
apk_name
*
name0
;
pkg
,
struct
apk_package
*
pkg0
;
APK_FOREACH_INSTALLED
|
APK_DEP_SATISFIES
|
apk_foreach_genid
(),
print_rdep_pkg
,
NULL
);
/* Check only the package that is installed, and that
* it actually has this package as dependency. */
name0
=
pkg
->
name
->
rdepends
->
item
[
i
];
pkg0
=
apk_pkg_get_installed
(
name0
);
if
(
pkg0
==
NULL
)
continue
;
for
(
j
=
0
;
j
<
pkg0
->
depends
->
num
;
j
++
)
{
if
(
pkg0
->
depends
->
item
[
j
].
name
!=
pkg
->
name
)
continue
;
printf
(
PKG_VER_FMT
"%s"
,
PKG_VER_PRINTF
(
pkg0
),
separator
);
break
;
}
}
}
}