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
0a131418
Commit
0a131418
authored
Jun 17, 2013
by
Timo Teräs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
print: move progress printing to common functions
parent
92764088
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
39 deletions
+46
-39
src/apk.c
src/apk.c
+1
-1
src/apk_database.h
src/apk_database.h
+2
-2
src/apk_print.h
src/apk_print.h
+7
-1
src/commit.c
src/commit.c
+4
-34
src/database.c
src/database.c
+0
-1
src/print.c
src/print.c
+32
-0
No files found.
src/apk.c
View file @
0a131418
...
...
@@ -386,7 +386,7 @@ int main(int argc, char **argv)
apk_flags
&=
~
APK_PROGRESS
;
break
;
case
0x10f
:
dbopts
.
progress_fd
=
atoi
(
optarg
);
apk_
progress_fd
=
atoi
(
optarg
);
break
;
case
0x102
:
apk_flags
|=
APK_CLEAN_PROTECTED
;
...
...
src/apk_database.h
View file @
0a131418
...
...
@@ -107,7 +107,7 @@ struct apk_repository_list {
};
struct
apk_db_options
{
int
lock_wait
,
progress_fd
;
int
lock_wait
;
unsigned
long
open_flags
;
char
*
root
;
char
*
arch
;
...
...
@@ -129,7 +129,7 @@ struct apk_repository_tag {
struct
apk_database
{
char
*
root
;
int
root_fd
,
lock_fd
,
cache_fd
,
keys_fd
,
progress_fd
;
int
root_fd
,
lock_fd
,
cache_fd
,
keys_fd
;
unsigned
num_repos
,
num_repo_tags
;
const
char
*
cache_dir
;
char
*
cache_remount_dir
;
...
...
src/apk_print.h
View file @
0a131418
...
...
@@ -18,6 +18,8 @@
#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)
extern
int
apk_progress_fd
;
void
apk_log
(
const
char
*
prefix
,
const
char
*
format
,
...);
const
char
*
apk_error_str
(
int
error
);
...
...
@@ -29,7 +31,11 @@ struct apk_indent {
int
indent
;
};
int
apk_print_indented
(
struct
apk_indent
*
i
,
apk_blob_t
blob
);
#define APK_PRINT_PROGRESS_MASK 0xff
#define APK_PRINT_PROGRESS_FORCE 0x100
void
apk_print_progress
(
int
percent
);
int
apk_print_indented
(
struct
apk_indent
*
i
,
apk_blob_t
blob
);
void
apk_print_indented_words
(
struct
apk_indent
*
i
,
const
char
*
text
);
void
apk_print_indented_fmt
(
struct
apk_indent
*
i
,
const
char
*
fmt
,
...);
...
...
src/commit.c
View file @
0a131418
...
...
@@ -118,43 +118,12 @@ static void count_change(struct apk_change *change, struct apk_stats *stats)
}
}
static
void
draw_progress
(
int
percent
)
{
const
int
bar_width
=
apk_get_screen_width
()
-
7
;
int
i
;
fprintf
(
stderr
,
"\e7%3i%% ["
,
percent
);
for
(
i
=
0
;
i
<
bar_width
*
percent
/
100
;
i
++
)
fputc
(
'#'
,
stderr
);
for
(;
i
<
bar_width
;
i
++
)
fputc
(
' '
,
stderr
);
fputc
(
']'
,
stderr
);
fflush
(
stderr
);
fputs
(
"\e8\e[0K"
,
stderr
);
}
struct
progress
{
struct
apk_stats
done
;
struct
apk_stats
total
;
struct
apk_package
*
pkg
;
size_t
percent
;
int
progress_fd
;
};
static
void
update_progress
(
struct
progress
*
prog
,
size_t
percent
,
int
force
)
{
if
(
prog
->
percent
==
percent
&&
!
force
)
return
;
prog
->
percent
=
percent
;
if
(
apk_flags
&
APK_PROGRESS
)
draw_progress
(
percent
);
if
(
prog
->
progress_fd
!=
0
)
{
char
buf
[
8
];
size_t
n
=
snprintf
(
buf
,
sizeof
(
buf
),
"%zu
\n
"
,
percent
);
write
(
prog
->
progress_fd
,
buf
,
n
);
}
}
static
void
progress_cb
(
void
*
ctx
,
size_t
pkg_percent
)
{
struct
progress
*
prog
=
(
struct
progress
*
)
ctx
;
...
...
@@ -168,7 +137,9 @@ static void progress_cb(void *ctx, size_t pkg_percent)
prog
->
total
.
bytes
+
prog
->
total
.
packages
);
else
percent
=
0
;
update_progress
(
prog
,
percent
,
pkg_percent
==
0
);
if
(
pkg_percent
==
0
)
percent
|=
APK_PRINT_PROGRESS_FORCE
;
apk_print_progress
(
percent
);
}
static
int
dump_packages
(
struct
apk_changeset
*
changeset
,
...
...
@@ -279,7 +250,6 @@ int apk_solver_commit_changeset(struct apk_database *db,
/* Count what needs to be done */
memset
(
&
prog
,
0
,
sizeof
(
prog
));
prog
.
progress_fd
=
db
->
progress_fd
;
for
(
i
=
0
;
i
<
changeset
->
changes
->
num
;
i
++
)
{
change
=
&
changeset
->
changes
->
item
[
i
];
count_change
(
change
,
&
prog
.
total
);
...
...
@@ -345,7 +315,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
count_change
(
change
,
&
prog
.
done
);
}
update_progress
(
&
prog
,
100
,
1
);
apk_print_progress
(
100
|
APK_PRINT_PROGRESS_FORCE
);
run_triggers
(
db
,
changeset
);
...
...
src/database.c
View file @
0a131418
...
...
@@ -1453,7 +1453,6 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
int
r
,
fd
,
write_arch
=
FALSE
;
memset
(
db
,
0
,
sizeof
(
*
db
));
db
->
progress_fd
=
dbopts
->
progress_fd
;
if
(
apk_flags
&
APK_SIMULATE
)
{
dbopts
->
open_flags
&=
~
(
APK_OPENF_CREATE
|
APK_OPENF_WRITE
);
dbopts
->
open_flags
|=
APK_OPENF_READ
;
...
...
src/print.c
View file @
0a131418
...
...
@@ -19,6 +19,7 @@
#include "apk_defines.h"
#include "apk_print.h"
int
apk_progress_fd
;
static
int
apk_screen_width
=
0
;
void
apk_reset_screen_width
(
void
)
...
...
@@ -40,6 +41,37 @@ int apk_get_screen_width(void)
return
apk_screen_width
;
}
void
apk_print_progress
(
int
percent_flags
)
{
static
int
last_written
=
0
;
const
int
bar_width
=
apk_get_screen_width
()
-
7
;
char
buf
[
8
];
int
i
,
percent
;
percent
=
percent_flags
&
APK_PRINT_PROGRESS_MASK
;
if
(
last_written
==
percent
&&
!
(
percent_flags
&
APK_PRINT_PROGRESS_FORCE
))
return
;
last_written
=
percent
;
if
(
apk_flags
&
APK_PROGRESS
)
{
fprintf
(
stderr
,
"\e7%3i%% ["
,
percent
);
for
(
i
=
0
;
i
<
bar_width
*
percent
/
100
;
i
++
)
fputc
(
'#'
,
stderr
);
for
(;
i
<
bar_width
;
i
++
)
fputc
(
' '
,
stderr
);
fputc
(
']'
,
stderr
);
fflush
(
stderr
);
fputs
(
"\e8\e[0K"
,
stderr
);
}
if
(
apk_progress_fd
!=
0
)
{
i
=
snprintf
(
buf
,
sizeof
(
buf
),
"%zu
\n
"
,
percent
);
write
(
apk_progress_fd
,
buf
,
i
);
}
}
int
apk_print_indented
(
struct
apk_indent
*
i
,
apk_blob_t
blob
)
{
if
(
i
->
x
+
blob
.
len
+
1
>=
apk_get_screen_width
())
...
...
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