Added start of repo-add functionality

main
Jef Roosens 2022-01-09 22:30:07 +01:00
parent 17038dc33c
commit 93c0dc9c4f
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
2 changed files with 22 additions and 2 deletions

View File

@ -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]

12
vieter/repo.v 100644
View File

@ -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.')
}
}