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
Gitlab has been upgraded to v13.9
🎉
. Enjoy
Open sidebar
alpine
apk-tools
Commits
1a7f3e36
Commit
1a7f3e36
authored
Nov 27, 2008
by
Timo Teräs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
various: use apk_istream api
parent
8e23a2ba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
18 deletions
+43
-18
src/apk_blob.h
src/apk_blob.h
+2
-0
src/apk_io.h
src/apk_io.h
+1
-0
src/database.c
src/database.c
+11
-18
src/io.c
src/io.c
+29
-0
No files found.
src/apk_blob.h
View file @
1a7f3e36
...
...
@@ -20,6 +20,8 @@ struct apk_blob {
};
typedef
struct
apk_blob
apk_blob_t
;
#define APK_BLOB_IS_NULL(blob) (blob.ptr == NULL)
#define APK_BLOB_NULL ((apk_blob_t){0, NULL})
#define APK_BLOB_STR(str) ((apk_blob_t){strlen(str), (str)})
#define APK_BLOB_BUF(buf) ((apk_blob_t){sizeof(buf), (char *)(buf)})
...
...
src/apk_io.h
View file @
1a7f3e36
...
...
@@ -47,5 +47,6 @@ struct apk_bstream *apk_bstream_from_istream(struct apk_istream *istream);
struct
apk_bstream
*
apk_bstream_from_fd
(
int
fd
);
apk_blob_t
apk_blob_from_istream
(
struct
apk_istream
*
istream
,
size_t
size
);
apk_blob_t
apk_blob_from_file
(
const
char
*
file
);
#endif
src/database.c
View file @
1a7f3e36
...
...
@@ -244,7 +244,7 @@ static struct apk_db_file *apk_db_file_get(struct apk_database *db,
return
file
;
}
static
int
apk_db_read_fdb
(
struct
apk_database
*
db
,
int
fd
)
static
int
apk_db_read_fdb
(
struct
apk_database
*
db
,
struct
apk_istream
*
is
)
{
struct
apk_package
*
pkg
=
NULL
;
struct
apk_db_dir
*
dir
=
NULL
;
...
...
@@ -260,7 +260,7 @@ static int apk_db_read_fdb(struct apk_database *db, int fd)
r
=
APK_BLOB_PTR_LEN
(
buf
,
0
);
while
(
1
)
{
n
=
read
(
fd
,
&
r
.
ptr
[
r
.
len
],
sizeof
(
buf
)
-
r
.
len
);
n
=
is
->
read
(
is
,
&
r
.
ptr
[
r
.
len
],
sizeof
(
buf
)
-
r
.
len
);
if
(
n
<=
0
)
break
;
r
.
len
+=
n
;
...
...
@@ -450,9 +450,7 @@ int apk_db_create(const char *root)
static
int
apk_db_read_state
(
struct
apk_database
*
db
)
{
struct
apk_istream
*
is
;
struct
stat
st
;
char
*
buf
;
int
fd
;
apk_blob_t
blob
;
if
(
db
->
root
==
NULL
)
return
0
;
...
...
@@ -467,23 +465,18 @@ static int apk_db_read_state(struct apk_database *db)
*/
fchdir
(
db
->
root_fd
);
fd
=
open
(
"var/lib/apk/world"
,
O_RDONLY
);
if
(
fd
<
0
)
{
blob
=
apk_blob_from_file
(
"var/lib/apk/world"
);
if
(
APK_BLOB_IS_NULL
(
blob
)
)
{
apk_error
(
"Please run 'apk create' to initialize root"
);
return
-
1
;
}
apk_deps_parse
(
db
,
&
db
->
world
,
blob
);
free
(
blob
.
ptr
);
fstat
(
fd
,
&
st
);
buf
=
malloc
(
st
.
st_size
);
read
(
fd
,
buf
,
st
.
st_size
);
apk_deps_parse
(
db
,
&
db
->
world
,
APK_BLOB_PTR_LEN
(
buf
,
st
.
st_size
));
close
(
fd
);
fd
=
open
(
"var/lib/apk/files"
,
O_RDONLY
);
if
(
fd
>=
0
)
{
apk_db_read_fdb
(
db
,
fd
);
close
(
fd
);
is
=
apk_istream_from_file
(
"var/lib/apk/files"
);
if
(
is
!=
NULL
)
{
apk_db_read_fdb
(
db
,
is
);
is
->
close
(
is
);
}
is
=
apk_istream_from_file
(
"var/lib/apk/scripts"
);
...
...
src/io.c
View file @
1a7f3e36
...
...
@@ -305,6 +305,35 @@ apk_blob_t apk_blob_from_istream(struct apk_istream *is, size_t size)
return
APK_BLOB_PTR_LEN
(
ptr
,
rsize
);
}
apk_blob_t
apk_blob_from_file
(
const
char
*
file
)
{
int
fd
;
struct
stat
st
;
char
*
buf
;
fd
=
open
(
file
,
O_RDONLY
);
if
(
fd
<
0
)
return
APK_BLOB_NULL
;
if
(
fstat
(
fd
,
&
st
)
<
0
)
goto
err_fd
;
buf
=
malloc
(
st
.
st_size
);
if
(
buf
==
NULL
)
goto
err_fd
;
if
(
read
(
fd
,
buf
,
st
.
st_size
)
!=
st
.
st_size
)
goto
err_read
;
close
(
fd
);
return
APK_BLOB_PTR_LEN
(
buf
,
st
.
st_size
);
err_read:
free
(
buf
);
err_fd:
close
(
fd
);
return
APK_BLOB_NULL
;
}
int
apk_file_get_info
(
const
char
*
filename
,
struct
apk_file_info
*
fi
)
{
struct
stat
st
;
...
...
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