From 79b47a76e24c6c7e79617a53185991cf67bb2c0e Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 18 Feb 2022 21:59:33 +0100 Subject: [PATCH 1/2] Remove packages from db before adding new version --- src/repo/repo.v | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/repo/repo.v b/src/repo/repo.v index 554b744c..1bf2d0c8 100644 --- a/src/repo/repo.v +++ b/src/repo/repo.v @@ -74,6 +74,9 @@ fn (r &Repo) add(pkg &package.Pkg) ?bool { return false } + // We remove the older package version first, if present + r.remove(pkg.info.name, false) ? + os.mkdir(pkg_dir) or { return error('Failed to create package directory.') } os.write_file(os.join_path_single(pkg_dir, 'desc'), pkg.to_desc()) or { @@ -92,6 +95,31 @@ fn (r &Repo) add(pkg &package.Pkg) ?bool { return true } +// remove removes a package from the database. It returns false if the package +// wasn't present in the database. +fn (r &Repo) remove(pkg_name string, sync bool) ?bool { + // We iterate over every directory in the repo dir + for d in os.ls(r.repo_dir) ? { + name := d.split('-')#[..-2].join('-') + + if name == pkg_name { + // We lock the mutex here to prevent other routines from creating a + // new archive while we removed an entry + lock r.mutex { + os.rmdir_all(os.join_path_single(r.repo_dir, d)) ? + } + + if sync { + r.sync() ? + } + + return true + } + } + + return false +} + // Returns the path where the given package's desc & files files are stored fn (r &Repo) pkg_path(pkg &package.Pkg) string { return os.join_path(r.repo_dir, '$pkg.info.name-$pkg.info.version') From 99f6dc69fdef38c27a6b2b4784165bd2d25baa27 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 18 Feb 2022 22:08:58 +0100 Subject: [PATCH 2/2] Fixed tiny linting error --- src/web/parse.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/parse.v b/src/web/parse.v index b5925409..2eeef5e9 100644 --- a/src/web/parse.v +++ b/src/web/parse.v @@ -34,7 +34,7 @@ fn parse_attrs(name string, attrs []string) ?([]http.Method, string) { } if x.len > 0 { return IError(http.UnexpectedExtraAttributeError{ - attributes: x + attributes: x }) } if methods.len == 0 {