diff --git a/.woodpecker/.publish.yml b/.woodpecker/.publish.yml index 9e5f39a..6d3b34e 100644 --- a/.woodpecker/.publish.yml +++ b/.woodpecker/.publish.yml @@ -1,7 +1,19 @@ -branches: [main, dev] +# branches: [main, dev] platform: linux/amd64 pipeline: + dryrun: + image: woodpeckerci/plugin-docker-buildx + secrets: [ docker_username, docker_password ] + settings: + repo: chewingbever/vieter + tag: dev + platforms: [ linux/arm/v7, linux/arm64/v8, linux/amd64 ] + dry_run: true + when: + event: pull_request + branch: dev + dev: image: woodpeckerci/plugin-docker-buildx secrets: [ docker_username, docker_password ] diff --git a/src/pkg.v b/src/pkg.v index 8d23b6a..8b1849c 100644 --- a/src/pkg.v +++ b/src/pkg.v @@ -2,6 +2,7 @@ module pkg import time import os +import util #flag -larchive @@ -120,8 +121,8 @@ fn parse_pkg_info_string(pkg_info_str &string) ?PkgInfo { 'arch' { pkg_info.arch = value } 'builddate' { pkg_info.build_date = value.int() } 'packager' { pkg_info.packager = value } - 'md5sum' { pkg_info.md5sum = value } - 'sha256sum' { pkg_info.sha256sum = value } + 'md5sum' { continue } + 'sha256sum' { continue } 'pgpsig' { pkg_info.pgpsig = value } 'pgpsigsize' { pkg_info.pgpsigsize = value.int() } // Array values @@ -192,7 +193,11 @@ pub fn read_pkg(pkg_path string) ?Pkg { } mut pkg_info := parse_pkg_info_string(unsafe { cstring_to_vstring(&char(buf)) }) ? + pkg_info.csize = i64(os.file_size(pkg_path)) + pkg_info.md5sum, pkg_info.sha256sum = util.hash_file(pkg_path) or { + return error('Failed to hash package.') + } return Pkg{ info: pkg_info @@ -225,7 +230,6 @@ pub fn (p &PkgInfo) to_desc() string { desc += format_entry('CSIZE', p.csize.str()) desc += format_entry('ISIZE', p.size.str()) - // TODO calculate these desc += format_entry('MD5SUM', p.md5sum) desc += format_entry('SHA256SUM', p.sha256sum) diff --git a/src/util.v b/src/util.v new file mode 100644 index 0000000..cb17c3f --- /dev/null +++ b/src/util.v @@ -0,0 +1,30 @@ +module util + +import os +import crypto.md5 +import crypto.sha256 + +// hash_file returns the md5 & sha256 hash of a given file +pub fn hash_file(path &string) ?(string, string) { + file := os.open(path) or { return error('Failed to open file.') } + + mut md5sum := md5.new() + mut sha256sum := sha256.new() + + buf_size := i32(1_000_000) + mut buf := []byte{len: buf_size} + mut bytes_left := os.file_size(path) + + for bytes_left > 0 { + // TODO check if just breaking here is safe + bytes_read := file.read(mut buf) or { break } + bytes_left -= u64(bytes_read) + + if bytes_left > buf_size { + md5sum.write(buf) + sha256sum.write(buf) + } + } + + return md5sum.sum(buf).hex(), sha256sum.sum(buf).hex() +}