@@ -39,17 +39,17 @@ import (
3939 "github.com/fluxcd/pkg/sourceignore"
4040 "github.com/fluxcd/pkg/untar"
4141
42- sourcev1 "github.com/fluxcd/source-controller/api/v1"
42+ "github.com/fluxcd/source-controller/api/v1"
4343 intdigest "github.com/fluxcd/source-controller/internal/digest"
4444 sourcefs "github.com/fluxcd/source-controller/internal/fs"
4545)
4646
4747const GarbageCountLimit = 1000
4848
4949const (
50- // defaultFileMode is the permission mode applied to all files inside of an artifact archive.
50+ // defaultFileMode is the permission mode applied to all files inside an artifact archive.
5151 defaultFileMode int64 = 0o644
52- // defaultDirMode is the permission mode applied to all directories inside of an artifact archive.
52+ // defaultDirMode is the permission mode applied to all directories inside an artifact archive.
5353 defaultDirMode int64 = 0o755
5454)
5555
@@ -83,19 +83,19 @@ func NewStorage(basePath string, hostname string, artifactRetentionTTL time.Dura
8383 }, nil
8484}
8585
86- // NewArtifactFor returns a new v1beta1 .Artifact.
87- func (s * Storage ) NewArtifactFor (kind string , metadata metav1.Object , revision , fileName string ) sourcev1 .Artifact {
88- path := sourcev1 .ArtifactPath (kind , metadata .GetNamespace (), metadata .GetName (), fileName )
89- artifact := sourcev1 .Artifact {
86+ // NewArtifactFor returns a new v1 .Artifact.
87+ func (s * Storage ) NewArtifactFor (kind string , metadata metav1.Object , revision , fileName string ) v1 .Artifact {
88+ path := v1 .ArtifactPath (kind , metadata .GetNamespace (), metadata .GetName (), fileName )
89+ artifact := v1 .Artifact {
9090 Path : path ,
9191 Revision : revision ,
9292 }
9393 s .SetArtifactURL (& artifact )
9494 return artifact
9595}
9696
97- // SetArtifactURL sets the URL on the given v1beta1 .Artifact.
98- func (s Storage ) SetArtifactURL (artifact * sourcev1 .Artifact ) {
97+ // SetArtifactURL sets the URL on the given v1 .Artifact.
98+ func (s Storage ) SetArtifactURL (artifact * v1 .Artifact ) {
9999 if artifact .Path == "" {
100100 return
101101 }
@@ -116,14 +116,14 @@ func (s Storage) SetHostname(URL string) string {
116116 return u .String ()
117117}
118118
119- // MkdirAll calls os.MkdirAll for the given v1beta1 .Artifact base dir.
120- func (s * Storage ) MkdirAll (artifact sourcev1 .Artifact ) error {
119+ // MkdirAll calls os.MkdirAll for the given v1 .Artifact base dir.
120+ func (s * Storage ) MkdirAll (artifact v1 .Artifact ) error {
121121 dir := filepath .Dir (s .LocalPath (artifact ))
122122 return os .MkdirAll (dir , 0o700 )
123123}
124124
125- // RemoveAll calls os.RemoveAll for the given v1beta1 .Artifact base dir.
126- func (s * Storage ) RemoveAll (artifact sourcev1 .Artifact ) (string , error ) {
125+ // RemoveAll calls os.RemoveAll for the given v1 .Artifact base dir.
126+ func (s * Storage ) RemoveAll (artifact v1 .Artifact ) (string , error ) {
127127 var deletedDir string
128128 dir := filepath .Dir (s .LocalPath (artifact ))
129129 // Check if the dir exists.
@@ -134,8 +134,8 @@ func (s *Storage) RemoveAll(artifact sourcev1.Artifact) (string, error) {
134134 return deletedDir , os .RemoveAll (dir )
135135}
136136
137- // RemoveAllButCurrent removes all files for the given v1beta1 .Artifact base dir, excluding the current one.
138- func (s * Storage ) RemoveAllButCurrent (artifact sourcev1 .Artifact ) ([]string , error ) {
137+ // RemoveAllButCurrent removes all files for the given v1 .Artifact base dir, excluding the current one.
138+ func (s * Storage ) RemoveAllButCurrent (artifact v1 .Artifact ) ([]string , error ) {
139139 deletedFiles := []string {}
140140 localPath := s .LocalPath (artifact )
141141 dir := filepath .Dir (localPath )
@@ -168,7 +168,7 @@ func (s *Storage) RemoveAllButCurrent(artifact sourcev1.Artifact) ([]string, err
168168// 1. collect all artifact files with an expired ttl
169169// 2. if we satisfy maxItemsToBeRetained, then return
170170// 3. else, collect all artifact files till the latest n files remain, where n=maxItemsToBeRetained
171- func (s * Storage ) getGarbageFiles (artifact sourcev1 .Artifact , totalCountLimit , maxItemsToBeRetained int , ttl time.Duration ) (garbageFiles []string , _ error ) {
171+ func (s * Storage ) getGarbageFiles (artifact v1 .Artifact , totalCountLimit , maxItemsToBeRetained int , ttl time.Duration ) (garbageFiles []string , _ error ) {
172172 localPath := s .LocalPath (artifact )
173173 dir := filepath .Dir (localPath )
174174 artifactFilesWithCreatedTs := make (map [time.Time ]string )
@@ -219,7 +219,7 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
219219 return garbageFiles , nil
220220 }
221221
222- // sort all timestamps in an ascending order.
222+ // sort all timestamps in ascending order.
223223 sort .Slice (creationTimestamps , func (i , j int ) bool { return creationTimestamps [i ].Before (creationTimestamps [j ]) })
224224 for _ , ts := range creationTimestamps {
225225 path , ok := artifactFilesWithCreatedTs [ts ]
@@ -233,7 +233,7 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
233233 noOfGarbageFiles := len (garbageFiles )
234234 for _ , path := range sortedPaths {
235235 if path != localPath && filepath .Ext (path ) != ".lock" && ! stringInSlice (path , garbageFiles ) {
236- // If we previously collected a few garbage files with an expired ttl, then take that into account
236+ // If we previously collected some garbage files with an expired ttl, then take that into account
237237 // when checking whether we need to remove more files to satisfy the max no. of items allowed
238238 // in the filesystem, along with the no. of files already removed in this loop.
239239 if noOfGarbageFiles > 0 {
@@ -253,9 +253,9 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
253253 return garbageFiles , nil
254254}
255255
256- // GarbageCollect removes all garabge files in the artifact dir according to the provided
256+ // GarbageCollect removes all garbage files in the artifact dir according to the provided
257257// retention options.
258- func (s * Storage ) GarbageCollect (ctx context.Context , artifact sourcev1 .Artifact , timeout time.Duration ) ([]string , error ) {
258+ func (s * Storage ) GarbageCollect (ctx context.Context , artifact v1 .Artifact , timeout time.Duration ) ([]string , error ) {
259259 delFilesChan := make (chan []string )
260260 errChan := make (chan error )
261261 // Abort if it takes more than the provided timeout duration.
@@ -316,8 +316,8 @@ func stringInSlice(a string, list []string) bool {
316316 return false
317317}
318318
319- // ArtifactExist returns a boolean indicating whether the v1beta1 .Artifact exists in storage and is a regular file.
320- func (s * Storage ) ArtifactExist (artifact sourcev1 .Artifact ) bool {
319+ // ArtifactExist returns a boolean indicating whether the v1 .Artifact exists in storage and is a regular file.
320+ func (s * Storage ) ArtifactExist (artifact v1 .Artifact ) bool {
321321 fi , err := os .Lstat (s .LocalPath (artifact ))
322322 if err != nil {
323323 return false
@@ -343,11 +343,11 @@ func SourceIgnoreFilter(ps []gitignore.Pattern, domain []string) ArchiveFileFilt
343343 }
344344}
345345
346- // Archive atomically archives the given directory as a tarball to the given v1beta1 .Artifact path, excluding
346+ // Archive atomically archives the given directory as a tarball to the given v1 .Artifact path, excluding
347347// directories and any ArchiveFileFilter matches. While archiving, any environment specific data (for example,
348348// the user and group name) is stripped from file headers.
349349// If successful, it sets the digest and last update time on the artifact.
350- func (s * Storage ) Archive (artifact * sourcev1 .Artifact , dir string , filter ArchiveFileFilter ) (err error ) {
350+ func (s * Storage ) Archive (artifact * v1 .Artifact , dir string , filter ArchiveFileFilter ) (err error ) {
351351 if f , err := os .Stat (dir ); os .IsNotExist (err ) || ! f .IsDir () {
352352 return fmt .Errorf ("invalid dir path: %s" , dir )
353353 }
@@ -467,9 +467,9 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
467467 return nil
468468}
469469
470- // AtomicWriteFile atomically writes the io.Reader contents to the v1beta1 .Artifact path.
470+ // AtomicWriteFile atomically writes the io.Reader contents to the v1 .Artifact path.
471471// If successful, it sets the digest and last update time on the artifact.
472- func (s * Storage ) AtomicWriteFile (artifact * sourcev1 .Artifact , reader io.Reader , mode os.FileMode ) (err error ) {
472+ func (s * Storage ) AtomicWriteFile (artifact * v1 .Artifact , reader io.Reader , mode os.FileMode ) (err error ) {
473473 localPath := s .LocalPath (* artifact )
474474 tf , err := os .CreateTemp (filepath .Split (localPath ))
475475 if err != nil {
@@ -509,9 +509,9 @@ func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader,
509509 return nil
510510}
511511
512- // Copy atomically copies the io.Reader contents to the v1beta1 .Artifact path.
512+ // Copy atomically copies the io.Reader contents to the v1 .Artifact path.
513513// If successful, it sets the digest and last update time on the artifact.
514- func (s * Storage ) Copy (artifact * sourcev1 .Artifact , reader io.Reader ) (err error ) {
514+ func (s * Storage ) Copy (artifact * v1 .Artifact , reader io.Reader ) (err error ) {
515515 localPath := s .LocalPath (* artifact )
516516 tf , err := os .CreateTemp (filepath .Split (localPath ))
517517 if err != nil {
@@ -547,9 +547,9 @@ func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error
547547 return nil
548548}
549549
550- // CopyFromPath atomically copies the contents of the given path to the path of the v1beta1 .Artifact.
550+ // CopyFromPath atomically copies the contents of the given path to the path of the v1 .Artifact.
551551// If successful, the digest and last update time on the artifact is set.
552- func (s * Storage ) CopyFromPath (artifact * sourcev1 .Artifact , path string ) (err error ) {
552+ func (s * Storage ) CopyFromPath (artifact * v1 .Artifact , path string ) (err error ) {
553553 f , err := os .Open (path )
554554 if err != nil {
555555 return err
@@ -564,7 +564,7 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er
564564}
565565
566566// CopyToPath copies the contents in the (sub)path of the given artifact to the given path.
567- func (s * Storage ) CopyToPath (artifact * sourcev1 .Artifact , subPath , toPath string ) error {
567+ func (s * Storage ) CopyToPath (artifact * v1 .Artifact , subPath , toPath string ) error {
568568 // create a tmp directory to store artifact
569569 tmp , err := os .MkdirTemp ("" , "flux-include-" )
570570 if err != nil {
@@ -602,8 +602,8 @@ func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string
602602 return nil
603603}
604604
605- // Symlink creates or updates a symbolic link for the given v1beta1 .Artifact and returns the URL for the symlink.
606- func (s * Storage ) Symlink (artifact sourcev1 .Artifact , linkName string ) (string , error ) {
605+ // Symlink creates or updates a symbolic link for the given v1 .Artifact and returns the URL for the symlink.
606+ func (s * Storage ) Symlink (artifact v1 .Artifact , linkName string ) (string , error ) {
607607 localPath := s .LocalPath (artifact )
608608 dir := filepath .Dir (localPath )
609609 link := filepath .Join (dir , linkName )
@@ -621,19 +621,18 @@ func (s *Storage) Symlink(artifact sourcev1.Artifact, linkName string) (string,
621621 return "" , err
622622 }
623623
624- url := fmt .Sprintf ("http://%s/%s" , s .Hostname , filepath .Join (filepath .Dir (artifact .Path ), linkName ))
625- return url , nil
624+ return fmt .Sprintf ("http://%s/%s" , s .Hostname , filepath .Join (filepath .Dir (artifact .Path ), linkName )), nil
626625}
627626
628- // Lock creates a file lock for the given v1beta1 .Artifact.
629- func (s * Storage ) Lock (artifact sourcev1 .Artifact ) (unlock func (), err error ) {
627+ // Lock creates a file lock for the given v1 .Artifact.
628+ func (s * Storage ) Lock (artifact v1 .Artifact ) (unlock func (), err error ) {
630629 lockFile := s .LocalPath (artifact ) + ".lock"
631630 mutex := lockedfile .MutexAt (lockFile )
632631 return mutex .Lock ()
633632}
634633
635634// LocalPath returns the secure local path of the given artifact (that is: relative to the Storage.BasePath).
636- func (s * Storage ) LocalPath (artifact sourcev1 .Artifact ) string {
635+ func (s * Storage ) LocalPath (artifact v1 .Artifact ) string {
637636 if artifact .Path == "" {
638637 return ""
639638 }
@@ -644,7 +643,7 @@ func (s *Storage) LocalPath(artifact sourcev1.Artifact) string {
644643 return path
645644}
646645
647- // writecounter is an implementation of io.Writer that only records the number
646+ // writeCounter is an implementation of io.Writer that only records the number
648647// of bytes written.
649648type writeCounter struct {
650649 written int64
0 commit comments