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{
|
||||||
|
|
75
src/repo.v
75
src/repo.v
|
@ -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,47 +96,50 @@ 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() ? {
|
||||||
a := C.archive_write_new()
|
lock r.mutex {
|
||||||
entry := C.archive_entry_new()
|
a := C.archive_write_new()
|
||||||
st := C.stat{}
|
entry := C.archive_entry_new()
|
||||||
buf := [8192]byte{}
|
st := C.stat{}
|
||||||
|
buf := [8192]byte{}
|
||||||
|
|
||||||
// This makes the archive a gzip-compressed tarball
|
// This makes the archive a gzip-compressed tarball
|
||||||
C.archive_write_add_filter_gzip(a)
|
C.archive_write_add_filter_gzip(a)
|
||||||
C.archive_write_set_format_pax_restricted(a)
|
C.archive_write_set_format_pax_restricted(a)
|
||||||
|
|
||||||
repo_path := os.join_path_single(r.repo_dir, 'repo.db')
|
repo_path := os.join_path_single(r.repo_dir, 'repo.db')
|
||||||
|
|
||||||
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,
|
||||||
inner_path := os.join_path_single(d, 'desc')
|
it))) {
|
||||||
actual_path := os.join_path_single(r.repo_dir, inner_path)
|
inner_path := os.join_path_single(d, 'desc')
|
||||||
|
actual_path := os.join_path_single(r.repo_dir, inner_path)
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
C.stat(&char(actual_path.str), &st)
|
C.stat(&char(actual_path.str), &st)
|
||||||
|
}
|
||||||
|
|
||||||
|
C.archive_entry_set_pathname(entry, &char(inner_path.str))
|
||||||
|
C.archive_entry_copy_stat(entry, &st)
|
||||||
|
// C.archive_entry_set_size(entry, st.st_size)
|
||||||
|
// C.archive_entry_set_filetype(entry, C.AE_IFREG)
|
||||||
|
// C.archive_entry_set_perm(entry, 0o644)
|
||||||
|
C.archive_write_header(a, entry)
|
||||||
|
|
||||||
|
fd := C.open(&char(actual_path.str), C.O_RDONLY)
|
||||||
|
mut len := C.read(fd, &buf, sizeof(buf))
|
||||||
|
|
||||||
|
for len > 0 {
|
||||||
|
C.archive_write_data(a, &buf, len)
|
||||||
|
len = C.read(fd, &buf, sizeof(buf))
|
||||||
|
}
|
||||||
|
C.close(fd)
|
||||||
|
|
||||||
|
C.archive_entry_clear(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
C.archive_entry_set_pathname(entry, &char(inner_path.str))
|
C.archive_write_close(a)
|
||||||
C.archive_entry_copy_stat(entry, &st)
|
C.archive_write_free(a)
|
||||||
// C.archive_entry_set_size(entry, st.st_size)
|
|
||||||
// C.archive_entry_set_filetype(entry, C.AE_IFREG)
|
|
||||||
// C.archive_entry_set_perm(entry, 0o644)
|
|
||||||
C.archive_write_header(a, entry)
|
|
||||||
|
|
||||||
fd := C.open(&char(actual_path.str), C.O_RDONLY)
|
|
||||||
mut len := C.read(fd, &buf, sizeof(buf))
|
|
||||||
|
|
||||||
for len > 0 {
|
|
||||||
C.archive_write_data(a, &buf, len)
|
|
||||||
len = C.read(fd, &buf, sizeof(buf))
|
|
||||||
}
|
|
||||||
C.close(fd)
|
|
||||||
|
|
||||||
C.archive_entry_clear(entry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
C.archive_write_close(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