Failed attempt at fixing memory bug
ci/woodpecker/push/builder unknown status Details
ci/woodpecker/push/publish unknown status Details
ci/woodpecker/push/image Pipeline was successful Details
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/build Pipeline was successful Details

pull/48/head
Jef Roosens 2022-01-20 19:39:38 +01:00
parent 01d961f68e
commit f1a17cab22
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
3 changed files with 51 additions and 40 deletions

View File

@ -126,6 +126,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
mut buf := voidptr(0)
mut files := []string{}
mut pkg_info := PkgInfo{}
for C.archive_read_next_header(a, &entry) == C.ARCHIVE_OK {
pathname := C.archive_entry_pathname(entry)
@ -142,14 +143,21 @@ pub fn read_pkg(pkg_path string) ?Pkg {
// TODO can this unsafe block be avoided?
buf = unsafe { malloc(size) }
C.archive_read_data(a, voidptr(buf), size)
C.archive_read_data(a, buf, size)
unsafe {
println(cstring_to_vstring(buf))
}
pkg_info = parse_pkg_info_string(unsafe { cstring_to_vstring(buf) }) ?
unsafe {
free(buf)
}
} else {
C.archive_read_data_skip(a)
}
}
mut pkg_info := parse_pkg_info_string(unsafe { cstring_to_vstring(&char(buf)) }) ?
pkg_info.csize = i64(os.file_size(pkg_path))
return Pkg{

View File

@ -45,7 +45,7 @@ pub fn new(repo_dir string, pkg_dir string) ?Repo {
// add_from_path adds a package from an arbitrary path & moves it into the pkgs
// directory if necessary.
pub fn (r &Repo) add_from_path(pkg_path string) ?bool {
pkg := package.read_pkg(pkg_path) or { return error('Failed to read package file.') }
pkg := package.read_pkg(pkg_path) or { return error('Failed to read package file: $err.msg') }
added := r.add(pkg) ?
@ -96,6 +96,7 @@ fn (r &Repo) pkg_path(pkg &package.Pkg) string {
// Re-generate the repo archive files
fn (r &Repo) sync() ? {
lock r.mutex {
a := C.archive_write_new()
entry := C.archive_entry_new()
st := C.stat{}
@ -110,7 +111,8 @@ fn (r &Repo) sync() ? {
C.archive_write_open_filename(a, &char(repo_path.str))
// Iterate over each directory
for d in os.ls(r.repo_dir) ?.filter(os.is_dir(os.join_path_single(r.repo_dir, it))) {
for d in os.ls(r.repo_dir) ?.filter(os.is_dir(os.join_path_single(r.repo_dir,
it))) {
inner_path := os.join_path_single(d, 'desc')
actual_path := os.join_path_single(r.repo_dir, inner_path)
@ -139,4 +141,5 @@ fn (r &Repo) sync() ? {
C.archive_write_close(a)
C.archive_write_free(a)
}
}

View File

@ -74,7 +74,7 @@ fn (mut app App) put_package() web.Result {
}
added := app.repo.add_from_path(pkg_path) or {
app.lerror('Error while adding package.')
app.lerror('Error while adding package: $err.msg')
return app.text('Failed to add package.')
}