Compare commits

..

No commits in common. "dev" and "agents" have entirely different histories.
dev ... agents

25 changed files with 329 additions and 335 deletions

View File

@ -1,39 +0,0 @@
matrix:
PLATFORM:
- 'linux/amd64'
platform: ${PLATFORM}
when:
branch: [main, dev]
event: [push, tag]
steps:
build:
image: 'git.rustybever.be/chewing_bever/rieter-builder:1.79-alpine3.19'
commands:
- cargo build --verbose --release
- '[ "$(readelf -d target/release/rieterd | grep NEEDED | wc -l)" = 0 ]'
publish-dev:
image: 'git.rustybever.be/chewing_bever/rieter-builder:1.79-alpine3.19'
commands:
- apk add --no-cache minio-client
- mcli alias set rb 'https://s3.rustybever.be' "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY"
- mcli cp target/release/rieterd "rb/rieter/commits/$CI_COMMIT_SHA/rieterd-$(echo '${PLATFORM}' | sed 's:/:-:g')"
secrets:
- minio_access_key
- minio_secret_key
publish-rel:
image: 'curlimages/curl'
commands:
- >
curl -s --fail
--user "Chewing_Bever:$GITEA_PASSWORD"
--upload-file target/release/rieterd
https://git.rustybever.be/api/packages/Chewing_Bever/generic/rieter/"${CI_COMMIT_TAG}"/rieterd-"$(echo '${PLATFORM}' | sed 's:/:-:g')"
secrets:
- gitea_password
when:
event: tag

View File

@ -2,20 +2,13 @@ platform: 'linux/amd64'
when: when:
branch: branch:
exclude: [dev, main] exclude: [main]
event: push event: push
steps: steps:
build: build:
image: 'git.rustybever.be/chewing_bever/rieter-builder:1.79-alpine3.19' image: 'rust:1.70-alpine3.18'
commands: commands:
- apk add --no-cache build-base libarchive libarchive-dev
- cargo build --verbose - cargo build --verbose
# Binaries, even debug ones, should be statically compiled
- '[ "$(readelf -d target/debug/rieterd | grep NEEDED | wc -l)" = 0 ]'
# Clippy also performs a full build, so putting it here saves the CI a
# lot of work
clippy:
image: 'git.rustybever.be/chewing_bever/rieter-builder:1.79-alpine3.19'
commands:
- cargo clippy -- --no-deps -Dwarnings

View File

@ -0,0 +1,13 @@
platform: 'linux/amd64'
when:
branch:
exclude: [main]
event: push
steps:
clippy:
image: 'rust:1.70-alpine3.18'
commands:
- rustup component add clippy
- cargo clippy -- --no-deps -Dwarnings

View File

@ -1,11 +1,11 @@
platform: 'linux/amd64' platform: 'linux/amd64'
when: when:
branch: [main, dev] branch: dev
event: [push, tag] event: push
depends_on: depends_on:
- build-rel - build
steps: steps:
dev: dev:
@ -19,25 +19,4 @@ steps:
tags: tags:
- 'dev' - 'dev'
platforms: [ 'linux/amd64' ] platforms: [ 'linux/amd64' ]
build_args_from_env:
- 'CI_COMMIT_SHA'
mtu: 1300 mtu: 1300
when:
branch: dev
event: push
release:
image: 'woodpeckerci/plugin-docker-buildx'
secrets:
- 'docker_username'
- 'docker_password'
settings:
registry: 'git.rustybever.be'
repo: 'git.rustybever.be/chewing_bever/rieter'
auto_tag: true
platforms: [ 'linux/amd64' ]
build_args_from_env:
- 'CI_COMMIT_SHA'
mtu: 1300
when:
event: tag

View File

@ -7,6 +7,7 @@ when:
steps: steps:
lint: lint:
image: 'git.rustybever.be/chewing_bever/rieter-builder:1.79-alpine3.19' image: 'rust:1.70-alpine3.18'
commands: commands:
- rustup component add rustfmt
- cargo fmt -- --check - cargo fmt -- --check

View File

@ -7,15 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://git.rustybever.be/Chewing_Bever/rieter/src/branch/dev) ## [Unreleased](https://git.rustybever.be/Chewing_Bever/rieter/src/branch/dev)
## [0.1.0](https://git.rustybever.be/Chewing_Bever/rieter/src/tag/0.1.0)
### Added ### Added
* Server
* Functional repository server * Functional repository server
* Supports any number of repositories, grouped into distros, each * Serve packages from any number of repositories & architectures
supporting any number of architectures * Publish packages to and delete packages from repositories using HTTP
requests
* Packages of architecture "any" are part of every architecture's
database
* Bearer authentication for private routes
* REST API
* Repository & package information available using JSON REST API * Repository & package information available using JSON REST API
* Queueing system with configurable number of workers for resilient
concurrency
* TOML configuration file
* SQLite & Postgres support

5
Cargo.lock generated
View File

@ -1670,9 +1670,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.5" version = "1.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -1732,7 +1732,6 @@ dependencies = [
"futures", "futures",
"http-body-util", "http-body-util",
"libarchive", "libarchive",
"regex",
"sea-orm", "sea-orm",
"sea-orm-migration", "sea-orm-migration",
"sea-query", "sea-query",

View File

@ -1,16 +1,16 @@
FROM git.rustybever.be/chewing_bever/rieter-builder:1.79-alpine3.19 AS builder FROM rust:1.70-alpine3.18 AS builder
ARG TARGETPLATFORM
ARG CI_COMMIT_SHA
ARG DI_VER=1.2.5 ARG DI_VER=1.2.5
WORKDIR /app WORKDIR /app
RUN apk add --no-cache \ RUN apk add --no-cache \
build-base \
curl \ curl \
make \ make \
unzip \ unzip \
pkgconf pkgconf \
libarchive libarchive-dev
# Build dumb-init # Build dumb-init
RUN curl -Lo - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.tar.gz" | tar -xzf - && \ RUN curl -Lo - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.tar.gz" | tar -xzf - && \
@ -21,17 +21,33 @@ RUN curl -Lo - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.t
COPY . . COPY . .
RUN curl \ # ENV LIBARCHIVE_STATIC=1 \
--fail \ # LIBARCHIVE_LIB_DIR=/usr/lib \
-o rieterd \ # LIBARCHIVE_INCLUDE_DIR=/usr/include \
"https://s3.rustybever.be/rieter/commits/${CI_COMMIT_SHA}/rieterd-$(echo "${TARGETPLATFORM}" | sed 's:/:-:g')" && \ # LIBARCHIVE_LDFLAGS='-lssl -lcrypto -L/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4'
chmod +x rieterd # LIBARCHIVE_LDFLAGS='-L/usr/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4 -lsqlite3'
# https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
ENV RUSTFLAGS='-C target-feature=-crt-static'
RUN cargo build --release && \
du -h target/release/rieterd && \
readelf -d target/release/rieterd && \
chmod +x target/release/rieterd
FROM alpine:3.19 FROM alpine:3.18
RUN apk add --no-cache \
libgcc \
libarchive \
openssl
COPY --from=builder /app/dumb-init /bin/dumb-init COPY --from=builder /app/dumb-init /bin/dumb-init
COPY --from=builder /app/rieterd /bin/rieterd COPY --from=builder /app/target/release/rieterd /bin/rieterd
ENV RIETER_PKG_DIR=/data/pkgs \
RIETER_DATA_DIR=/data
WORKDIR /data WORKDIR /data

View File

@ -1,20 +0,0 @@
# Command to build and push builder image (change tags as necessary):
# docker buildx build -f build.Dockerfile -t git.rustybever.be/chewing_bever/rieter-builder:1.79-alpine3.19 --platform linux/amd64,linux/arm64 --push .
FROM rust:1.79-alpine3.19
# Dependencies required to statically compile libarchive and libsqlite3
RUN apk add --no-cache \
build-base \
libarchive-static libarchive-dev \
zlib-static \
openssl-libs-static \
bzip2-static \
xz-static \
expat-static \
zstd-static \
lz4-static \
acl-static && \
rustup component add clippy rustfmt
# Tell the libarchive3-sys package to statically link libarchive
ENV LIBARCHIVE_STATIC=1

View File

@ -386,7 +386,6 @@ pub enum ExtractOption {
ClearNoChangeFFlags, ClearNoChangeFFlags,
} }
#[derive(Default)]
pub struct ExtractOptions { pub struct ExtractOptions {
pub flags: i32, pub flags: i32,
} }
@ -421,3 +420,9 @@ impl ExtractOptions {
self self
} }
} }
impl Default for ExtractOptions {
fn default() -> ExtractOptions {
ExtractOptions { flags: 0 }
}
}

