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
981bc118
Commit
981bc118
authored
Jul 14, 2009
by
Timo Teräs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db: live with sha1 and md5
this also convers scripts file to a tar archive.
parent
e9eaedff
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
371 additions
and
159 deletions
+371
-159
src/add.c
src/add.c
+2
-1
src/apk.c
src/apk.c
+0
-2
src/apk_archive.h
src/apk_archive.h
+2
-1
src/apk_blob.h
src/apk_blob.h
+44
-0
src/apk_csum.h
src/apk_csum.h
+0
-49
src/apk_database.h
src/apk_database.h
+8
-6
src/apk_io.h
src/apk_io.h
+4
-3
src/apk_package.h
src/apk_package.h
+4
-2
src/archive.c
src/archive.c
+82
-9
src/audit.c
src/audit.c
+5
-3
src/blob.c
src/blob.c
+49
-0
src/cache.c
src/cache.c
+12
-11
src/database.c
src/database.c
+140
-58
src/io.c
src/io.c
+9
-5
src/package.c
src/package.c
+10
-9
No files found.
src/add.c
View file @
981bc118
...
...
@@ -103,7 +103,8 @@ static int add_main(void *ctx, int argc, char **argv)
goto
err
;
}
virtpkg
->
name
=
apk_db_get_name
(
&
db
,
APK_BLOB_STR
(
actx
->
virtpkg
));
csum_blob
(
APK_BLOB_STR
(
virtpkg
->
name
->
name
),
virtpkg
->
csum
);
apk_blob_checksum
(
APK_BLOB_STR
(
virtpkg
->
name
->
name
),
apk_default_checksum
(),
&
virtpkg
->
csum
);
virtpkg
->
version
=
strdup
(
"0"
);
virtpkg
->
description
=
strdup
(
"virtual meta package"
);
virtdep
=
apk_dep_from_pkg
(
&
db
,
virtpkg
);
...
...
src/apk.c
View file @
981bc118
...
...
@@ -23,9 +23,7 @@
#include "apk_defines.h"
#include "apk_applet.h"
#include "apk_blob.h"
#include "apk_csum.h"
csum_t
bad_checksum
=
{
0
};
const
char
*
apk_root
;
struct
apk_repository_url
apk_repository_list
;
int
apk_verbosity
=
1
,
apk_cwd_fd
,
apk_wait
;
...
...
src/apk_archive.h
View file @
981bc118
...
...
@@ -4,7 +4,7 @@
* 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
* 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.
*/
...
...
@@ -22,6 +22,7 @@ typedef int (*apk_archive_entry_parser)(void *ctx,
int
apk_parse_tar
(
struct
apk_istream
*
,
apk_archive_entry_parser
parser
,
void
*
ctx
);
int
apk_parse_tar_gz
(
struct
apk_bstream
*
,
apk_archive_entry_parser
parser
,
void
*
ctx
);
int
apk_write_tar_entry
(
struct
apk_ostream
*
,
const
struct
apk_file_info
*
ae
,
char
*
data
);
int
apk_archive_entry_extract
(
const
struct
apk_file_info
*
ae
,
struct
apk_istream
*
is
,
...
...
src/apk_blob.h
View file @
981bc118
...
...
@@ -13,6 +13,8 @@
#define APK_BLOB_H
#include <string.h>
#include <openssl/evp.h>
#include "apk_defines.h"
struct
apk_blob
{
...
...
@@ -22,10 +24,38 @@ struct apk_blob {
typedef
struct
apk_blob
apk_blob_t
;
typedef
int
(
*
apk_blob_cb
)(
void
*
ctx
,
apk_blob_t
blob
);
#define APK_CHECKSUM_NONE 0
#define APK_CHECKSUM_MD5 16
#define APK_CHECKSUM_SHA1 20
/* Internal cointainer for MD5 or SHA1 */
struct
apk_checksum
{
unsigned
char
data
[
20
];
unsigned
char
type
;
};
static
inline
const
EVP_MD
*
apk_default_checksum
(
void
)
{
return
EVP_sha1
();
}
static
inline
const
EVP_MD
*
apk_get_digest
(
int
type
)
{
switch
(
type
)
{
case
APK_CHECKSUM_MD5
:
return
EVP_md5
();
case
APK_CHECKSUM_SHA1
:
return
EVP_sha1
();
}
return
EVP_md_null
();
}
#define APK_BLOB_IS_NULL(blob) ((blob).ptr == NULL)
#define APK_BLOB_NULL ((apk_blob_t){0, NULL})
#define APK_BLOB_BUF(buf) ((apk_blob_t){sizeof(buf), (char *)(buf)})
#define APK_BLOB_CSUM(csum) ((apk_blob_t){(csum).type, (char *)(csum).data})
#define APK_BLOB_STRUCT(s) ((apk_blob_t){sizeof(s), (char*)&(s)})
#define APK_BLOB_PTR_LEN(beg,len) ((apk_blob_t){(len), (beg)})
#define APK_BLOB_PTR_PTR(beg,end) APK_BLOB_PTR_LEN((beg),(end)-(beg)+1)
...
...
@@ -47,12 +77,26 @@ int apk_blob_compare(apk_blob_t a, apk_blob_t b);
int
apk_blob_for_each_segment
(
apk_blob_t
blob
,
const
char
*
split
,
apk_blob_cb
cb
,
void
*
ctx
);
static
inline
void
apk_blob_checksum
(
apk_blob_t
b
,
const
EVP_MD
*
md
,
struct
apk_checksum
*
csum
)
{
csum
->
type
=
EVP_MD_size
(
md
);
EVP_Digest
(
b
.
ptr
,
b
.
len
,
csum
->
data
,
NULL
,
md
,
NULL
);
}
static
inline
const
int
apk_checksum_compare
(
const
struct
apk_checksum
*
a
,
const
struct
apk_checksum
*
b
)
{
return
apk_blob_compare
(
APK_BLOB_PTR_LEN
((
char
*
)
a
->
data
,
a
->
type
),
APK_BLOB_PTR_LEN
((
char
*
)
b
->
data
,
b
->
type
));
}
void
apk_blob_push_blob
(
apk_blob_t
*
to
,
apk_blob_t
literal
);
void
apk_blob_push_uint
(
apk_blob_t
*
to
,
unsigned
int
value
,
int
radix
);
void
apk_blob_push_csum
(
apk_blob_t
*
to
,
struct
apk_checksum
*
csum
);
void
apk_blob_push_hexdump
(
apk_blob_t
*
to
,
apk_blob_t
binary
);
void
apk_blob_pull_char
(
apk_blob_t
*
b
,
int
expected
);
unsigned
int
apk_blob_pull_uint
(
apk_blob_t
*
b
,
int
radix
);
void
apk_blob_pull_csum
(
apk_blob_t
*
b
,
struct
apk_checksum
*
csum
);
void
apk_blob_pull_hexdump
(
apk_blob_t
*
b
,
apk_blob_t
to
);
#endif
src/apk_csum.h
deleted
100644 → 0
View file @
e9eaedff
/* apk_csum.c - Alpine Package Keeper (APK)
*
* Copyright (C) 2009 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_CSUM_H
#define APK_CSUM_H
#include <openssl/evp.h>
#define MAX_CSUM_SIZE 16
/* MD5 */
typedef
unsigned
char
*
csum_p
;
typedef
unsigned
char
csum_t
[
MAX_CSUM_SIZE
];
typedef
EVP_MD_CTX
csum_ctx_t
;
extern
csum_t
bad_checksum
;
static
inline
void
csum_init
(
csum_ctx_t
*
ctx
)
{
EVP_DigestInit
(
ctx
,
EVP_md5
());
}
static
inline
void
csum_process
(
csum_ctx_t
*
ctx
,
unsigned
char
*
buf
,
size_t
len
)
{
EVP_DigestUpdate
(
ctx
,
buf
,
len
);
}
static
inline
void
csum_finish
(
csum_ctx_t
*
ctx
,
csum_p
csum
)
{
EVP_DigestFinal
(
ctx
,
csum
,
NULL
);
}
static
inline
int
csum_valid
(
csum_p
csum
)
{
return
memcmp
(
csum
,
bad_checksum
,
MAX_CSUM_SIZE
);
}
static
inline
void
csum_blob
(
apk_blob_t
blob
,
csum_p
csum
)
{
EVP_Digest
(
blob
.
ptr
,
blob
.
len
,
csum
,
NULL
,
EVP_md5
(),
NULL
);
}
#endif
src/apk_database.h
View file @
981bc118
...
...
@@ -17,7 +17,8 @@
#include "apk_archive.h"
#include "apk_package.h"
#define APK_MAX_REPOS 32
#define APK_MAX_REPOS 32
#define APK_CACHE_CSUM_BYTES 4
extern
const
char
*
const
apk_index_gz
;
...
...
@@ -29,8 +30,8 @@ struct apk_db_file {
struct
hlist_node
diri_files_list
;
struct
apk_db_dir_instance
*
diri
;
csum_t
csum
;
unsigned
short
namelen
;
struct
apk_checksum
csum
;
char
name
[];
};
...
...
@@ -73,7 +74,7 @@ struct apk_name {
struct
apk_repository
{
char
*
url
;
csum_t
url_
csum
;
struct
apk_checksum
csum
;
};
struct
apk_database
{
...
...
@@ -135,7 +136,7 @@ int apk_db_cache_active(struct apk_database *db);
struct
apk_package
*
apk_db_pkg_add_file
(
struct
apk_database
*
db
,
const
char
*
file
);
struct
apk_package
*
apk_db_pkg_add
(
struct
apk_database
*
db
,
struct
apk_package
*
pkg
);
struct
apk_package
*
apk_db_get_pkg
(
struct
apk_database
*
db
,
csum_t
sum
);
struct
apk_package
*
apk_db_get_pkg
(
struct
apk_database
*
db
,
struct
apk_checksum
*
c
sum
);
struct
apk_package
*
apk_db_get_file_owner
(
struct
apk_database
*
db
,
apk_blob_t
filename
);
int
apk_db_index_read
(
struct
apk_database
*
db
,
struct
apk_bstream
*
bs
,
int
repo
);
...
...
@@ -143,9 +144,10 @@ int apk_db_index_write(struct apk_database *db, struct apk_ostream *os);
int
apk_db_add_repository
(
apk_database_t
db
,
apk_blob_t
repository
);
int
apk_repository_update
(
struct
apk_database
*
db
,
struct
apk_repository
*
repo
);
int
apk_cache_download
(
struct
apk_database
*
db
,
csum_t
csum
,
int
apk_cache_download
(
struct
apk_database
*
db
,
struct
apk_checksum
*
csum
,
const
char
*
url
,
const
char
*
item
);
int
apk_cache_exists
(
struct
apk_database
*
db
,
csum_t
csum
,
const
char
*
item
);
int
apk_cache_exists
(
struct
apk_database
*
db
,
struct
apk_checksum
*
csum
,
const
char
*
item
);
int
apk_db_install_pkg
(
struct
apk_database
*
db
,
struct
apk_package
*
oldpkg
,
...
...
src/apk_io.h
View file @
981bc118
...
...
@@ -11,9 +11,10 @@
#ifndef APK_IO
#define APK_IO
#include <openssl/evp.h>
#include "apk_defines.h"
#include "apk_blob.h"
#include "apk_csum.h"
struct
apk_file_info
{
char
*
name
;
...
...
@@ -26,7 +27,7 @@ struct apk_file_info {
mode_t
mode
;
time_t
mtime
;
dev_t
device
;
csum_t
csum
;
struct
apk_checksum
csum
;
};
struct
apk_istream
{
...
...
@@ -83,7 +84,7 @@ size_t apk_ostream_write_string(struct apk_ostream *ostream, const char *string)
apk_blob_t
apk_blob_from_istream
(
struct
apk_istream
*
istream
,
size_t
size
);
apk_blob_t
apk_blob_from_file
(
const
char
*
file
);
int
apk_file_get_info
(
const
char
*
filename
,
struct
apk_file_info
*
fi
);
int
apk_file_get_info
(
const
char
*
filename
,
int
checksum
,
struct
apk_file_info
*
fi
);
int
apk_url_download
(
const
char
*
url
,
const
char
*
file
);
const
char
*
apk_url_local_file
(
const
char
*
url
);
...
...
src/apk_package.h
View file @
981bc118
...
...
@@ -4,7 +4,7 @@
* 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
* 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.
*/
...
...
@@ -52,7 +52,6 @@ APK_ARRAY(apk_dependency_array, struct apk_dependency);
struct
apk_package
{
apk_hash_node
hash_node
;
csum_t
csum
;
unsigned
repos
;
struct
apk_name
*
name
;
char
*
version
;
...
...
@@ -60,6 +59,7 @@ struct apk_package {
struct
apk_dependency_array
*
depends
;
size_t
installed_size
,
size
;
char
*
filename
;
struct
apk_checksum
csum
;
/* for installed packages only */
struct
list_head
installed_pkgs_list
;
...
...
@@ -68,6 +68,8 @@ struct apk_package {
};
APK_ARRAY
(
apk_package_array
,
struct
apk_package
*
);
extern
const
char
*
apk_script_types
[];
int
apk_deps_add
(
struct
apk_dependency_array
**
depends
,
struct
apk_dependency
*
dep
);
void
apk_deps_del
(
struct
apk_dependency_array
**
deps
,
...
...
src/archive.c
View file @
981bc118
...
...
@@ -44,19 +44,34 @@ struct tar_header {
char
padding
[
12
];
/* 500-512 */
};
#define GET_OCTAL(s) get_octal(s, sizeof(s))
#define GET_OCTAL(s) get_octal(s, sizeof(s))
#define PUT_OCTAL(s,v) put_octal(s, sizeof(s), v)
static
int
get_octal
(
char
*
s
,
size_t
l
)
{
apk_blob_t
b
=
APK_BLOB_PTR_LEN
(
s
,
l
);
return
apk_blob_pull_uint
(
&
b
,
8
);
}
static
void
put_octal
(
char
*
s
,
size_t
l
,
size_t
value
)
{
char
*
ptr
=
&
s
[
l
-
1
];
*
(
ptr
--
)
=
'\0'
;
while
(
value
!=
0
&&
ptr
>=
s
)
{
*
(
ptr
--
)
=
'0'
+
(
value
%
8
);
value
/=
8
;
}
while
(
ptr
>=
s
)
*
(
ptr
--
)
=
'0'
;
}
struct
apk_tar_entry_istream
{
struct
apk_istream
is
;
struct
apk_istream
*
tar_is
;
size_t
bytes_left
;
csum_ctx_t
csum_
ctx
;
csum_p
csum
;
EVP_MD_CTX
md
ctx
;
struct
apk_checksum
*
csum
;
};
static
size_t
tar_entry_read
(
void
*
stream
,
void
*
ptr
,
size_t
size
)
...
...
@@ -69,9 +84,11 @@ static size_t tar_entry_read(void *stream, void *ptr, size_t size)
size
=
teis
->
tar_is
->
read
(
teis
->
tar_is
,
ptr
,
size
);
if
(
size
>
0
)
{
teis
->
bytes_left
-=
size
;
csum_process
(
&
teis
->
csum_ctx
,
ptr
,
size
);
if
(
teis
->
bytes_left
==
0
)
csum_finish
(
&
teis
->
csum_ctx
,
teis
->
csum
);
EVP_DigestUpdate
(
&
teis
->
mdctx
,
ptr
,
size
);
if
(
teis
->
bytes_left
==
0
)
{
teis
->
csum
->
type
=
EVP_MD_CTX_size
(
&
teis
->
mdctx
);
EVP_DigestFinal_ex
(
&
teis
->
mdctx
,
teis
->
csum
->
data
,
NULL
);
}
}
return
size
;
}
...
...
@@ -83,13 +100,14 @@ int apk_parse_tar(struct apk_istream *is, apk_archive_entry_parser parser,
struct
apk_tar_entry_istream
teis
=
{
.
is
.
read
=
tar_entry_read
,
.
tar_is
=
is
,
.
csum
=
entry
.
csum
,
.
csum
=
&
entry
.
csum
,
};
struct
tar_header
buf
;
unsigned
long
offset
=
0
;
int
end
=
0
,
r
;
size_t
toskip
;
EVP_MD_CTX_init
(
&
teis
.
mdctx
);
memset
(
&
entry
,
0
,
sizeof
(
entry
));
while
((
r
=
is
->
read
(
is
,
&
buf
,
512
))
==
512
)
{
offset
+=
512
;
...
...
@@ -156,11 +174,11 @@ int apk_parse_tar(struct apk_istream *is, apk_archive_entry_parser parser,
entry
.
name
=
strdup
(
buf
.
name
);
/* callback parser function */
csum_init
(
&
teis
.
csum_ctx
);
EVP_DigestInit_ex
(
&
teis
.
mdctx
,
apk_default_checksum
(),
NULL
);
r
=
parser
(
ctx
,
&
entry
,
&
teis
.
is
);
free
(
entry
.
name
);
if
(
r
!=
0
)
return
r
;
goto
er
r
;
entry
.
name
=
NULL
;
}
...
...
@@ -173,12 +191,67 @@ int apk_parse_tar(struct apk_istream *is, apk_archive_entry_parser parser,
if
(
toskip
!=
0
)
is
->
read
(
is
,
NULL
,
toskip
);
}
EVP_MD_CTX_cleanup
(
&
teis
.
mdctx
);
if
(
r
!=
0
)
{
apk_error
(
"Bad TAR header (r=%d)"
,
r
);
return
-
1
;
}
return
0
;
err:
EVP_MD_CTX_cleanup
(
&
teis
.
mdctx
);
return
r
;
}
int
apk_write_tar_entry
(
struct
apk_ostream
*
os
,
const
struct
apk_file_info
*
ae
,
char
*
data
)
{
static
char
padding
[
512
];
struct
tar_header
buf
;
int
pad
;
memset
(
&
buf
,
0
,
sizeof
(
buf
));
if
(
ae
!=
NULL
)
{
const
unsigned
char
*
src
;
int
chksum
,
i
;
if
(
S_ISREG
(
ae
->
mode
))
buf
.
typeflag
=
'0'
;
else
return
-
1
;
strncpy
(
buf
.
name
,
ae
->
name
,
sizeof
(
buf
.
name
));
strncpy
(
buf
.
uname
,
ae
->
uname
,
sizeof
(
buf
.
uname
));
strncpy
(
buf
.
gname
,
ae
->
gname
,
sizeof
(
buf
.
gname
));
PUT_OCTAL
(
buf
.
size
,
ae
->
size
);
PUT_OCTAL
(
buf
.
uid
,
ae
->
uid
);
PUT_OCTAL
(
buf
.
gid
,
ae
->
gid
);
PUT_OCTAL
(
buf
.
mode
,
ae
->
mode
&
07777
);
PUT_OCTAL
(
buf
.
mtime
,
ae
->
mtime
);
/* Checksum */
strcpy
(
buf
.
magic
,
"ustar "
);
memset
(
buf
.
chksum
,
' '
,
sizeof
(
buf
.
chksum
));
src
=
(
const
unsigned
char
*
)
&
buf
;
for
(
i
=
chksum
=
0
;
i
<
sizeof
(
buf
);
i
++
)
chksum
+=
src
[
i
];
put_octal
(
buf
.
chksum
,
sizeof
(
buf
.
chksum
)
-
1
,
chksum
);
}
if
(
os
->
write
(
os
,
&
buf
,
sizeof
(
buf
))
!=
sizeof
(
buf
))
return
-
1
;
if
(
data
!=
NULL
)
{
if
(
os
->
write
(
os
,
data
,
ae
->
size
)
!=
ae
->
size
)
return
-
1
;
pad
=
512
-
(
ae
->
size
&
511
);
if
(
pad
!=
512
&&
os
->
write
(
os
,
padding
,
pad
)
!=
pad
)
return
-
1
;
}
return
0
;
}
...
...
src/audit.c
View file @
981bc118
...
...
@@ -46,7 +46,7 @@ static int audit_directory(apk_hash_item item, void *ctx)
snprintf
(
tmp
,
sizeof
(
tmp
),
"%s/%s"
,
dbd
->
name
,
de
->
d_name
);
if
(
apk_file_get_info
(
tmp
,
&
fi
)
<
0
)
if
(
apk_file_get_info
(
tmp
,
APK_CHECKSUM_NONE
,
&
fi
)
<
0
)
continue
;
if
(
S_ISDIR
(
fi
.
mode
))
{
...
...
@@ -57,8 +57,10 @@ static int audit_directory(apk_hash_item item, void *ctx)
}
else
{
dbf
=
apk_db_file_query
(
db
,
bdir
,
APK_BLOB_STR
(
de
->
d_name
));
if
(
dbf
!=
NULL
)
{
if
(
apk_blob_compare
(
APK_BLOB_BUF
(
fi
.
csum
),
APK_BLOB_BUF
(
dbf
->
csum
))
==
0
)
if
(
apk_file_get_info
(
tmp
,
dbf
->
csum
.
type
,
&
fi
)
<
0
)
continue
;
if
(
apk_checksum_compare
(
&
fi
.
csum
,
&
dbf
->
csum
)
==
0
)
continue
;
reason
=
'U'
;
...
...
src/blob.c
View file @
981bc118
...
...
@@ -186,6 +186,30 @@ void apk_blob_push_uint(apk_blob_t *to, unsigned int value, int radix)
apk_blob_push_blob
(
to
,
APK_BLOB_PTR_PTR
(
ptr
+
1
,
&
buf
[
sizeof
(
buf
)
-
1
]));
}
static
int
checksum_char_to_id
(
char
chr
)
{
switch
(
chr
)
{
case
'1'
:
return
APK_CHECKSUM_SHA1
;
}
return
APK_CHECKSUM_NONE
;
}
void
apk_blob_push_csum
(
apk_blob_t
*
to
,
struct
apk_checksum
*
csum
)
{
switch
(
csum
->
type
)
{
case
APK_CHECKSUM_MD5
:
apk_blob_push_hexdump
(
to
,
APK_BLOB_CSUM
(
*
csum
));
break
;
case
APK_CHECKSUM_SHA1
:
apk_blob_push_blob
(
to
,
APK_BLOB_STR
(
"X1"
));
apk_blob_push_hexdump
(
to
,
APK_BLOB_CSUM
(
*
csum
));
break
;
default:
*
to
=
APK_BLOB_NULL
;
break
;
}
}
void
apk_blob_push_hexdump
(
apk_blob_t
*
to
,
apk_blob_t
binary
)
{
char
*
d
;
...
...
@@ -239,6 +263,31 @@ unsigned int apk_blob_pull_uint(apk_blob_t *b, int radix)
return
val
;
}
void
apk_blob_pull_csum
(
apk_blob_t
*
b
,
struct
apk_checksum
*
csum
)
{
if
(
unlikely
(
APK_BLOB_IS_NULL
(
*
b
)))
return
;
if
(
unlikely
(
b
->
len
<
2
))
{
*
b
=
APK_BLOB_NULL
;
return
;
}
switch
(
b
->
ptr
[
0
])
{
case
'X'
:
csum
->
type
=
checksum_char_to_id
(
b
->
ptr
[
1
]);
b
->
ptr
+=
2
;
b
->
len
-=
2
;
apk_blob_pull_hexdump
(
b
,
APK_BLOB_CSUM
(
*
csum
));
break
;
default:
/* Assume MD5 for backwards compatibility */
csum
->
type
=
APK_CHECKSUM_MD5
;
apk_blob_pull_hexdump
(
b
,
APK_BLOB_CSUM
(
*
csum
));
break
;
}
}
void
apk_blob_pull_hexdump
(
apk_blob_t
*
b
,
apk_blob_t
to
)
{
char
*
s
,
*
d
;
...
...
src/cache.c
View file @
981bc118
...
...
@@ -46,13 +46,13 @@ static int cache_download(struct apk_database *db)
pkg
=
change
->
newpkg
;
snprintf
(
pkgfile
,
sizeof
(
pkgfile
),
"%s-%s.apk"
,
pkg
->
name
->
name
,
pkg
->
version
);
if
(
apk_cache_exists
(
db
,
pkg
->
csum
,
pkgfile
))
if
(
apk_cache_exists
(
db
,
&
pkg
->
csum
,
pkgfile
))
continue
;
for
(
i
=
0
;
i
<
db
->
num_repos
;
i
++
)
{
if
(
!
(
pkg
->
repos
&
BIT
(
i
)))
continue
;
r
=
apk_cache_download
(
db
,
pkg
->
csum
,
db
->
repos
[
i
].
url
,
r
=
apk_cache_download
(
db
,
&
pkg
->
csum
,
db
->
repos
[
i
].
url
,
pkgfile
);
if
(
r
!=
0
)
return
r
;
...
...
@@ -68,11 +68,9 @@ static int cache_clean(struct apk_database *db)
{
DIR
*
dir
;
struct
dirent
*
de
;
struct
apk_package
*
pkg
;
char
path
[
256
];
char
path
[
256
],
csum
[
APK_CACHE_CSUM_BYTES
];
int
delete
,
i
;
apk_blob_t
b
;
csum_t
csum
;
snprintf
(
path
,
sizeof
(
path
),
"%s/%s"
,
db
->
root
,
db
->
cache_dir
);
if
(
chdir
(
path
)
!=
0
)
...
...
@@ -87,24 +85,25 @@ static int cache_clean(struct apk_database *db)
continue
;
delete
=
TRUE
;
do
{
if
(
strlen
(
de
->
d_name
)
<=
sizeof
(
csum_t
)
*
2
+
2
)
if
(
strlen
(
de
->
d_name
)
<=
APK_CACHE_CSUM_BYTES
*
2
+
2
)
break
;
b
=
APK_BLOB_PTR_LEN
(
de
->
d_name
,
sizeof
(
csum_t
)
*
2
);
b
=
APK_BLOB_PTR_LEN
(
de
->
d_name
,
APK_CACHE_CSUM_BYTES
*
2
);
apk_blob_pull_hexdump
(
&
b
,
APK_BLOB_BUF
(
csum
));
if
(
APK_BLOB_IS_NULL
(
b
))
break
;
if
(
de
->
d_name
[
sizeof
(
csum_t
)
*
2
]
!=
'.'
)
if
(
de
->
d_name
[
APK_CACHE_CSUM_BYTES
*
2
]
!=
'.'
)
break
;
if
(
strcmp
(
&
de
->
d_name
[
sizeof
(
csum_t
)
*
2
+
1
],
if
(
strcmp
(
&
de
->
d_name
[
APK_CACHE_CSUM_BYTES
*
2
+
1
],
apk_index_gz
)
==
0
)
{
/* Index - check for matching repository */
for
(
i
=
0
;
i
<
db
->
num_repos
;
i
++
)
if
(
memcmp
(
db
->
repos
[
i
].
url_csum
,
csum
,
sizeof
(
csum_t
)
)
==
0
)
if
(
memcmp
(
db
->
repos
[
i
].
csum
.
data
,
csum
,
APK_CACHE_CSUM_BYTES
)
==
0
)
break
;
delete
=
(
i
>=
db
->
num_repos
);
}
else
{
/* Package - search for it */
#if 0
pkg = apk_db_get_pkg(db, csum);
if (pkg == NULL)
break;
...
...
@@ -113,6 +112,8 @@ static int cache_clean(struct apk_database *db)
pkg->name->name, pkg->version);
delete = strcmp(&de->d_name[sizeof(csum_t)*2+1],
path);
#endif
//#warning FIXME - need to check if cache file is valid - look up using name, check csum
}
}
while
(
0
);
...
...
src/database.c
View file @
981bc118
...
...
@@ -36,7 +36,7 @@ struct install_ctx {
int
script
;
struct
apk_db_dir_instance
*
diri
;
csum_t
data_csum
;
struct
apk_checksum
data_csum
;
apk_progress_cb
cb
;
void
*
cb_ctx
;
...
...
@@ -69,7 +69,7 @@ static const struct apk_hash_ops pkg_name_hash_ops = {
static
apk_blob_t
pkg_info_get_key
(
apk_hash_item
item
)
{
return
APK_BLOB_
BUF
(((
struct
apk_package
*
)
item
)
->
csum
);
return
APK_BLOB_
CSUM
(((
struct
apk_package
*
)
item
)
->
csum
);
}
static
unsigned
long
csum_hash
(
apk_blob_t
csum
)
...
...
@@ -372,7 +372,7 @@ struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *
{
struct
apk_package
*
idb
;
idb
=
apk_hash_get
(
&
db
->
available
.
packages
,
APK_BLOB_
BUF
(
pkg
->
csum
));
idb
=
apk_hash_get
(
&
db
->
available
.
packages
,
APK_BLOB_
CSUM
(
pkg
->
csum
));
if
(
idb
==
NULL
)
{
idb
=
pkg
;
apk_hash_insert
(
&
db
->
available
.
packages
,
pkg
);
...
...
@@ -473,8 +473,7 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
apk_error
(
"FDB checksum entry before file entry"
);
return
-
1
;
}
apk_blob_pull_hexdump
(
&
l
,
APK_BLOB_BUF
(
file
->
csum
));
apk_blob_pull_csum
(
&
l
,
&
file
->
csum
);
break
;
default:
apk_error
(
"FDB entry '%c' unsupported"
,
field
);
...
...
@@ -518,9 +517,9 @@ static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os)
hlist_for_each_entry
(
file
,
c2
,
&
diri
->
owned_files
,
diri_files_list
)
{
apk_blob_push_blob
(
&
bbuf
,
APK_BLOB_STR
(
"R:"
));
apk_blob_push_blob
(
&
bbuf
,
APK_BLOB_PTR_LEN
(
file
->
name
,
file
->
namelen
));
if
(
csum_valid
(
file
->
csum
)
)
{
if
(
file
->
csum
.
type
!=
APK_CHECKSUM_NONE
)
{
apk_blob_push_blob
(
&
bbuf
,
APK_BLOB_STR
(
"
\n
Z:"
));
apk_blob_push_
hexdump
(
&
bbuf
,
APK_BLOB_BUF
(
file
->
csum
)
);
apk_blob_push_
csum
(
&
bbuf
,
&
file
->
csum
);
}
apk_blob_push_blob
(
&
bbuf
,
APK_BLOB_STR
(
"
\n
"
));
...
...
@@ -538,50 +537,118 @@ static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os)
return
0
;
}
struct
apk_script_header
{
csum_t
csum
;
unsigned
int
type
;
unsigned
int
size
;
};
static
int
apk_db_scriptdb_write
(
struct
apk_database
*
db
,
struct
apk_ostream
*
os
)
{
struct
apk_package
*
pkg
;
struct
apk_script
*
script
;
struct
apk_script_header
hdr
;
struct
hlist_node
*
c2
;
struct
apk_file_info
fi
;
char
filename
[
256
];
apk_blob_t
bfn
;
int
r
,
i
;
list_for_each_entry
(
pkg
,
&
db
->
installed
.
packages
,
installed_pkgs_list
)
{
hlist_for_each_entry
(
script
,
c2
,
&
pkg
->
scripts
,
script_list
)
{
memcpy