Logs now show names of added packages
ci/woodpecker/push/builder unknown status Details
ci/woodpecker/push/deploy unknown status Details
ci/woodpecker/push/docker unknown status Details
ci/woodpecker/push/lint Pipeline failed Details
ci/woodpecker/push/build Pipeline was successful Details

pull/64/head
Jef Roosens 2022-02-02 13:24:31 +01:00
parent 3ad960fd59
commit a29592ef36
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
5 changed files with 32 additions and 26 deletions

View File

@ -178,10 +178,13 @@ fn format_entry(key string, value string) string {
return '\n%$key%\n$value\n' return '\n%$key%\n$value\n'
} }
pub fn (pkg &Pkg) full_name() string {
p := pkg.info
return '$p.name-$p.version-$p.arch'
}
// filename returns the correct filename of the package file // filename returns the correct filename of the package file
pub fn (pkg &Pkg) filename() string { pub fn (pkg &Pkg) filename() string {
p := pkg.info
ext := match pkg.compression { ext := match pkg.compression {
0 { '.tar' } 0 { '.tar' }
1 { '.tar.gz' } 1 { '.tar.gz' }
@ -189,7 +192,7 @@ pub fn (pkg &Pkg) filename() string {
else { panic("Another compression code shouldn't be possible. Faulty code: $pkg.compression") } else { panic("Another compression code shouldn't be possible. Faulty code: $pkg.compression") }
} }
return '$p.name-$p.version-${p.arch}.pkg$ext' return '${pkg.full_name()}.pkg$ext'
} }
// to_desc returns a desc file valid string representation // to_desc returns a desc file valid string representation

View File

@ -20,6 +20,12 @@ pub:
pkg_dir string [required] pkg_dir string [required]
} }
pub struct RepoAddResult {
pub:
added bool [required]
pkg &package.Pkg [required]
}
// new creates a new Repo & creates the directories as needed // new creates a new Repo & creates the directories as needed
pub fn new(repo_dir string, pkg_dir string) ?Repo { pub fn new(repo_dir string, pkg_dir string) ?Repo {
if !os.is_dir(repo_dir) { if !os.is_dir(repo_dir) {
@ -38,7 +44,7 @@ pub fn new(repo_dir string, pkg_dir string) ?Repo {
// add_from_path adds a package from an arbitrary path & moves it into the pkgs // add_from_path adds a package from an arbitrary path & moves it into the pkgs
// directory if necessary. // directory if necessary.
pub fn (r &Repo) add_from_path(pkg_path string) ?bool { pub fn (r &Repo) add_from_path(pkg_path string) ?RepoAddResult {
pkg := package.read_pkg(pkg_path) or { return error('Failed to read package file: $err.msg') } pkg := package.read_pkg(pkg_path) or { return error('Failed to read package file: $err.msg') }
added := r.add(pkg) ? added := r.add(pkg) ?
@ -53,7 +59,10 @@ pub fn (r &Repo) add_from_path(pkg_path string) ?bool {
} }
} }
return added return RepoAddResult{
added: added
pkg: &pkg
}
} }
// add adds a given Pkg to the repository // add adds a given Pkg to the repository

View File

@ -62,7 +62,7 @@ fn (mut app App) put_package() web.Result {
pkg_path = os.join_path_single(app.dl_dir, rand.uuid_v4()) pkg_path = os.join_path_single(app.dl_dir, rand.uuid_v4())
} }
app.ldebug("Uploading $length (${pretty_bytes(length.int())}) bytes to '$pkg_path'.") app.ldebug("Uploading $length bytes (${pretty_bytes(length.int())}) to '$pkg_path'.")
// This is used to time how long it takes to upload a file // This is used to time how long it takes to upload a file
mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true }) mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true })
@ -80,28 +80,22 @@ fn (mut app App) put_package() web.Result {
return app.text("Content-Type header isn't set.") return app.text("Content-Type header isn't set.")
} }
added := app.repo.add_from_path(pkg_path) or { res := app.repo.add_from_path(pkg_path) or {
app.lerror('Error while adding package: $err.msg') app.lerror('Error while adding package: $err.msg')
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path'.") } os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") }
return app.text('Failed to add package.') return app.text('Failed to add package.')
} }
if !added { if !res.added {
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path'.") } os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") }
app.lwarn('Duplicate package.') app.lwarn("Duplicate package '$res.pkg.full_name()'.")
return app.text('File already exists.') return app.text('File already exists.')
} }
app.linfo("Added '$pkg_path' to repository.") app.linfo("Added '$res.pkg.full_name()' to repository.")
return app.text('Package added successfully.') return app.text('Package added successfully.')
} }
// add_package PUT a new package to the server
['/add'; put]
pub fn (mut app App) add_package() web.Result {
return app.text('')
}