aboutsummaryrefslogtreecommitdiff
path: root/internal/feed
diff options
context:
space:
mode:
Diffstat (limited to 'internal/feed')
-rw-r--r--internal/feed/cache/cache.go16
-rw-r--r--internal/feed/cache/v1.go4
-rw-r--r--internal/feed/cache/v2.go63
3 files changed, 76 insertions, 7 deletions
diff --git a/internal/feed/cache/cache.go b/internal/feed/cache/cache.go
index 9613f06..1ea8eaf 100644
--- a/internal/feed/cache/cache.go
+++ b/internal/feed/cache/cache.go
@@ -18,7 +18,7 @@ import (
type Version byte
const (
- currentVersion Version = v1Version
+ currentVersion Version = v2Version
)
type Impl interface {
@@ -56,6 +56,8 @@ func forVersion(version Version) (Impl, error) {
switch version {
case v1Version:
return newV1Cache(), nil
+ case v2Version:
+ return newV2Cache(), nil
default:
return nil, fmt.Errorf("unknown cache version '%d'", version)
}
@@ -169,11 +171,15 @@ func Load(fileName string) (Cache, error) {
return Cache{}, fmt.Errorf("decoding for version '%d' from '%s': %w", version, fileName, err)
}
- if cache, err = cache.transformTo(currentVersion); err != nil {
- return Cache{}, fmt.Errorf("cannot transform from version %d to %d: %w", version, currentVersion, err)
- }
+ if currentVersion != cache.Version() {
+ if cache, err = cache.transformTo(currentVersion); err != nil {
+ return Cache{}, fmt.Errorf("cannot transform from version %d to %d: %w", version, currentVersion, err)
+ }
- log.Printf("Loaded cache (version %d), transformed to version %d.", version, currentVersion)
+ log.Printf("Loaded cache (version %d), transformed to version %d.", version, currentVersion)
+ } else {
+ log.Printf("Loaded cache (version %d)", version)
+ }
return Cache{cache, lock, true}, nil
}
diff --git a/internal/feed/cache/v1.go b/internal/feed/cache/v1.go
index 17a0346..0363303 100644
--- a/internal/feed/cache/v1.go
+++ b/internal/feed/cache/v1.go
@@ -179,8 +179,8 @@ func newV1Cache() *v1Cache {
func (cache *v1Cache) transformTo(v Version) (Impl, error) {
switch v {
- case v1Version:
- return cache, nil
+ case v2Version:
+ return (*v2Cache)(cache), nil
default:
return nil, fmt.Errorf("Transformation not supported")
}
diff --git a/internal/feed/cache/v2.go b/internal/feed/cache/v2.go
new file mode 100644
index 0000000..87636b6
--- /dev/null
+++ b/internal/feed/cache/v2.go
@@ -0,0 +1,63 @@
+package cache
+
+import (
+ "compress/gzip"
+ "fmt"
+ "io"
+
+ "github.com/Necoro/feed2imap-go/internal/feed"
+)
+
+const v2Version Version = 2
+
+// v2Cache is identical to v1Cache, but uses gzip compression for storage
+type v2Cache v1Cache
+
+func newV2Cache() *v2Cache {
+ return (*v2Cache)(newV1Cache())
+}
+
+func (cache *v2Cache) asV1() *v1Cache {
+ return (*v1Cache)(cache)
+}
+
+func (cache *v2Cache) cachedFeed(feed *feed.Feed) CachedFeed {
+ return cache.asV1().cachedFeed(feed)
+}
+
+func (cache *v2Cache) transformTo(v Version) (Impl, error) {
+ return nil, fmt.Errorf("Transformation not supported")
+}
+
+func (cache *v2Cache) Version() Version {
+ return v2Version
+}
+
+func (cache *v2Cache) Info() string {
+ return cache.asV1().Info()
+}
+
+func (cache *v2Cache) SpecificInfo(i interface{}) string {
+ return cache.asV1().SpecificInfo(i)
+}
+
+func (cache *v2Cache) load(reader io.Reader) error {
+ gzipReader, err := gzip.NewReader(reader)
+ if err != nil {
+ return err
+ }
+ defer gzipReader.Close()
+
+ return cache.asV1().load(gzipReader)
+}
+
+func (cache *v2Cache) store(writer io.Writer) error {
+ gzipWriter := gzip.NewWriter(writer)
+ defer gzipWriter.Close()
+
+ if err := cache.asV1().store(gzipWriter); err != nil {
+ return err
+ }
+
+ return gzipWriter.Flush()
+}
ref='/portato.git/commit/portato/gui/wrapper.py?id=6a9034fb7a161e441934969553ffff63e49348ee&follow=1'> r664@Devoty: necoro | 2008-01-18 21:40:29 +0100Necoro5-26/+181 First support for 'delete on demand' r665@Devoty: necoro | 2008-01-18 22:18:05 +0100 Finished the 'on demand removal' 2008-01-18 r661@Devoty: necoro | 2008-01-18 14:16:59 +0100Necoro8-211/+293 First support for interactive emerges r662@Devoty: necoro | 2008-01-18 20:22:58 +0100 Now finished interactive emerges 2008-01-18 r655@Devoty: necoro | 2008-01-18 03:04:53 +0100Necoro1-1/+1 Small bugfix 2008-01-18 r651@Devoty: necoro | 2008-01-18 02:41:51 +0100Necoro3-393/+513 adjust changelog and translation 2008-01-18 r643@Devoty: necoro | 2008-01-16 18:55:49 +0100Necoro14-249/+525 Fixed small bug in PackageTable.cb_package_revert_clicked r646@Devoty: necoro | 2008-01-18 00:12:30 +0100 Make tabpositions being configurable by the user r647@Devoty: necoro | 2008-01-18 01:38:19 +0100 Renamed 'shm' to '_shm' to not hide the global one r648@Devoty: necoro | 2008-01-18 01:38:29 +0100 Renamed 'shm' to '_shm' to not hide the global one r649@Devoty: necoro | 2008-01-18 02:34:43 +0100 Added update queues; general UI improvement 2008-01-14 r634@Devoty: necoro | 2008-01-14 23:48:24 +0100Necoro3-1/+4 Removed the broken plugins until they get replaced 2008-01-14 r632@Devoty: necoro | 2008-01-14 23:44:52 +0100Necoro3-175/+181 small changes 2008-01-14(no commit message)Necoro10-758/+1014 2008-01-14 r621@Devoty: necoro | 2008-01-14 20:21:40 +0100Necoro2-21/+61 adjust changelog r622@Devoty: necoro | 2008-01-14 21:01:11 +0100 Some new views 2008-01-14 r618@Devoty: necoro | 2008-01-14 20:19:05 +0100Necoro2-35/+57 An ALL category 2008-01-14 r617@Devoty: necoro | 2008-01-14 19:12:59 +0100Necoro2-10/+10 Remove unnecessairy loads of the shm module 2008-01-14 r609@Devoty: necoro | 2008-01-14 17:04:38 +0100Necoro9-394/+477 Allowed '-' and '_' in key names. Also use group names instead of their number. r610@Devoty: necoro | 2008-01-14 17:05:42 +0100 Disabled saving of the queues r611@Devoty: necoro | 2008-01-14 17:08:53 +0100 Added the possibility to permanently en-/disable plugins r612@Devoty: necoro | 2008-01-14 17:14:09 +0100 adjust changelog and translations r613@Devoty: necoro | 2008-01-14 17:40:53 +0100 Dropdown should be localized too 2008-01-14 r605@Devoty: necoro | 2008-01-14 11:43:34 +0100Necoro2-26/+129 Updated shm module to version 1.1.4 2008-01-14 r603@Devoty: necoro | 2008-01-14 11:30:26 +0100Necoro4-26/+38 Improved 'update world'; really support new use defaults 2008-01-11 r598@Devoty: necoro | 2008-01-10 16:36:29 +0100Necoro4-10/+50 Handle the new useflag format correctly 2008-01-11 r597@Devoty: necoro | 2008-01-10 14:12:35 +0100Necoro1-3/+3 updated todo 2008-01-10 r595@Devoty: necoro | 2008-01-10 04:04:15 +0100Necoro1-52/+3 Re-Introduced etc-proposals 2008-01-09 r586@Devoty: necoro | 2008-01-09 14:54:18 +0100Necoro1-1/+1 Disabled catapult till it is really usable 2007-12-06 r577@Devoty: necoro | 2007-12-06 20:37:36 +0100Necoro1-1/+1 Fixed desktop file 2007-12-06 r572@Devoty: necoro | 2007-11-28 08:48:15 +0100Necoro1-0/+1 2007-11-27 r570@Devoty: necoro | 2007-11-27 02:08:21 +0100Necoro3-84/+108 Added scrollbars to update window