From 93c0dc9c4f69cde6e91d270c43c3f0e8b92234d3 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 9 Jan 2022 22:30:07 +0100 Subject: [PATCH] Added start of repo-add functionality --- vieter/main.v | 12 ++++++++++-- vieter/repo.v | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 vieter/repo.v diff --git a/vieter/main.v b/vieter/main.v index 7d9a1e2..d7a1b7d 100644 --- a/vieter/main.v +++ b/vieter/main.v @@ -4,11 +4,14 @@ import web import os import log import io +import repo const port = 8000 const buf_size = 1_000_000 +const db_name = 'pieter.db.tar.gz' + struct App { web.Context api_key string [required; web_global] @@ -43,7 +46,6 @@ fn reader_to_file(mut reader io.BufferedReader, length int, path string) ? { for to_write > 0 { // TODO don't just loop infinitely here bytes_written := file.write(buf[bytes_read - to_write..bytes_read]) or { continue } - println(bytes_written) to_write = to_write - bytes_written } @@ -66,7 +68,13 @@ fn (mut app App) put_package(pkg string) web.Result { return app.text("Content-Type header isn't set.") } - return app.text('just stop') + repo.add_package(os.join_path_single(app.repo_dir, db_name), full_path) or { + os.rm(full_path) or { println('Failed to remove $full_path') } + + return app.text('Failed to add package to repo.') + } + + return app.text('Package added successfully.') } // ['/publish'; post] diff --git a/vieter/repo.v b/vieter/repo.v new file mode 100644 index 0000000..54dfc38 --- /dev/null +++ b/vieter/repo.v @@ -0,0 +1,12 @@ +module repo + +import os + +pub fn add_package(db_path string, pkg_path string) ? { + res := os.execute("repo-add '$db_path' '$pkg_path'") + + if res.exit_code != 0 { + println(res.output) + return error('repo-add failed.') + } +}