Working .PKGINFO read function!
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
parent
fd334d93a2
commit
f49992d452
|
@ -1,7 +1,11 @@
|
||||||
*.c
|
*.c
|
||||||
data/
|
data/
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
vieter
|
vieter
|
||||||
vieter-prod
|
dvieter
|
||||||
|
pvieter
|
||||||
|
vieter.c
|
||||||
|
|
||||||
# Ignore testing files
|
# Ignore testing files
|
||||||
*.pkg*
|
*.pkg*
|
||||||
|
|
23
Makefile
23
Makefile
|
@ -10,17 +10,24 @@ LARCHIVE_LIB := $(LARCHIVE_DIR)/libarchive/libarchive.so
|
||||||
# V := LDFLAGS=$(PWD)/$(LARCHIVE_LIB) v -cflags '-I$(PWD)/$(LARCHIVE_DIR) -I $(PWD)/$(LARCHIVE_DIR)'
|
# V := LDFLAGS=$(PWD)/$(LARCHIVE_LIB) v -cflags '-I$(PWD)/$(LARCHIVE_DIR) -I $(PWD)/$(LARCHIVE_DIR)'
|
||||||
V := v
|
V := v
|
||||||
|
|
||||||
|
all: vieter
|
||||||
|
|
||||||
# =====COMPILATION=====
|
# =====COMPILATION=====
|
||||||
.PHONY: debug
|
# Regular binary
|
||||||
debug: vieter
|
|
||||||
vieter: $(SOURCES)
|
vieter: $(SOURCES)
|
||||||
$(V) -cg -o vieter $(SRC_DIR)
|
$(V) -g -o vieter $(SRC_DIR)
|
||||||
|
|
||||||
|
# Debug build using gcc
|
||||||
|
.PHONY: debug
|
||||||
|
debug: dvieter
|
||||||
|
dvieter: $(SOURCES)
|
||||||
|
$(V) -keepc -cg -cc gcc -o dvieter $(SRC_DIR)
|
||||||
|
|
||||||
|
# Optimised production build
|
||||||
.PHONY: prod
|
.PHONY: prod
|
||||||
prod: vieter-prod
|
prod: pvieter
|
||||||
vieter-prod: $(SOURCES)
|
pvieter: $(SOURCES)
|
||||||
$(V) -o vieter-prod -prod $(SRC_DIR)
|
$(V) -o pvieter -prod $(SRC_DIR)
|
||||||
|
|
||||||
.PHONY: c
|
.PHONY: c
|
||||||
c:
|
c:
|
||||||
|
@ -30,7 +37,7 @@ c:
|
||||||
# =====EXECUTION=====
|
# =====EXECUTION=====
|
||||||
# Run the server in the default 'data' directory
|
# Run the server in the default 'data' directory
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run: debug
|
run: vieter
|
||||||
API_KEY=test REPO_DIR=data LOG_LEVEL=DEBUG ./vieter
|
API_KEY=test REPO_DIR=data LOG_LEVEL=DEBUG ./vieter
|
||||||
|
|
||||||
.PHONY: run-prod
|
.PHONY: run-prod
|
||||||
|
@ -69,4 +76,4 @@ $(LARCHIVE_LIB):
|
||||||
'$(MAKE)' -C "libarchive-${LARCHIVE_VER}"
|
'$(MAKE)' -C "libarchive-${LARCHIVE_VER}"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf '$(LARCHIVE_DIR)' 'data' 'vieter' 'vieter-prod'
|
rm -rf '$(LARCHIVE_DIR)' 'data' 'vieter' 'dvieter' 'pvieter' 'vieter.c'
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
module archive
|
module archive
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
#flag -larchive
|
#flag -larchive
|
||||||
#include "archive.h"
|
#include "archive.h"
|
||||||
#include "archive_entry.h"
|
#include "archive_entry.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
struct C.archive {}
|
struct C.archive {}
|
||||||
|
|
||||||
|
@ -10,66 +13,75 @@ struct C.archive_entry {}
|
||||||
|
|
||||||
// Create a new archive struct
|
// Create a new archive struct
|
||||||
fn C.archive_read_new() &C.archive
|
fn C.archive_read_new() &C.archive
|
||||||
|
fn C.archive_entry_new() &C.archive_entry
|
||||||
fn C.archive_read_support_filter_all(&C.archive)
|
fn C.archive_read_support_filter_all(&C.archive)
|
||||||
fn C.archive_read_support_format_all(&C.archive)
|
fn C.archive_read_support_format_all(&C.archive)
|
||||||
|
// Open an archive for reading
|
||||||
fn C.archive_read_open_filename(&C.archive, &char, int) int
|
fn C.archive_read_open_filename(&C.archive, &char, int) int
|
||||||
fn C.archive_read_next_header(&C.archive, &&C.archive_entry) int
|
fn C.archive_read_next_header(&C.archive, &&C.archive_entry) int
|
||||||
|
fn C.archive_read_next_header2(&C.archive, &C.archive_entry) int
|
||||||
fn C.archive_entry_pathname(&C.archive_entry) &char
|
fn C.archive_entry_pathname(&C.archive_entry) &char
|
||||||
fn C.archive_read_data_skip(&C.archive)
|
fn C.archive_read_data_skip(&C.archive)
|
||||||
fn C.archive_read_free(&C.archive) int
|
fn C.archive_read_free(&C.archive) int
|
||||||
fn C.archive_read_data(&C.archive, voidptr, int)
|
fn C.archive_read_data(&C.archive, voidptr, int)
|
||||||
fn C.archive_entry_size(&C.archive_entry) int
|
fn C.archive_entry_size(&C.archive_entry) int
|
||||||
|
|
||||||
pub fn list_filenames() {
|
fn C.strcmp(&char, &char) int
|
||||||
a := C.archive_read_new()
|
|
||||||
entry := &C.archive_entry{}
|
|
||||||
mut r := 0
|
|
||||||
|
|
||||||
C.archive_read_support_filter_all(a)
|
// pub fn list_filenames() {
|
||||||
C.archive_read_support_format_all(a)
|
// a := C.archive_read_new()
|
||||||
|
// entry := &C.archive_entry{}
|
||||||
|
// mut r := 0
|
||||||
|
|
||||||
r = C.archive_read_open_filename(a, c'test/homebank-5.5.1-1-x86_64.pkg.tar.zst', 10240)
|
// C.archive_read_support_filter_all(a)
|
||||||
|
// C.archive_read_support_format_all(a)
|
||||||
|
|
||||||
for (C.archive_read_next_header(a, &entry) == C.ARCHIVE_OK) {
|
// r = C.archive_read_open_filename(a, c'test/homebank-5.5.1-1-x86_64.pkg.tar.zst', 10240)
|
||||||
println(cstring_to_vstring(C.archive_entry_pathname(entry)))
|
|
||||||
C.archive_read_data_skip(a) // Note 2
|
|
||||||
}
|
|
||||||
|
|
||||||
r = C.archive_read_free(a) // Note 3
|
// for (C.archive_read_next_header(a, &entry) == C.ARCHIVE_OK) {
|
||||||
}
|
// println(cstring_to_vstring(C.archive_entry_pathname(entry)))
|
||||||
|
// C.archive_read_data_skip(a) // Note 2
|
||||||
|
// }
|
||||||
|
|
||||||
|
// r = C.archive_read_free(a) // Note 3
|
||||||
|
// }
|
||||||
|
|
||||||
pub fn get_pkg_info(pkg_path string) ?string {
|
pub fn get_pkg_info(pkg_path string) ?string {
|
||||||
|
if !os.is_file(pkg_path) {
|
||||||
|
return error("'$pkg_path' doesn't exist or isn't a file.")
|
||||||
|
}
|
||||||
|
|
||||||
a := C.archive_read_new()
|
a := C.archive_read_new()
|
||||||
entry := &C.archive_entry{}
|
entry := C.archive_entry_new()
|
||||||
mut r := 0
|
mut r := 0
|
||||||
|
|
||||||
C.archive_read_support_filter_all(a)
|
C.archive_read_support_filter_all(a)
|
||||||
C.archive_read_support_format_all(a)
|
C.archive_read_support_format_all(a)
|
||||||
|
|
||||||
// TODO find out where does this 10240 come from
|
// TODO find out where does this 10240 come from
|
||||||
println('1')
|
|
||||||
r = C.archive_read_open_filename(a, &char(pkg_path.str), 10240)
|
r = C.archive_read_open_filename(a, &char(pkg_path.str), 10240)
|
||||||
|
defer {
|
||||||
|
C.archive_read_free(a)
|
||||||
|
}
|
||||||
|
|
||||||
if r != C.ARCHIVE_OK {
|
if r != C.ARCHIVE_OK {
|
||||||
return error('Failed to open package.')
|
return error('Failed to open package.')
|
||||||
}
|
}
|
||||||
|
|
||||||
println('2')
|
|
||||||
// We iterate over every header in search of the .PKGINFO one
|
// We iterate over every header in search of the .PKGINFO one
|
||||||
mut buf := []byte{}
|
mut buf := voidptr(0)
|
||||||
for C.archive_read_next_header(a, &entry) == C.ARCHIVE_OK {
|
for C.archive_read_next_header(a, &entry) == C.ARCHIVE_OK {
|
||||||
// TODO possibly avoid this cstring_to_vstring
|
if C.strcmp(C.archive_entry_pathname(entry), c'.PKGINFO') == 0 {
|
||||||
if cstring_to_vstring(C.archive_entry_pathname(entry)) == '.PKGINFO' {
|
|
||||||
size := C.archive_entry_size(entry)
|
size := C.archive_entry_size(entry)
|
||||||
|
|
||||||
buf = []byte{len: size}
|
// TODO can this unsafe block be avoided?
|
||||||
C.archive_read_data(a, voidptr(&buf), size)
|
buf = unsafe { malloc(size) }
|
||||||
|
C.archive_read_data(a, voidptr(buf), size)
|
||||||
break
|
break
|
||||||
}else{
|
}else{
|
||||||
C.archive_read_data_skip(a)
|
C.archive_read_data_skip(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = C.archive_read_free(a) // Note 3
|
return unsafe { cstring_to_vstring(&char(buf)) }
|
||||||
return buf.bytestr()
|
|
||||||
}
|
}
|
||||||
|
|
14
src/main.v
14
src/main.v
|
@ -54,7 +54,7 @@ fn reader_to_file(mut reader io.BufferedReader, length int, path string) ? {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main2() {
|
||||||
// Configure logger
|
// Configure logger
|
||||||
log_level_str := os.getenv_opt('LOG_LEVEL') or { 'WARN' }
|
log_level_str := os.getenv_opt('LOG_LEVEL') or { 'WARN' }
|
||||||
log_level := log.level_from_tag(log_level_str) or {
|
log_level := log.level_from_tag(log_level_str) or {
|
||||||
|
@ -95,12 +95,18 @@ fn main() {
|
||||||
logger.info("Created package directory '$repo.pkg_dir()'.")
|
logger.info("Created package directory '$repo.pkg_dir()'.")
|
||||||
}
|
}
|
||||||
|
|
||||||
archive.get_pkg_info('test/homebank-5.5.1-1-x86_64.pkg.tar.zst') or {
|
|
||||||
eprintln(err.msg)
|
|
||||||
}
|
|
||||||
web.run(&App{
|
web.run(&App{
|
||||||
logger: logger
|
logger: logger
|
||||||
api_key: key
|
api_key: key
|
||||||
repo: repo
|
repo: repo
|
||||||
}, port)
|
}, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// archive.list_filenames()
|
||||||
|
info := archive.get_pkg_info('test/jjr-joplin-desktop-2.6.10-4-x86_64.pkg.tar.zst') or {
|
||||||
|
eprintln(err.msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println(info)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue