forked from vieter-v/vieter
Failed attempt at fixing memory bug
parent
01d961f68e
commit
f1a17cab22
|
@ -126,6 +126,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
|
||||||
|
|
||||||
mut buf := voidptr(0)
|
mut buf := voidptr(0)
|
||||||
mut files := []string{}
|
mut files := []string{}
|
||||||
|
mut pkg_info := PkgInfo{}
|
||||||
|
|
||||||
for C.archive_read_next_header(a, &entry) == C.ARCHIVE_OK {
|
for C.archive_read_next_header(a, &entry) == C.ARCHIVE_OK {
|
||||||
pathname := C.archive_entry_pathname(entry)
|
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?
|
// TODO can this unsafe block be avoided?
|
||||||
buf = unsafe { malloc(size) }
|
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 {
|
} else {
|
||||||
C.archive_read_data_skip(a)
|
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))
|
pkg_info.csize = i64(os.file_size(pkg_path))
|
||||||
|
|
||||||
return Pkg{
|
return Pkg{
|
||||||
|
|
|
@ -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
|
// add_from_path adds a package from an arbitrary path & moves it into the pkgs
|
||||||
// directory if necessary.
|
// directory if necessary.
|
||||||
pub fn (r &Repo) add_from_path(pkg_path string) ?bool {
|
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) ?
|
added := r.add(pkg) ?
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ fn (r &Repo) pkg_path(pkg &package.Pkg) string {
|
||||||
|
|
||||||
// Re-generate the repo archive files
|
// Re-generate the repo archive files
|
||||||
fn (r &Repo) sync() ? {
|
fn (r &Repo) sync() ? {
|
||||||
|
lock r.mutex {
|
||||||
a := C.archive_write_new()
|
a := C.archive_write_new()
|
||||||
entry := C.archive_entry_new()
|
entry := C.archive_entry_new()
|
||||||
st := C.stat{}
|
st := C.stat{}
|
||||||
|
@ -110,7 +111,8 @@ fn (r &Repo) sync() ? {
|
||||||
C.archive_write_open_filename(a, &char(repo_path.str))
|
C.archive_write_open_filename(a, &char(repo_path.str))
|
||||||
|
|
||||||
// Iterate over each directory
|
// 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')
|
inner_path := os.join_path_single(d, 'desc')
|
||||||
actual_path := os.join_path_single(r.repo_dir, inner_path)
|
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_close(a)
|
||||||
C.archive_write_free(a)
|
C.archive_write_free(a)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ fn (mut app App) put_package() web.Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
added := app.repo.add_from_path(pkg_path) or {
|
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.')
|
return app.text('Failed to add package.')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue