@@ -8,10 +8,8 @@ import (
88 "io"
99 "os"
1010 "path/filepath"
11- "strings"
1211 "time"
1312
14- "github.com/outcatcher/hipapu/internal/config"
1513 "github.com/schollz/progressbar/v3"
1614)
1715
2321
2422// Synchronize runs synchronization of all new releases replacing local files reporting the progress.
2523func (a * Application ) Synchronize (ctx context.Context ) error {
26- installations := a .config .GetInstallations ()
24+ installations , err := a .List (ctx )
25+ if err != nil {
26+ return fmt .Errorf ("sync error: %w" , err )
27+ }
2728
2829 if len (installations ) == 0 {
2930 return ErrEmptyInstallationList
@@ -50,29 +51,18 @@ func (a *Application) Synchronize(ctx context.Context) error {
5051
5152//nolint:cyclop,funlen // rewriting makes it less readable
5253func (a * Application ) syncInstallation (
53- ctx context.Context , installation config. Installation ,
54+ ctx context.Context , installation Installation ,
5455) error {
55- file , err := a .files .GetFileInfo (installation .LocalPath )
56- if err != nil {
57- return fmt .Errorf ("failed to get file info: %w" , err )
58- }
59-
60- urlParts := strings .Split (installation .RepoURL , "/" )
61- owner , repo := urlParts [len (urlParts )- 2 ], urlParts [len (urlParts )- 1 ]
62-
6356 a .log ().InfoContext (ctx ,
6457 "Starting sync of installation" ,
65- "owner" , owner ,
66- "repo" , repo ,
67- "local path" , installation .LocalPath ,
58+ "owner" , installation . Release . Owner ,
59+ "repo" , installation . Release . Repo ,
60+ "local path" , installation .LocalFile . FilePath ,
6861 )
6962
70- release , err := a .remote .GetLatestRelease (ctx , owner , repo )
71- if err != nil {
72- return fmt .Errorf ("failed to get release info: %w" , err )
73- }
63+ release , file := installation .Release , installation .LocalFile
7464
75- if ! release .PublishedAt .After (file .LastModified ) {
65+ if ! release .PublishedAt .After (installation . LocalFile .LastModified ) {
7666 a .log ().Info (
7767 "Current installation is up to date" ,
7868 "published at" , release .PublishedAt .Format (time .RFC3339 ),
@@ -140,9 +130,9 @@ func (a *Application) syncInstallation(
140130 }
141131
142132 a .log ().Info ("Finished sync of installation" ,
143- "owner" , owner ,
144- "repo" , repo ,
145- "local path" , installation . LocalPath ,
133+ "owner" , release . Owner ,
134+ "repo" , release . Repo ,
135+ "local path" , file . FilePath ,
146136 "download URL" , downloadURL ,
147137 )
148138
0 commit comments