anatol / pacoloco

Caching proxy server for Arch Linux pacman
MIT License
199 stars 30 forks source link

Add per-repo file purge times #74

Open cofinalsubnets opened 1 year ago

cofinalsubnets commented 1 year ago

Hi. This PR adds a per-repository purge_files_after configuration option that overrides the global setting if present.

As an example of how this is useful, my use case is that i want to use pacoloco to proxy the Arch Linux Archive. Since the archive by definition doesn't get package updates, i'm not concerned about the local cache growing too large; on the contrary, if i'm downloading a specific old version of something it's probably for some special reason, so i'd like to cache it indefinitely. But i'd also like to purge normal packages after a reasonable time. So now i can write this:

purge_files_after: 2592000
repos:
  archlinux:
    mirrorlist: /etc/pacman.d/mirrorlist
  archlinux_2021_01_25:
    url: https://archive.archlinux.org/repos/2021/01/25/
    purge_files_after: 0
anatol commented 1 year ago

Looks good to me.

Could you please also update the README and mention this configuration option + add one to the an example.

anatol commented 1 year ago

Could you please also run the reformatter gofumpt -w -l . to fix 2 following issues:

diff --git a/config_test.go b/config_test.go
index abd377d..e6ae55c 100644
--- a/config_test.go
+++ b/config_test.go
@@ -153,14 +153,14 @@ repos:
                CacheDir: `/tmp`,
                Port:     9129,
                Repos: map[string]*Repo{
-                       "archlinux": &Repo{
+                       "archlinux": {
                                URL: "http://mirrors.kernel.org/archlinux",
                        },
-                       "anotherlinux": &Repo{
+                       "anotherlinux": {
                                URL:             "http://dev.null",
                                PurgeFilesAfter: &zero,
                        },
-                       "yetanotherlinux": &Repo{
+                       "yetanotherlinux": {
                                URL:             "http://dev.zero",
                                PurgeFilesAfter: &oneHundredThousand,
                        },
diff --git a/purge.go b/purge.go
index db74a2d..74bf4a4 100644
--- a/purge.go
+++ b/purge.go
@@ -18,7 +18,7 @@ func (r *Repo) purgeSeconds() int {
 func setupPurgeStaleFilesRoutine() *time.Ticker {
        ticker := time.NewTicker(time.Duration(24) * time.Hour) // purge files once a day
        go func() {
-               for _ = range ticker.C {
+               for range ticker.C {
                        for repoName, repo := range config.Repos {
                                dir := filepath.Join(config.CacheDir, "pkgs", repoName)
                                purgeStaleFiles(dir, repo.purgeSeconds())
anatol commented 1 year ago

I am thinking of a new release for pacoloco to bring the recent fixes to users.

Hi @gw000, if you plan to work on this PR in the near future then I would prefer to wait with the release a bit until the PR is merged.

anatol commented 2 months ago

ping @cofinalsubnets, are you still interested in moving this PR forward?