View File

@ -78,7 +78,7 @@ impl Builder {
ffi::archive_read_support_filter_program_signature( ffi::archive_read_support_filter_program_signature(
self.handle_mut(), self.handle_mut(),
c_prog.as_ptr(), c_prog.as_ptr(),
mem::transmute::<std::option::Option<extern "C" fn()>, *const std::ffi::c_void>(cb), mem::transmute(cb),
size, size,
) )
} }

View File

@ -41,7 +41,7 @@ impl FileWriter {
unsafe { unsafe {
match ffi::archive_write_header(self.handle_mut(), entry.entry_mut()) { match ffi::archive_write_header(self.handle_mut(), entry.entry_mut()) {
ffi::ARCHIVE_OK => Ok(()), ffi::ARCHIVE_OK => Ok(()),
_ => Err(ArchiveError::from(self as &dyn Handle)), _ => Err(ArchiveError::from(self as &dyn Handle).into()),
} }
} }
} }
@ -50,7 +50,7 @@ impl FileWriter {
unsafe { unsafe {
match ffi::archive_write_header(self.handle_mut(), entry.entry_mut()) { match ffi::archive_write_header(self.handle_mut(), entry.entry_mut()) {
ffi::ARCHIVE_OK => (), ffi::ARCHIVE_OK => (),
_ => return Err(ArchiveError::from(self as &dyn Handle)), _ => return Err(ArchiveError::from(self as &dyn Handle).into()),
} }
} }
@ -74,7 +74,7 @@ impl FileWriter {
// Negative values signal errors // Negative values signal errors
if res < 0 { if res < 0 {
return Err(ArchiveError::from(self as &dyn Handle)); return Err(ArchiveError::from(self as &dyn Handle).into());
} }
written += usize::try_from(res).unwrap(); written += usize::try_from(res).unwrap();

View File

@ -30,12 +30,6 @@ impl Entry for WriteEntry {
} }
} }
impl Default for WriteEntry {
fn default() -> Self {
Self::new()
}
}
impl Drop for WriteEntry { impl Drop for WriteEntry {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ffi::archive_entry_free(self.entry_mut()) } unsafe { ffi::archive_entry_free(self.entry_mut()) }

View File

@ -4,7 +4,3 @@
DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
xcode-select --install xcode-select --install
# 64-bit timestamps
`time_t` has been replaced with `i64` as Musl no longer supports 32-bit `time_t` values.

View File

@ -1,6 +1,35 @@
extern crate pkg_config;
use std::env;
fn main() { fn main() {
pkg_config::Config::new() let lib_dir = env::var("LIBARCHIVE_LIB_DIR").ok();
.atleast_version("3") let include_dir = env::var("LIBARCHIVE_INCLUDE_DIR").ok();
.probe("libarchive")
.unwrap(); if lib_dir.is_some() && include_dir.is_some() {
println!("cargo:rustc-flags=-L native={}", lib_dir.unwrap());
println!("cargo:include={}", include_dir.unwrap());
let mode = match env::var_os("LIBARCHIVE_STATIC") {
Some(_) => "static",
None => "dylib",
};
println!("cargo:rustc-flags=-l {0}=archive", mode);
if mode == "static" {
if let Ok(ldflags) = env::var("LIBARCHIVE_LDFLAGS") {
for token in ldflags.split_whitespace() {
if token.starts_with("-L") {
println!("cargo:rustc-flags=-L native={}", token.replace("-L", ""));
} else if token.starts_with("-l") {
println!("cargo:rustc-flags=-l static={}", token.replace("-l", ""));
}
}
}
}
} else {
match pkg_config::find_library("libarchive") {
Ok(_) => (),
Err(msg) => panic!("Unable to locate libarchive, err={:?}", msg),
}
}
} }

View File

@ -294,10 +294,14 @@ extern "C" {
) -> c_int; ) -> c_int;
pub fn archive_read_extract_set_progress_callback( pub fn archive_read_extract_set_progress_callback(
arg1: *mut Struct_archive, arg1: *mut Struct_archive,
_progress_func: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void)>, _progress_func: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void) -> ()>,
_user_data: *mut c_void, _user_data: *mut c_void,
); ) -> ();
pub fn archive_read_extract_set_skip_file(arg1: *mut Struct_archive, arg2: i64, arg3: i64); pub fn archive_read_extract_set_skip_file(
arg1: *mut Struct_archive,
arg2: i64,
arg3: i64,
) -> ();
pub fn archive_read_close(arg1: *mut Struct_archive) -> c_int; pub fn archive_read_close(arg1: *mut Struct_archive) -> c_int;
pub fn archive_read_free(arg1: *mut Struct_archive) -> c_int; pub fn archive_read_free(arg1: *mut Struct_archive) -> c_int;
pub fn archive_read_finish(arg1: *mut Struct_archive) -> c_int; pub fn archive_read_finish(arg1: *mut Struct_archive) -> c_int;
@ -439,7 +443,7 @@ extern "C" {
arg3: ::std::option::Option< arg3: ::std::option::Option<
unsafe extern "C" fn(arg1: *mut c_void, arg2: *const c_char, arg3: i64) -> i64, unsafe extern "C" fn(arg1: *mut c_void, arg2: *const c_char, arg3: i64) -> i64,
>, >,
arg4: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void)>, arg4: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void) -> ()>,
) -> c_int; ) -> c_int;
pub fn archive_write_disk_set_user_lookup( pub fn archive_write_disk_set_user_lookup(
arg1: *mut Struct_archive, arg1: *mut Struct_archive,
@ -447,7 +451,7 @@ extern "C" {
arg3: ::std::option::Option< arg3: ::std::option::Option<
unsafe extern "C" fn(arg1: *mut c_void, arg2: *const c_char, arg3: i64) -> i64, unsafe extern "C" fn(arg1: *mut c_void, arg2: *const c_char, arg3: i64) -> i64,
>, >,
arg4: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void)>, arg4: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void) -> ()>,
) -> c_int; ) -> c_int;
pub fn archive_write_disk_gid(arg1: *mut Struct_archive, arg2: *const c_char, arg3: i64) pub fn archive_write_disk_gid(arg1: *mut Struct_archive, arg2: *const c_char, arg3: i64)
-> i64; -> i64;
@ -471,7 +475,7 @@ extern "C" {
arg3: ::std::option::Option< arg3: ::std::option::Option<
unsafe extern "C" fn(arg1: *mut c_void, arg2: i64) -> *const c_char, unsafe extern "C" fn(arg1: *mut c_void, arg2: i64) -> *const c_char,
>, >,
arg4: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void)>, arg4: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void) -> ()>,
) -> c_int; ) -> c_int;
pub fn archive_read_disk_set_uname_lookup( pub fn archive_read_disk_set_uname_lookup(
arg1: *mut Struct_archive, arg1: *mut Struct_archive,
@ -479,7 +483,7 @@ extern "C" {
arg3: ::std::option::Option< arg3: ::std::option::Option<
unsafe extern "C" fn(arg1: *mut c_void, arg2: i64) -> *const c_char, unsafe extern "C" fn(arg1: *mut c_void, arg2: i64) -> *const c_char,
>, >,
arg4: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void)>, arg4: ::std::option::Option<unsafe extern "C" fn(arg1: *mut c_void) -> ()>,
) -> c_int; ) -> c_int;
pub fn archive_read_disk_open(arg1: *mut Struct_archive, arg2: *const c_char) -> c_int; pub fn archive_read_disk_open(arg1: *mut Struct_archive, arg2: *const c_char) -> c_int;
pub fn archive_read_disk_open_w(arg1: *mut Struct_archive, arg2: *const wchar_t) -> c_int; pub fn archive_read_disk_open_w(arg1: *mut Struct_archive, arg2: *const wchar_t) -> c_int;
@ -498,7 +502,7 @@ extern "C" {
arg1: *mut Struct_archive, arg1: *mut Struct_archive,
arg2: *mut c_void, arg2: *mut c_void,
arg3: *mut Struct_archive_entry, arg3: *mut Struct_archive_entry,
), ) -> (),
>, >,
_client_data: *mut c_void, _client_data: *mut c_void,
) -> c_int; ) -> c_int;
@ -525,9 +529,10 @@ extern "C" {
pub fn archive_error_string(arg1: *mut Struct_archive) -> *const c_char; pub fn archive_error_string(arg1: *mut Struct_archive) -> *const c_char;
pub fn archive_format_name(arg1: *mut Struct_archive) -> *const c_char; pub fn archive_format_name(arg1: *mut Struct_archive) -> *const c_char;
pub fn archive_format(arg1: *mut Struct_archive) -> c_int; pub fn archive_format(arg1: *mut Struct_archive) -> c_int;
pub fn archive_clear_error(arg1: *mut Struct_archive); pub fn archive_clear_error(arg1: *mut Struct_archive) -> ();
pub fn archive_set_error(arg1: *mut Struct_archive, _err: c_int, fmt: *const c_char, ...); pub fn archive_set_error(arg1: *mut Struct_archive, _err: c_int, fmt: *const c_char, ...)
pub fn archive_copy_error(dest: *mut Struct_archive, src: *mut Struct_archive); -> ();
pub fn archive_copy_error(dest: *mut Struct_archive, src: *mut Struct_archive) -> ();
pub fn archive_file_count(arg1: *mut Struct_archive) -> c_int; pub fn archive_file_count(arg1: *mut Struct_archive) -> c_int;
pub fn archive_match_new() -> *mut Struct_archive; pub fn archive_match_new() -> *mut Struct_archive;
pub fn archive_match_free(arg1: *mut Struct_archive) -> c_int; pub fn archive_match_free(arg1: *mut Struct_archive) -> c_int;
@ -585,7 +590,7 @@ extern "C" {
pub fn archive_match_include_time( pub fn archive_match_include_time(
arg1: *mut Struct_archive, arg1: *mut Struct_archive,
_flag: c_int, _flag: c_int,
_sec: i64, _sec: time_t,
_nsec: c_long, _nsec: c_long,
) -> c_int; ) -> c_int;
pub fn archive_match_include_date( pub fn archive_match_include_date(
@ -625,16 +630,16 @@ extern "C" {
pub fn archive_match_include_gname_w(arg1: *mut Struct_archive, arg2: *const wchar_t) -> c_int; pub fn archive_match_include_gname_w(arg1: *mut Struct_archive, arg2: *const wchar_t) -> c_int;
pub fn archive_entry_clear(arg1: *mut Struct_archive_entry) -> *mut Struct_archive_entry; pub fn archive_entry_clear(arg1: *mut Struct_archive_entry) -> *mut Struct_archive_entry;
pub fn archive_entry_clone(arg1: *mut Struct_archive_entry) -> *mut Struct_archive_entry; pub fn archive_entry_clone(arg1: *mut Struct_archive_entry) -> *mut Struct_archive_entry;
pub fn archive_entry_free(arg1: *mut Struct_archive_entry); pub fn archive_entry_free(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_new() -> *mut Struct_archive_entry; pub fn archive_entry_new() -> *mut Struct_archive_entry;
pub fn archive_entry_new2(arg1: *mut Struct_archive) -> *mut Struct_archive_entry; pub fn archive_entry_new2(arg1: *mut Struct_archive) -> *mut Struct_archive_entry;
pub fn archive_entry_atime(arg1: *mut Struct_archive_entry) -> i64; pub fn archive_entry_atime(arg1: *mut Struct_archive_entry) -> time_t;
pub fn archive_entry_atime_nsec(arg1: *mut Struct_archive_entry) -> c_long; pub fn archive_entry_atime_nsec(arg1: *mut Struct_archive_entry) -> c_long;
pub fn archive_entry_atime_is_set(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_atime_is_set(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_birthtime(arg1: *mut Struct_archive_entry) -> i64; pub fn archive_entry_birthtime(arg1: *mut Struct_archive_entry) -> time_t;
pub fn archive_entry_birthtime_nsec(arg1: *mut Struct_archive_entry) -> c_long; pub fn archive_entry_birthtime_nsec(arg1: *mut Struct_archive_entry) -> c_long;
pub fn archive_entry_birthtime_is_set(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_birthtime_is_set(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_ctime(arg1: *mut Struct_archive_entry) -> i64; pub fn archive_entry_ctime(arg1: *mut Struct_archive_entry) -> time_t;
pub fn archive_entry_ctime_nsec(arg1: *mut Struct_archive_entry) -> c_long; pub fn archive_entry_ctime_nsec(arg1: *mut Struct_archive_entry) -> c_long;
pub fn archive_entry_ctime_is_set(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_ctime_is_set(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_dev(arg1: *mut Struct_archive_entry) -> dev_t; pub fn archive_entry_dev(arg1: *mut Struct_archive_entry) -> dev_t;
@ -646,7 +651,7 @@ extern "C" {
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *mut c_ulong, arg2: *mut c_ulong,
arg3: *mut c_ulong, arg3: *mut c_ulong,
); ) -> ();
pub fn archive_entry_fflags_text(arg1: *mut Struct_archive_entry) -> *const c_char; pub fn archive_entry_fflags_text(arg1: *mut Struct_archive_entry) -> *const c_char;
pub fn archive_entry_gid(arg1: *mut Struct_archive_entry) -> i64; pub fn archive_entry_gid(arg1: *mut Struct_archive_entry) -> i64;
pub fn archive_entry_gname(arg1: *mut Struct_archive_entry) -> *const c_char; pub fn archive_entry_gname(arg1: *mut Struct_archive_entry) -> *const c_char;
@ -657,7 +662,7 @@ extern "C" {
pub fn archive_entry_ino64(arg1: *mut Struct_archive_entry) -> i64; pub fn archive_entry_ino64(arg1: *mut Struct_archive_entry) -> i64;
pub fn archive_entry_ino_is_set(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_ino_is_set(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_mode(arg1: *mut Struct_archive_entry) -> mode_t; pub fn archive_entry_mode(arg1: *mut Struct_archive_entry) -> mode_t;
pub fn archive_entry_mtime(arg1: *mut Struct_archive_entry) -> i64; pub fn archive_entry_mtime(arg1: *mut Struct_archive_entry) -> time_t;
pub fn archive_entry_mtime_nsec(arg1: *mut Struct_archive_entry) -> c_long; pub fn archive_entry_mtime_nsec(arg1: *mut Struct_archive_entry) -> c_long;
pub fn archive_entry_mtime_is_set(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_mtime_is_set(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_nlink(arg1: *mut Struct_archive_entry) -> c_uint; pub fn archive_entry_nlink(arg1: *mut Struct_archive_entry) -> c_uint;
@ -677,17 +682,33 @@ extern "C" {
pub fn archive_entry_uid(arg1: *mut Struct_archive_entry) -> i64; pub fn archive_entry_uid(arg1: *mut Struct_archive_entry) -> i64;
pub fn archive_entry_uname(arg1: *mut Struct_archive_entry) -> *const c_char; pub fn archive_entry_uname(arg1: *mut Struct_archive_entry) -> *const c_char;
pub fn archive_entry_uname_w(arg1: *mut Struct_archive_entry) -> *const wchar_t; pub fn archive_entry_uname_w(arg1: *mut Struct_archive_entry) -> *const wchar_t;
pub fn archive_entry_set_atime(arg1: *mut Struct_archive_entry, arg2: i64, arg3: c_long); pub fn archive_entry_set_atime(
pub fn archive_entry_unset_atime(arg1: *mut Struct_archive_entry); arg1: *mut Struct_archive_entry,
pub fn archive_entry_set_birthtime(arg1: *mut Struct_archive_entry, arg2: i64, arg3: c_long); arg2: time_t,
pub fn archive_entry_unset_birthtime(arg1: *mut Struct_archive_entry); arg3: c_long,
pub fn archive_entry_set_ctime(arg1: *mut Struct_archive_entry, arg2: i64, arg3: c_long); ) -> ();
pub fn archive_entry_unset_ctime(arg1: *mut Struct_archive_entry); pub fn archive_entry_unset_atime(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_set_dev(arg1: *mut Struct_archive_entry, arg2: dev_t); pub fn archive_entry_set_birthtime(
pub fn archive_entry_set_devmajor(arg1: *mut Struct_archive_entry, arg2: dev_t); arg1: *mut Struct_archive_entry,
pub fn archive_entry_set_devminor(arg1: *mut Struct_archive_entry, arg2: dev_t); arg2: time_t,
pub fn archive_entry_set_filetype(arg1: *mut Struct_archive_entry, arg2: c_uint); arg3: c_long,
pub fn archive_entry_set_fflags(arg1: *mut Struct_archive_entry, arg2: c_ulong, arg3: c_ulong); ) -> ();
pub fn archive_entry_unset_birthtime(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_set_ctime(
arg1: *mut Struct_archive_entry,
arg2: time_t,
arg3: c_long,
) -> ();
pub fn archive_entry_unset_ctime(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_set_dev(arg1: *mut Struct_archive_entry, arg2: dev_t) -> ();
pub fn archive_entry_set_devmajor(arg1: *mut Struct_archive_entry, arg2: dev_t) -> ();
pub fn archive_entry_set_devminor(arg1: *mut Struct_archive_entry, arg2: dev_t) -> ();
pub fn archive_entry_set_filetype(arg1: *mut Struct_archive_entry, arg2: c_uint) -> ();
pub fn archive_entry_set_fflags(
arg1: *mut Struct_archive_entry,
arg2: c_ulong,
arg3: c_ulong,
) -> ();
pub fn archive_entry_copy_fflags_text( pub fn archive_entry_copy_fflags_text(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_char, arg2: *const c_char,
@ -696,60 +717,79 @@ extern "C" {
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const wchar_t, arg2: *const wchar_t,
) -> *const wchar_t; ) -> *const wchar_t;
pub fn archive_entry_set_gid(arg1: *mut Struct_archive_entry, arg2: i64); pub fn archive_entry_set_gid(arg1: *mut Struct_archive_entry, arg2: i64) -> ();
pub fn archive_entry_set_gname(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_set_gname(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_gname(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_copy_gname(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_gname_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t); pub fn archive_entry_copy_gname_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t) -> ();
pub fn archive_entry_update_gname_utf8( pub fn archive_entry_update_gname_utf8(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_char, arg2: *const c_char,
) -> c_int; ) -> c_int;
pub fn archive_entry_set_hardlink(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_set_hardlink(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_hardlink(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_copy_hardlink(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_hardlink_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t); pub fn archive_entry_copy_hardlink_w(
arg1: *mut Struct_archive_entry,
arg2: *const wchar_t,
) -> ();
pub fn archive_entry_update_hardlink_utf8( pub fn archive_entry_update_hardlink_utf8(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_char, arg2: *const c_char,
) -> c_int; ) -> c_int;
pub fn archive_entry_set_ino(arg1: *mut Struct_archive_entry, arg2: i64); pub fn archive_entry_set_ino(arg1: *mut Struct_archive_entry, arg2: i64) -> ();
pub fn archive_entry_set_ino64(arg1: *mut Struct_archive_entry, arg2: i64); pub fn archive_entry_set_ino64(arg1: *mut Struct_archive_entry, arg2: i64) -> ();
pub fn archive_entry_set_link(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_set_link(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_link(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_copy_link(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_link_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t); pub fn archive_entry_copy_link_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t) -> ();
pub fn archive_entry_update_link_utf8( pub fn archive_entry_update_link_utf8(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_char, arg2: *const c_char,
) -> c_int; ) -> c_int;
pub fn archive_entry_set_mode(arg1: *mut Struct_archive_entry, arg2: mode_t); pub fn archive_entry_set_mode(arg1: *mut Struct_archive_entry, arg2: mode_t) -> ();
pub fn archive_entry_set_mtime(arg1: *mut Struct_archive_entry, arg2: i64, arg3: c_long); pub fn archive_entry_set_mtime(
pub fn archive_entry_unset_mtime(arg1: *mut Struct_archive_entry); arg1: *mut Struct_archive_entry,
pub fn archive_entry_set_nlink(arg1: *mut Struct_archive_entry, arg2: c_uint); arg2: time_t,
pub fn archive_entry_set_pathname(arg1: *mut Struct_archive_entry, arg2: *const c_char); arg3: c_long,
pub fn archive_entry_copy_pathname(arg1: *mut Struct_archive_entry, arg2: *const c_char); ) -> ();
pub fn archive_entry_copy_pathname_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t); pub fn archive_entry_unset_mtime(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_set_nlink(arg1: *mut Struct_archive_entry, arg2: c_uint) -> ();
pub fn archive_entry_set_pathname(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_pathname(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_pathname_w(
arg1: *mut Struct_archive_entry,
arg2: *const wchar_t,
) -> ();
pub fn archive_entry_update_pathname_utf8( pub fn archive_entry_update_pathname_utf8(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_char, arg2: *const c_char,
) -> c_int; ) -> c_int;
pub fn archive_entry_set_perm(arg1: *mut Struct_archive_entry, arg2: mode_t); pub fn archive_entry_set_perm(arg1: *mut Struct_archive_entry, arg2: mode_t) -> ();
pub fn archive_entry_set_rdev(arg1: *mut Struct_archive_entry, arg2: dev_t); pub fn archive_entry_set_rdev(arg1: *mut Struct_archive_entry, arg2: dev_t) -> ();
pub fn archive_entry_set_rdevmajor(arg1: *mut Struct_archive_entry, arg2: dev_t); pub fn archive_entry_set_rdevmajor(arg1: *mut Struct_archive_entry, arg2: dev_t) -> ();
pub fn archive_entry_set_rdevminor(arg1: *mut Struct_archive_entry, arg2: dev_t); pub fn archive_entry_set_rdevminor(arg1: *mut Struct_archive_entry, arg2: dev_t) -> ();
pub fn archive_entry_set_size(arg1: *mut Struct_archive_entry, arg2: i64); pub fn archive_entry_set_size(arg1: *mut Struct_archive_entry, arg2: i64) -> ();
pub fn archive_entry_unset_size(arg1: *mut Struct_archive_entry); pub fn archive_entry_unset_size(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_copy_sourcepath(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_copy_sourcepath(
pub fn archive_entry_copy_sourcepath_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t); arg1: *mut Struct_archive_entry,
pub fn archive_entry_set_symlink(arg1: *mut Struct_archive_entry, arg2: *const c_char); arg2: *const c_char,
pub fn archive_entry_copy_symlink(arg1: *mut Struct_archive_entry, arg2: *const c_char); ) -> ();
pub fn archive_entry_copy_symlink_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t); pub fn archive_entry_copy_sourcepath_w(
arg1: *mut Struct_archive_entry,
arg2: *const wchar_t,
) -> ();
pub fn archive_entry_set_symlink(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_symlink(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_symlink_w(
arg1: *mut Struct_archive_entry,
arg2: *const wchar_t,
) -> ();
pub fn archive_entry_update_symlink_utf8( pub fn archive_entry_update_symlink_utf8(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_char, arg2: *const c_char,
) -> c_int; ) -> c_int;
pub fn archive_entry_set_uid(arg1: *mut Struct_archive_entry, arg2: i64); pub fn archive_entry_set_uid(arg1: *mut Struct_archive_entry, arg2: i64) -> ();
pub fn archive_entry_set_uname(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_set_uname(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_uname(arg1: *mut Struct_archive_entry, arg2: *const c_char); pub fn archive_entry_copy_uname(arg1: *mut Struct_archive_entry, arg2: *const c_char) -> ();
pub fn archive_entry_copy_uname_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t); pub fn archive_entry_copy_uname_w(arg1: *mut Struct_archive_entry, arg2: *const wchar_t) -> ();
pub fn archive_entry_update_uname_utf8( pub fn archive_entry_update_uname_utf8(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_char, arg2: *const c_char,
@ -757,7 +797,7 @@ extern "C" {
// pub fn archive_entry_stat(arg1: *mut Struct_archive_entry) -> *const Struct_stat; // pub fn archive_entry_stat(arg1: *mut Struct_archive_entry) -> *const Struct_stat;
// pub fn archive_entry_copy_stat(arg1: *mut Struct_archive_entry, // pub fn archive_entry_copy_stat(arg1: *mut Struct_archive_entry,
// arg2: *const Struct_stat) // arg2: *const Struct_stat)
// ; // -> ();
pub fn archive_entry_mac_metadata( pub fn archive_entry_mac_metadata(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *mut size_t, arg2: *mut size_t,
@ -766,8 +806,8 @@ extern "C" {
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_void, arg2: *const c_void,
arg3: size_t, arg3: size_t,
); ) -> ();
pub fn archive_entry_acl_clear(arg1: *mut Struct_archive_entry); pub fn archive_entry_acl_clear(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_acl_add_entry( pub fn archive_entry_acl_add_entry(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: c_int, arg2: c_int,
@ -808,13 +848,13 @@ extern "C" {
pub fn archive_entry_acl_text(arg1: *mut Struct_archive_entry, arg2: c_int) -> *const c_char; pub fn archive_entry_acl_text(arg1: *mut Struct_archive_entry, arg2: c_int) -> *const c_char;
pub fn archive_entry_acl_count(arg1: *mut Struct_archive_entry, arg2: c_int) -> c_int; pub fn archive_entry_acl_count(arg1: *mut Struct_archive_entry, arg2: c_int) -> c_int;
pub fn archive_entry_acl(arg1: *mut Struct_archive_entry) -> *mut Struct_archive_acl; pub fn archive_entry_acl(arg1: *mut Struct_archive_entry) -> *mut Struct_archive_acl;
pub fn archive_entry_xattr_clear(arg1: *mut Struct_archive_entry); pub fn archive_entry_xattr_clear(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_xattr_add_entry( pub fn archive_entry_xattr_add_entry(
arg1: *mut Struct_archive_entry, arg1: *mut Struct_archive_entry,
arg2: *const c_char, arg2: *const c_char,
arg3: *const c_void, arg3: *const c_void,
arg4: size_t, arg4: size_t,
); ) -> ();
pub fn archive_entry_xattr_count(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_xattr_count(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_xattr_reset(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_xattr_reset(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_xattr_next( pub fn archive_entry_xattr_next(
@ -823,8 +863,12 @@ extern "C" {
arg3: *mut *const c_void, arg3: *mut *const c_void,
arg4: *mut size_t, arg4: *mut size_t,
) -> c_int; ) -> c_int;
pub fn archive_entry_sparse_clear(arg1: *mut Struct_archive_entry); pub fn archive_entry_sparse_clear(arg1: *mut Struct_archive_entry) -> ();
pub fn archive_entry_sparse_add_entry(arg1: *mut Struct_archive_entry, arg2: i64, arg3: i64); pub fn archive_entry_sparse_add_entry(
arg1: *mut Struct_archive_entry,
arg2: i64,
arg3: i64,
) -> ();
pub fn archive_entry_sparse_count(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_sparse_count(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_sparse_reset(arg1: *mut Struct_archive_entry) -> c_int; pub fn archive_entry_sparse_reset(arg1: *mut Struct_archive_entry) -> c_int;
pub fn archive_entry_sparse_next( pub fn archive_entry_sparse_next(
@ -836,13 +880,13 @@ extern "C" {
pub fn archive_entry_linkresolver_set_strategy( pub fn archive_entry_linkresolver_set_strategy(
arg1: *mut Struct_archive_entry_linkresolver, arg1: *mut Struct_archive_entry_linkresolver,
arg2: c_int, arg2: c_int,
); ) -> ();
pub fn archive_entry_linkresolver_free(arg1: *mut Struct_archive_entry_linkresolver); pub fn archive_entry_linkresolver_free(arg1: *mut Struct_archive_entry_linkresolver) -> ();
pub fn archive_entry_linkify( pub fn archive_entry_linkify(
arg1: *mut Struct_archive_entry_linkresolver, arg1: *mut Struct_archive_entry_linkresolver,
arg2: *mut *mut Struct_archive_entry, arg2: *mut *mut Struct_archive_entry,
arg3: *mut *mut Struct_archive_entry, arg3: *mut *mut Struct_archive_entry,
); ) -> ();
pub fn archive_entry_partial_links( pub fn archive_entry_partial_links(
res: *mut Struct_archive_entry_linkresolver, res: *mut Struct_archive_entry_linkresolver,
links: *mut c_uint, links: *mut c_uint,

View File

@ -14,7 +14,6 @@ figment = { version = "0.10.19", features = ["env", "toml"] }
futures = "0.3.28" futures = "0.3.28"
http-body-util = "0.1.1" http-body-util = "0.1.1"
libarchive = { path = "../libarchive" } libarchive = { path = "../libarchive" }
regex = "1.10.5"
sea-orm-migration = "0.12.1" sea-orm-migration = "0.12.1"
sea-query = { version = "0.30.7", features = ["backend-postgres", "backend-sqlite"] } sea-query = { version = "0.30.7", features = ["backend-postgres", "backend-sqlite"] }
serde = { version = "1.0.178", features = ["derive"] } serde = { version = "1.0.178", features = ["derive"] }

View File

@ -88,7 +88,7 @@ pub async fn connect(conn: &DbConfig) -> crate::Result<DbConn> {
} => { } => {
let mut url = format!("postgres://{}:{}@{}:{}/{}", user, password, host, port, db); let mut url = format!("postgres://{}:{}@{}:{}/{}", user, password, host, port, db);
if !schema.is_empty() { if schema != "" {
url = format!("{url}?currentSchema={schema}"); url = format!("{url}?currentSchema={schema}");
} }

View File

@ -4,9 +4,6 @@ use sea_orm::{sea_query::IntoCondition, *};
use sea_query::{Alias, Expr, Query, SelectStatement}; use sea_query::{Alias, Expr, Query, SelectStatement};
use serde::Deserialize; use serde::Deserialize;
/// How many fields may be inserted at once into the database.
const PACKAGE_INSERT_LIMIT: usize = 1000;
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Filter { pub struct Filter {
repo: Option<i32>, repo: Option<i32>,
@ -60,17 +57,17 @@ pub async fn by_id(conn: &DbConn, id: i32) -> Result<Option<package::Model>> {
pub async fn by_fields( pub async fn by_fields(
conn: &DbConn, conn: &DbConn,
repo_id: i32, repo_id: i32,
name: &str,
version: &str,
arch: &str, arch: &str,
compression: &str, name: &str,
version: Option<&str>,
compression: Option<&str>,
) -> Result<Option<package::Model>> { ) -> Result<Option<package::Model>> {
let cond = Condition::all() let cond = Condition::all()
.add(package::Column::RepoId.eq(repo_id)) .add(package::Column::RepoId.eq(repo_id))
.add(package::Column::Name.eq(name)) .add(package::Column::Name.eq(name))
.add(package::Column::Arch.eq(arch)) .add(package::Column::Arch.eq(arch))
.add(package::Column::Version.eq(version)) .add_option(version.map(|version| package::Column::Version.eq(version)))
.add(package::Column::Compression.eq(compression)); .add_option(compression.map(|compression| package::Column::Compression.eq(compression)));
Package::find().filter(cond).one(conn).await Package::find().filter(cond).one(conn).await
} }
@ -163,34 +160,23 @@ pub async fn insert(
.iter() .iter()
.map(|s| (PackageRelatedEnum::Optdepend, s)), .map(|s| (PackageRelatedEnum::Optdepend, s)),
); );
let related = crate::util::Chunked::new(related, PACKAGE_INSERT_LIMIT);
for chunk in related { PackageRelated::insert_many(related.map(|(t, s)| package_related::ActiveModel {
PackageRelated::insert_many(
chunk
.into_iter()
.map(|(t, s)| package_related::ActiveModel {
package_id: Set(pkg_entry.id), package_id: Set(pkg_entry.id),
r#type: Set(t), r#type: Set(t),
name: Set(s.to_string()), name: Set(s.to_string()),
}), }))
)
.on_empty_do_nothing() .on_empty_do_nothing()
.exec(&txn) .exec(&txn)
.await?; .await?;
}
let files = crate::util::Chunked::new(pkg.files, PACKAGE_INSERT_LIMIT); PackageFile::insert_many(pkg.files.iter().map(|s| package_file::ActiveModel {
for chunk in files {
PackageFile::insert_many(chunk.into_iter().map(|s| package_file::ActiveModel {
package_id: Set(pkg_entry.id), package_id: Set(pkg_entry.id),
path: Set(s.display().to_string()), path: Set(s.display().to_string()),
})) }))
.on_empty_do_nothing() .on_empty_do_nothing()
.exec(&txn) .exec(&txn)
.await?; .await?;
}
txn.commit().await?; txn.commit().await?;

View File

@ -3,7 +3,6 @@ mod config;
pub mod db; pub mod db;
mod error; mod error;
mod repo; mod repo;
mod util;
mod web; mod web;
pub use config::{Config, DbConfig, FsConfig}; pub use config::{Config, DbConfig, FsConfig};
@ -16,15 +15,13 @@ use sea_orm_migration::MigratorTrait;
use tokio::runtime; use tokio::runtime;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
pub const ANY_ARCH: &str = "any"; pub const ANY_ARCH: &'static str = "any";
pub const PKG_FILENAME_REGEX: &str = "^([a-z0-9@._+-]+)-((?:[0-9]+:)?[a-zA-Z0-9@._+]+-[0-9]+)-([a-zA-z0-9_]+).pkg.tar.([a-zA-Z0-9]+)$";
#[derive(Clone)] #[derive(Clone)]
pub struct Global { pub struct Global {
config: crate::config::Config, config: crate::config::Config,
repo: repo::Handle, repo: repo::Handle,
db: sea_orm::DbConn, db: sea_orm::DbConn,
pkg_filename_re: regex::Regex,
} }
fn main() -> crate::Result<()> { fn main() -> crate::Result<()> {
@ -81,7 +78,6 @@ fn setup(rt: &runtime::Handle, config_file: PathBuf) -> crate::Result<Global> {
config: config.clone(), config: config.clone(),
repo, repo,
db, db,
pkg_filename_re: regex::Regex::new(PKG_FILENAME_REGEX).unwrap(),
}) })
} }

View File

@ -124,11 +124,7 @@ impl RepoArchivesWriter {
fn write_desc(&self, path: impl AsRef<Path>, pkg: &db::package::Model) -> crate::Result<()> { fn write_desc(&self, path: impl AsRef<Path>, pkg: &db::package::Model) -> crate::Result<()> {
let mut f = std::io::BufWriter::new(std::fs::File::create(path)?); let mut f = std::io::BufWriter::new(std::fs::File::create(path)?);
let filename = format!( writeln!(f, "%FILENAME%\n{}", pkg.id)?;
"{}-{}-{}.pkg.tar.{}",
pkg.name, pkg.version, pkg.arch, pkg.compression
);
writeln!(f, "%FILENAME%\n{}", filename)?;
let mut write_attr = |k: &str, v: &str| { let mut write_attr = |k: &str, v: &str| {
if !v.is_empty() { if !v.is_empty() {
@ -216,8 +212,8 @@ impl RepoArchivesWriter {
self.ar_db.close()?; self.ar_db.close()?;
self.ar_files.close()?; self.ar_files.close()?;
let _ = std::fs::remove_file(&self.tmp_paths[0]); let _ = std::fs::remove_file(&self.tmp_paths[0])?;
let _ = std::fs::remove_file(&self.tmp_paths[1]); let _ = std::fs::remove_file(&self.tmp_paths[1])?;
Ok(()) Ok(())
} }

View File

@ -29,14 +29,12 @@ pub enum Command {
Clean, Clean,
} }
type RepoState = (AtomicU32, Arc<Mutex<()>>);
pub struct SharedState { pub struct SharedState {
pub repos_dir: PathBuf, pub repos_dir: PathBuf,
pub conn: DbConn, pub conn: DbConn,
pub rx: Mutex<UnboundedReceiver<Command>>, pub rx: Mutex<UnboundedReceiver<Command>>,
pub tx: UnboundedSender<Command>, pub tx: UnboundedSender<Command>,
pub repos: RwLock<HashMap<i32, RepoState>>, pub repos: RwLock<HashMap<i32, (AtomicU32, Arc<Mutex<()>>)>>,
} }
impl SharedState { impl SharedState {

View File

@ -13,6 +13,8 @@ use libarchive::{
}; };
use sea_orm::ActiveValue::Set; use sea_orm::ActiveValue::Set;
const IGNORED_FILES: [&str; 5] = [".BUILDINFO", ".INSTALL", ".MTREE", ".PKGINFO", ".CHANGELOG"];
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Package { pub struct Package {
pub path: PathBuf, pub path: PathBuf,
@ -48,18 +50,18 @@ pub struct PkgInfo {
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum InvalidPkgInfoError { pub enum ParsePkgInfoError {
Size, InvalidSize,
BuildDate, InvalidBuildDate,
PgpSigSize, InvalidPgpSigSize,
} }
impl fmt::Display for InvalidPkgInfoError { impl fmt::Display for ParsePkgInfoError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self { let s = match self {
Self::Size => "invalid size", Self::InvalidSize => "invalid size",
Self::BuildDate => "invalid build date", Self::InvalidBuildDate => "invalid build date",
Self::PgpSigSize => "invalid pgp sig size", Self::InvalidPgpSigSize => "invalid pgp sig size",
}; };
write!(f, "{}", s) write!(f, "{}", s)
@ -67,7 +69,7 @@ impl fmt::Display for InvalidPkgInfoError {
} }
impl PkgInfo { impl PkgInfo {
pub fn extend<S: AsRef<str>>(&mut self, line: S) -> Result<(), InvalidPkgInfoError> { pub fn extend<S: AsRef<str>>(&mut self, line: S) -> Result<(), ParsePkgInfoError> {
let line = line.as_ref(); let line = line.as_ref();
if !line.starts_with('#') { if !line.starts_with('#') {
@ -77,21 +79,26 @@ impl PkgInfo {
"pkgbase" => self.base = value.to_string(), "pkgbase" => self.base = value.to_string(),
"pkgver" => self.version = value.to_string(), "pkgver" => self.version = value.to_string(),
"pkgdesc" => self.description = Some(value.to_string()), "pkgdesc" => self.description = Some(value.to_string()),
"size" => self.size = value.parse().map_err(|_| InvalidPkgInfoError::Size)?, "size" => {
self.size = value.parse().map_err(|_| ParsePkgInfoError::InvalidSize)?
}
"url" => self.url = Some(value.to_string()), "url" => self.url = Some(value.to_string()),
"arch" => self.arch = value.to_string(), "arch" => self.arch = value.to_string(),
"builddate" => { "builddate" => {
let seconds: i64 = let seconds: i64 = value
value.parse().map_err(|_| InvalidPkgInfoError::BuildDate)?; .parse()
self.build_date = chrono::DateTime::from_timestamp_millis(seconds * 1000) .map_err(|_| ParsePkgInfoError::InvalidBuildDate)?;
.ok_or(InvalidPkgInfoError::BuildDate)? self.build_date = NaiveDateTime::from_timestamp_millis(seconds * 1000)
.naive_utc(); .ok_or(ParsePkgInfoError::InvalidBuildDate)?
} }
"packager" => self.packager = Some(value.to_string()), "packager" => self.packager = Some(value.to_string()),
"pgpsig" => self.pgpsig = Some(value.to_string()), "pgpsig" => self.pgpsig = Some(value.to_string()),
"pgpsigsize" => { "pgpsigsize" => {
self.pgpsigsize = self.pgpsigsize = Some(
Some(value.parse().map_err(|_| InvalidPkgInfoError::PgpSigSize)?) value
.parse()
.map_err(|_| ParsePkgInfoError::InvalidPgpSigSize)?,
)
} }
"group" => self.groups.push(value.to_string()), "group" => self.groups.push(value.to_string()),
"license" => self.licenses.push(value.to_string()), "license" => self.licenses.push(value.to_string()),
@ -151,9 +158,11 @@ impl Package {
let entry = entry?; let entry = entry?;
let path_name = entry.pathname(); let path_name = entry.pathname();
if !path_name.starts_with('.') { if !IGNORED_FILES.iter().any(|p| p == &path_name) {
files.push(PathBuf::from(path_name)); files.push(PathBuf::from(path_name));
} else if path_name == ".PKGINFO" { }
if path_name == ".PKGINFO" {
info = Some(PkgInfo::parse(entry)?); info = Some(PkgInfo::parse(entry)?);
} }
} }
@ -217,3 +226,10 @@ impl From<Package> for package::ActiveModel {
} }
} }
} }
pub fn filename(pkg: &package::Model) -> String {
format!(
"{}-{}-{}.pkg.tar.{}",
pkg.name, pkg.version, pkg.arch, pkg.compression
)
}

View File

@ -1,23 +0,0 @@
pub struct Chunked<I> {
iter: I,
chunk_size: usize,
}
impl<I: Iterator> Chunked<I> {
pub fn new<T: IntoIterator<IntoIter = I>>(into: T, chunk_size: usize) -> Self {
Self {
iter: into.into_iter(),
chunk_size,
}
}
}
// https://users.rust-lang.org/t/how-to-breakup-an-iterator-into-chunks/87915/5
impl<I: Iterator> Iterator for Chunked<I> {
type Item = Vec<I::Item>;
fn next(&mut self) -> Option<Self::Item> {
Some(self.iter.by_ref().take(self.chunk_size).collect())
.filter(|chunk: &Vec<_>| !chunk.is_empty())
}
}

View File

@ -1,11 +1,11 @@
use crate::{db, FsConfig}; use crate::FsConfig;
use axum::{ use axum::{
body::Body, body::Body,
extract::{Path, State}, extract::{Path, State},
http::{Request, StatusCode}, http::{Request, StatusCode},
response::IntoResponse, response::IntoResponse,
routing::{delete, get, post}, routing::{delete, post},
Router, Router,
}; };
use futures::TryStreamExt; use futures::TryStreamExt;
@ -27,7 +27,12 @@ pub fn router(api_key: &str) -> Router<crate::Global> {
) )
// Routes added after the layer do not get that layer applied, so the GET requests will not // Routes added after the layer do not get that layer applied, so the GET requests will not
// be authorized // be authorized
.route("/:distro/:repo/:arch/:filename", get(get_file)) .route(
"/:distro/:repo/:arch/:filename",
delete(delete_package)
.route_layer(ValidateRequestHeaderLayer::bearer(api_key))
.get(get_file),
)
} }
/// Serve the package archive files and database archives. If files are requested for an /// Serve the package archive files and database archives. If files are requested for an
@ -39,37 +44,23 @@ async fn get_file(
req: Request<Body>, req: Request<Body>,
) -> crate::Result<impl IntoResponse> { ) -> crate::Result<impl IntoResponse> {
if let Some(repo_id) = global.repo.get_repo(&distro, &repo).await? { if let Some(repo_id) = global.repo.get_repo(&distro, &repo).await? {
let file_name = match global.config.fs {
if file_name == format!("{}.db", repo) || file_name == format!("{}.db.tar.gz", repo) { FsConfig::Local { data_dir } => {
let repo_dir = data_dir.join("repos").join(repo_id.to_string());
let file_name = if file_name == format!("{}.db", repo)
|| file_name == format!("{}.db.tar.gz", repo)
{
format!("{}.db.tar.gz", arch) format!("{}.db.tar.gz", arch)
} else if file_name == format!("{}.files", repo) } else if file_name == format!("{}.files", repo)
|| file_name == format!("{}.files.tar.gz", repo) || file_name == format!("{}.files.tar.gz", repo)
{ {
format!("{}.files.tar.gz", arch) format!("{}.files.tar.gz", arch)
} else if let Some(m) = global.pkg_filename_re.captures(&file_name) {
// SAFETY: these unwraps cannot fail if the RegEx matched successfully
db::query::package::by_fields(
&global.db,
repo_id,
m.get(1).unwrap().as_str(),
m.get(2).unwrap().as_str(),
m.get(3).unwrap().as_str(),
m.get(4).unwrap().as_str(),
)
.await?
.ok_or(StatusCode::NOT_FOUND)?
.id
.to_string()
} else { } else {
return Err(StatusCode::NOT_FOUND.into()); file_name
}; };
match global.config.fs { let path = repo_dir.join(file_name);
FsConfig::Local { data_dir } => {
let path = data_dir
.join("repos")
.join(repo_id.to_string())
.join(file_name);
Ok(ServeFile::new(path).oneshot(req).await) Ok(ServeFile::new(path).oneshot(req).await)
} }
} }
@ -124,3 +115,28 @@ async fn delete_arch_repo(
Ok(StatusCode::NOT_FOUND) Ok(StatusCode::NOT_FOUND)
} }
} }
async fn delete_package(
State(global): State<crate::Global>,
Path((distro, repo, arch, pkg_name)): Path<(String, String, String, String)>,
) -> crate::Result<StatusCode> {
Ok(StatusCode::NOT_FOUND)
//if let Some(mgr) = global.mgr.get_mgr(&distro).await {
// let pkg_removed = mgr.remove_pkg(&repo, &arch, &pkg_name).await?;
//
// if pkg_removed {
// tracing::info!(
// "Removed package '{}' ({}) from repository '{}'",
// pkg_name,
// arch,
// repo
// );
//
// Ok(StatusCode::OK)
// } else {
// Ok(StatusCode::NOT_FOUND)
// }
//} else {
// Ok(StatusCode::NOT_FOUND)
//}
}