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
61
Issues
61
List
Boards
Labels
Service Desk
Milestones
Merge Requests
15
Merge Requests
15
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
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
3ec82a5a
Commit
3ec82a5a
authored
Mar 05, 2010
by
Natanael Copa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First steps for libapk
parent
60b537e3
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
165 additions
and
77 deletions
+165
-77
.gitignore
.gitignore
+1
-0
Make.rules
Make.rules
+20
-2
Makefile
Makefile
+2
-1
src/Makefile
src/Makefile
+17
-7
src/add.c
src/add.c
+1
-0
src/apk.c
src/apk.c
+3
-57
src/apk_database.h
src/apk_database.h
+1
-1
src/apk_defines.h
src/apk_defines.h
+1
-8
src/apk_print.h
src/apk_print.h
+27
-0
src/apk_state.h
src/apk_state.h
+3
-0
src/archive.c
src/archive.c
+1
-0
src/cache.c
src/cache.c
+1
-0
src/database.c
src/database.c
+6
-1
src/del.c
src/del.c
+1
-0
src/fetch.c
src/fetch.c
+1
-0
src/fix.c
src/fix.c
+1
-0
src/index.c
src/index.c
+1
-0
src/info.c
src/info.c
+1
-0
src/package.c
src/package.c
+1
-0
src/print.c
src/print.c
+70
-0
src/state.c
src/state.c
+1
-0
src/update.c
src/update.c
+1
-0
src/upgrade.c
src/upgrade.c
+1
-0
src/ver.c
src/ver.c
+1
-0
src/verify.c
src/verify.c
+1
-0
No files found.
.gitignore
View file @
3ec82a5a
...
...
@@ -2,3 +2,4 @@ apk
*.o
*.d
*.cmd
*.so
Make.rules
View file @
3ec82a5a
...
...
@@ -70,7 +70,7 @@ INSTALL := install
INSTALLDIR := $(INSTALL) -d
CFLAGS ?= -g -O2
CFLAGS_ALL := -Werror -Wall -Wstrict-prototypes -D_GNU_SOURCE -std=gnu99
CFLAGS_ALL := -Werror -Wall -Wstrict-prototypes -D_GNU_SOURCE -std=gnu99
-fPIC
CFLAGS_ALL += $(CFLAGS)
LDFLAGS ?= -g
...
...
@@ -196,6 +196,24 @@ $(obj)/%.o: override local-target-prereqs=%
$(obj)/%.o: $(src)/%.c FORCE
$(call if_changed_rule,cc_o_c)
#####
# Link shared libraries
#
__shlibs := $(addprefix $(obj)/,$(sort $(shlibs-y)))
shobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(shlibs-y),$($(m)-objs))))
# link shared library
quiet_cmd_shlib = LD -shared $@
cmd_shlib = $(CC) $(ld_flags) -shared -o $@ \
$(addprefix $(obj)/,$($(@F)-objs)) \
$(LIBS) $(LIBS_$(@F))
$(__shlibs): override local-target-prereqs=$(addprefix $(obj)/,$($(*F)-objs))
$(__shlibs): $(obj)/%: $(shobjs) FORCE
$(call if_changed,shlib)
targets += $(__shlibs) $(shobjs)
#####
# Link programs
...
...
@@ -256,7 +274,7 @@ ifeq ($(toplevelrun),yes)
\( -name '*.[oas]' -o -name '.*.cmd' -o -name '.*.d' \) \
-type f -print | xargs rm -f
endif
$(Q)rm -rf $(addprefix $(obj)/,$(sort $(progs-y) $(progs-n) $(progs-)))
$(Q)rm -rf $(addprefix $(obj)/,$(sort $(progs-y) $(progs-n) $(progs-)
$(shlibs-y) $(shlibs-n) $(shlibs-)
))
ifeq ($(origin VERSION),command line)
DIST_VERSION=$(VERSION)
...
...
Makefile
View file @
3ec82a5a
...
...
@@ -9,11 +9,12 @@ VERSION := 2.0.3
DESTDIR
:=
SBINDIR
:=
/sbin
LIBDIR
:=
/lib
CONFDIR
:=
/etc/apk
MANDIR
:=
/usr/share/man
DOCDIR
:=
/usr/share/doc/apk
export
DESTDIR
SBINDIR
CONFDIR
MANDIR
DOCDIR
export
DESTDIR
SBINDIR
LIBDIR
CONFDIR
MANDIR
DOCDIR
##
# Top-level rules and targets
...
...
src/Makefile
View file @
3ec82a5a
...
...
@@ -4,24 +4,34 @@ ifeq ($(shell pkg-config --print-errors --exists $(PKGDEPS) || echo fail),fail)
$(error
Build
dependencies
are
not
met)
endif
shlibs-y
+=
libapk.so
libapk.so-objs
:=
common.o state.o database.o package.o archive.o
\
version.o io.o url.o gunzip.o blob.o hash.o print.o
progs-y
+=
apk
apk-objs
:=
common.o state.o database.o package.o archive
.o
\
version.o io.o url.o gunzip.o blob.o hash.o apk
.o
\
a
dd.o del.o fix.o update.o info.o search.o upgrade.o
\
cache.o ver.o index.o fetch.o audit.o verify.o
apk-objs
:=
apk.o add.o del.o fix.o update.o info
.o
\
search.o upgrade.o cache.o ver.o index.o fetch
.o
\
a
udit.o verify.o
CFLAGS
+=
-D_ATFILE_SOURCE
CFLAGS_apk.o
:=
-DAPK_VERSION
=
\"
$(FULL_VERSION)
\"
LIBS_apk
:=
-lapk
progs-$(STATIC)
+=
apk.static
apk.static-objs
:=
$
(
apk-objs
)
LDFLAGS_apk.static
:=
-static
LDFLAGS_apk
+=
-nopie
LDFLAGS_apk
+=
-nopie
-L
$(obj)
CFLAGS
+=
$(
shell
pkg-config
--cflags
$(PKGDEPS)
)
LIBS
:=
-Wl
,--as-needed
\
$(
shell
pkg-config
--libs
$(PKGDEPS)
)
\
-Wl
,--no-as-needed
install
:
$(INSTALLDIR)
$(DESTDIR)$(SBINDIR)
$(obj)/apk
:
$(obj)/libapk.so
install
:
$(obj)/apk $(obj)/libapk.so
$(INSTALLDIR)
$(DESTDIR)$(SBINDIR)
$(DESTDIR)$(LIBDIR)
$(INSTALL)
$(obj)
/apk
$(DESTDIR)$(SBINDIR)
$(INSTALL)
$(obj)
/libapk.so
$(DESTDIR)$(LIBDIR)
src/add.c
View file @
3ec82a5a
...
...
@@ -14,6 +14,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_state.h"
#include "apk_print.h"
struct
add_ctx
{
const
char
*
virtpkg
;
...
...
src/apk.c
View file @
3ec82a5a
...
...
@@ -24,9 +24,7 @@
#include "apk_database.h"
#include "apk_applet.h"
#include "apk_blob.h"
int
apk_verbosity
=
1
,
apk_wait
;
unsigned
int
apk_flags
=
0
;
#include "apk_print.h"
static
struct
apk_option
generic_options
[]
=
{
{
'h'
,
"help"
,
"Show generic help or applet specific help"
},
...
...
@@ -60,64 +58,12 @@ static struct apk_option generic_options[] = {
{
0x111
,
"overlay-from-stdin"
,
"Read list of overlay files from stdin"
},
};
const
char
*
apk_error_str
(
int
error
)
{
if
(
error
<
0
)
error
=
-
error
;
switch
(
error
)
{
case
ENOKEY
:
return
"UNTRUSTED signature"
;
case
EKEYREJECTED
:
return
"BAD signature"
;
case
EIO
:
return
"IO ERROR"
;
case
EBADMSG
:
return
"BAD archive"
;
case
ENOMSG
:
return
"archive does not contain expected data"
;
default:
return
strerror
(
error
);
}
}
void
apk_log
(
const
char
*
prefix
,
const
char
*
format
,
...)
{
va_list
va
;
if
(
prefix
!=
NULL
)
fprintf
(
stderr
,
"%s"
,
prefix
);
va_start
(
va
,
format
);
vfprintf
(
stderr
,
format
,
va
);
va_end
(
va
);
fprintf
(
stderr
,
"
\n
"
);
}
static
int
version
(
void
)
{
printf
(
"apk-tools "
APK_VERSION
"
\n
"
);
return
0
;
}
int
apk_print_indented
(
struct
apk_indent
*
i
,
apk_blob_t
blob
)
{
static
const
int
wrap_length
=
80
;
if
(
i
->
x
+
blob
.
len
+
1
>=
wrap_length
)
{
i
->
x
=
i
->
indent
;
printf
(
"
\n
%*s"
,
i
->
indent
-
1
,
""
);
}
else
if
(
i
->
x
+
1
<
i
->
indent
)
{
printf
(
"%*s"
,
i
->
indent
-
i
->
x
-
1
,
""
);
}
i
->
x
+=
printf
(
" %.*s"
,
blob
.
len
,
blob
.
ptr
);
return
0
;
}
void
apk_print_indented_words
(
struct
apk_indent
*
i
,
const
char
*
text
)
{
apk_blob_for_each_segment
(
APK_BLOB_STR
(
text
),
" "
,
(
apk_blob_cb
)
apk_print_indented
,
i
);
}
static
int
format_option
(
char
*
buf
,
size_t
len
,
struct
apk_option
*
o
,
const
char
*
separator
)
{
...
...
@@ -289,7 +235,7 @@ int main(int argc, char **argv)
struct
apk_applet
*
applet
;
char
short_options
[
256
],
*
sopt
;
struct
option
*
opt
,
*
all_options
;
int
r
,
optindex
,
num_options
;
int
r
,
optindex
,
num_options
,
apk_wait
=
0
;
void
*
ctx
=
NULL
;
struct
apk_repository_list
*
repo
=
NULL
;
struct
apk_database
db
;
...
...
@@ -410,7 +356,7 @@ int main(int argc, char **argv)
argv
++
;
}
r
=
apk_db_open
(
&
db
,
&
dbopts
);
r
=
apk_db_open
(
&
db
,
&
dbopts
,
apk_wait
);
if
(
r
!=
0
)
{
apk_error
(
"Failed to open apk database: %s"
,
apk_error_str
(
r
));
...
...
src/apk_database.h
View file @
3ec82a5a
...
...
@@ -155,7 +155,7 @@ struct apk_db_file *apk_db_file_query(struct apk_database *db,
APK_OPENF_NO_SCRIPTS | \
APK_OPENF_NO_WORLD)
int
apk_db_open
(
struct
apk_database
*
db
,
struct
apk_db_options
*
dbopts
);
int
apk_db_open
(
struct
apk_database
*
db
,
struct
apk_db_options
*
dbopts
,
int
apk_wait
);
void
apk_db_close
(
struct
apk_database
*
db
);
int
apk_db_write_config
(
struct
apk_database
*
db
);
int
apk_db_run_triggers
(
struct
apk_database
*
db
);
...
...
src/apk_defines.h
View file @
3ec82a5a
...
...
@@ -47,7 +47,7 @@
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
extern
int
apk_verbosity
,
apk_wait
;
extern
int
apk_verbosity
;
extern
unsigned
int
apk_flags
;
#define APK_FORCE 0x0001
...
...
@@ -65,13 +65,6 @@ extern unsigned int apk_flags;
#define APK_NO_NETWORK 0x1000
#define APK_OVERLAY_FROM_STDIN 0x2000
#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0)
#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0)
#define apk_message(args...) do { if (apk_verbosity > 0) { apk_log(NULL, args); } } while (0)
void
apk_log
(
const
char
*
prefix
,
const
char
*
format
,
...);
const
char
*
apk_error_str
(
int
error
);
static
inline
size_t
apk_calc_installed_size
(
size_t
size
)
{
const
size_t
bsize
=
4
*
1024
;
...
...
src/apk_print.h
0 → 100644
View file @
3ec82a5a
/* apk_state.h - Alpine Package Keeper (APK)
*
* Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
#ifndef APK_PRINT_H
#define APK_PRINT_H
#include "apk_blob.h"
#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0)
#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0)
#define apk_message(args...) do { if (apk_verbosity > 0) { apk_log(NULL, args); } } while (0)
void
apk_log
(
const
char
*
prefix
,
const
char
*
format
,
...);
const
char
*
apk_error_str
(
int
error
);
int
apk_print_indented
(
struct
apk_indent
*
i
,
apk_blob_t
blob
);
void
apk_print_indented_words
(
struct
apk_indent
*
i
,
const
char
*
text
);
#endif
src/apk_state.h
View file @
3ec82a5a
...
...
@@ -43,4 +43,7 @@ int apk_state_lock_name(struct apk_state *state,
struct
apk_name
*
name
,
struct
apk_package
*
newpkg
);
int
apk_print_indented
(
struct
apk_indent
*
i
,
apk_blob_t
blob
);
void
apk_print_indented_words
(
struct
apk_indent
*
i
,
const
char
*
text
);
#endif
src/archive.c
View file @
3ec82a5a
...
...
@@ -24,6 +24,7 @@
#include <stdint.h>
#include "apk_defines.h"
#include "apk_print.h"
#include "apk_archive.h"
struct
tar_header
{
...
...
src/cache.c
View file @
3ec82a5a
...
...
@@ -19,6 +19,7 @@
#include "apk_database.h"
#include "apk_state.h"
#include "apk_package.h"
#include "apk_print.h"
#define CACHE_CLEAN BIT(0)
#define CACHE_DOWNLOAD BIT(1)
...
...
src/database.c
View file @
3ec82a5a
...
...
@@ -27,6 +27,10 @@
#include "apk_state.h"
#include "apk_applet.h"
#include "apk_archive.h"
#include "apk_print.h"
int
apk_verbosity
=
1
;
unsigned
int
apk_flags
=
0
;
const
char
*
const
apkindex_tar_gz
=
"APKINDEX.tar.gz"
;
const
char
*
const
apk_index_gz
=
"APK_INDEX.gz"
;
...
...
@@ -1021,7 +1025,8 @@ static void handle_alarm(int sig)
{
}
int
apk_db_open
(
struct
apk_database
*
db
,
struct
apk_db_options
*
dbopts
)
int
apk_db_open
(
struct
apk_database
*
db
,
struct
apk_db_options
*
dbopts
,
int
apk_wait
)
{
const
char
*
msg
=
NULL
;
struct
apk_repository_list
*
repo
=
NULL
;
...
...
src/del.c
View file @
3ec82a5a
...
...
@@ -13,6 +13,7 @@
#include "apk_applet.h"
#include "apk_state.h"
#include "apk_database.h"
#include "apk_print.h"
static
int
del_parse
(
void
*
ctx
,
struct
apk_db_options
*
db
,
int
optch
,
int
optindex
,
const
char
*
optarg
)
...
...
src/fetch.c
View file @
3ec82a5a
...
...
@@ -20,6 +20,7 @@
#include "apk_database.h"
#include "apk_state.h"
#include "apk_io.h"
#include "apk_print.h"
#define FETCH_RECURSIVE 1
#define FETCH_STDOUT 2
...
...
src/fix.c
View file @
3ec82a5a
...
...
@@ -14,6 +14,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_state.h"
#include "apk_print.h"
struct
fix_ctx
{
unsigned
int
reinstall
:
1
;
...
...
src/index.c
View file @
3ec82a5a
...
...
@@ -15,6 +15,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_print.h"
#define INDEX_OLD_FORMAT 0x10000
...
...
src/info.c
View file @
3ec82a5a
...
...
@@ -16,6 +16,7 @@
#include "apk_package.h"
#include "apk_database.h"
#include "apk_state.h"
#include "apk_print.h"
struct
info_ctx
{
int
(
*
action
)(
struct
info_ctx
*
ctx
,
struct
apk_database
*
db
,
...
...
src/package.c
View file @
3ec82a5a
...
...
@@ -27,6 +27,7 @@
#include "apk_package.h"
#include "apk_database.h"
#include "apk_state.h"
#include "apk_print.h"
void
apk_pkg_format_plain
(
struct
apk_package
*
pkg
,
apk_blob_t
to
)
{
...
...
src/print.c
0 → 100644
View file @
3ec82a5a
/* state.c - Alpine Package Keeper (APK)
*
* Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include <errno.h>
#include "apk_defines.h"
#include "apk_print.h"
int
apk_print_indented
(
struct
apk_indent
*
i
,
apk_blob_t
blob
)
{
static
const
int
wrap_length
=
80
;
if
(
i
->
x
+
blob
.
len
+
1
>=
wrap_length
)
{
i
->
x
=
i
->
indent
;
printf
(
"
\n
%*s"
,
i
->
indent
-
1
,
""
);
}
i
->
x
+=
printf
(
" %.*s"
,
blob
.
len
,
blob
.
ptr
);
return
0
;
}
void
apk_print_indented_words
(
struct
apk_indent
*
i
,
const
char
*
text
)
{
apk_blob_for_each_segment
(
APK_BLOB_STR
(
text
),
" "
,
(
apk_blob_cb
)
apk_print_indented
,
i
);
}
const
char
*
apk_error_str
(
int
error
)
{
if
(
error
<
0
)
error
=
-
error
;
switch
(
error
)
{
case
ENOKEY
:
return
"UNTRUSTED signature"
;
case
EKEYREJECTED
:
return
"BAD signature"
;
case
EIO
:
return
"IO ERROR"
;
case
EBADMSG
:
return
"BAD archive"
;
case
ENOMSG
:
return
"archive does not contain expected data"
;
default:
return
strerror
(
error
);
}
}
void
apk_log
(
const
char
*
prefix
,
const
char
*
format
,
...)
{
va_list
va
;
if
(
prefix
!=
NULL
)
fprintf
(
stderr
,
"%s"
,
prefix
);
va_start
(
va
,
format
);
vfprintf
(
stderr
,
format
,
va
);
va_end
(
va
);
fprintf
(
stderr
,
"
\n
"
);
}
src/state.c
View file @
3ec82a5a
...
...
@@ -16,6 +16,7 @@
#include "apk_state.h"
#include "apk_database.h"
#include "apk_print.h"
struct
apk_name_choices
{
unsigned
short
refs
,
num
;
...
...
src/update.c
View file @
3ec82a5a
...
...
@@ -14,6 +14,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_version.h"
#include "apk_print.h"
static
int
update_main
(
void
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
{
...
...
src/upgrade.c
View file @
3ec82a5a
...
...
@@ -15,6 +15,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_state.h"
#include "apk_print.h"
static
int
upgrade_parse
(
void
*
ctx
,
struct
apk_db_options
*
dbopts
,
int
optch
,
int
optindex
,
const
char
*
optarg
)
...
...
src/ver.c
View file @
3ec82a5a
...
...
@@ -14,6 +14,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_version.h"
#include "apk_print.h"
struct
ver_ctx
{
int
(
*
action
)(
struct
apk_database
*
db
,
int
argc
,
char
**
argv
);
...
...
src/verify.c
View file @
3ec82a5a
...
...
@@ -15,6 +15,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_print.h"
static
int
verify_main
(
void
*
ctx
,
struct
apk_database
*
db
,
int
argc
,
char
**
argv
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment