Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per-repo file purge times #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cofinalsubnets
Copy link
Contributor

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

Adds a per-repo `purge_files_after` configuration option that overrides
the global setting if present.
@anatol
Copy link
Owner

anatol commented Mar 21, 2023

Looks good to me.

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

@@ -9,6 +9,19 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
)

func (r *Repo) Equal(x interface{}) bool {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Equal function introduction seems unrelated to perrepo purge option. It makes sense to move it to a separate commit (but keep it in this PR).

@anatol
Copy link
Owner

anatol commented Mar 23, 2023

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
Copy link
Owner

anatol commented Mar 31, 2023

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
Copy link
Owner

anatol commented Apr 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants