@@ -39,17 +39,17 @@ import (
39
39
"github.com/fluxcd/pkg/sourceignore"
40
40
"github.com/fluxcd/pkg/untar"
41
41
42
- sourcev1 "github.com/fluxcd/source-controller/api/v1"
42
+ "github.com/fluxcd/source-controller/api/v1"
43
43
intdigest "github.com/fluxcd/source-controller/internal/digest"
44
44
sourcefs "github.com/fluxcd/source-controller/internal/fs"
45
45
)
46
46
47
47
const GarbageCountLimit = 1000
48
48
49
49
const (
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.
51
51
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.
53
53
defaultDirMode int64 = 0o755
54
54
)
55
55
@@ -83,19 +83,19 @@ func NewStorage(basePath string, hostname string, artifactRetentionTTL time.Dura
83
83
}, nil
84
84
}
85
85
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 {
90
90
Path : path ,
91
91
Revision : revision ,
92
92
}
93
93
s .SetArtifactURL (& artifact )
94
94
return artifact
95
95
}
96
96
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 ) {
99
99
if artifact .Path == "" {
100
100
return
101
101
}
@@ -116,14 +116,14 @@ func (s Storage) SetHostname(URL string) string {
116
116
return u .String ()
117
117
}
118
118
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 {
121
121
dir := filepath .Dir (s .LocalPath (artifact ))
122
122
return os .MkdirAll (dir , 0o700 )
123
123
}
124
124
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 ) {
127
127
var deletedDir string
128
128
dir := filepath .Dir (s .LocalPath (artifact ))
129
129
// Check if the dir exists.
@@ -134,8 +134,8 @@ func (s *Storage) RemoveAll(artifact sourcev1.Artifact) (string, error) {
134
134
return deletedDir , os .RemoveAll (dir )
135
135
}
136
136
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 ) {
139
139
deletedFiles := []string {}
140
140
localPath := s .LocalPath (artifact )
141
141
dir := filepath .Dir (localPath )
@@ -168,7 +168,7 @@ func (s *Storage) RemoveAllButCurrent(artifact sourcev1.Artifact) ([]string, err
168
168
// 1. collect all artifact files with an expired ttl
169
169
// 2. if we satisfy maxItemsToBeRetained, then return
170
170
// 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 ) {
172
172
localPath := s .LocalPath (artifact )
173
173
dir := filepath .Dir (localPath )
174
174
artifactFilesWithCreatedTs := make (map [time.Time ]string )
@@ -219,7 +219,7 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
219
219
return garbageFiles , nil
220
220
}
221
221
222
- // sort all timestamps in an ascending order.
222
+ // sort all timestamps in ascending order.
223
223
sort .Slice (creationTimestamps , func (i , j int ) bool { return creationTimestamps [i ].Before (creationTimestamps [j ]) })
224
224
for _ , ts := range creationTimestamps {
225
225
path , ok := artifactFilesWithCreatedTs [ts ]
@@ -233,7 +233,7 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
233
233
noOfGarbageFiles := len (garbageFiles )
234
234
for _ , path := range sortedPaths {
235
235
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
237
237
// when checking whether we need to remove more files to satisfy the max no. of items allowed
238
238
// in the filesystem, along with the no. of files already removed in this loop.
239
239
if noOfGarbageFiles > 0 {
@@ -253,9 +253,9 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
253
253
return garbageFiles , nil
254
254
}
255
255
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
257
257
// 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 ) {
259
259
delFilesChan := make (chan []string )
260
260
errChan := make (chan error )
261
261
// Abort if it takes more than the provided timeout duration.
@@ -316,8 +316,8 @@ func stringInSlice(a string, list []string) bool {
316
316
return false
317
317
}
318
318
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 {
321
321
fi , err := os .Lstat (s .LocalPath (artifact ))
322
322
if err != nil {
323
323
return false
@@ -343,11 +343,11 @@ func SourceIgnoreFilter(ps []gitignore.Pattern, domain []string) ArchiveFileFilt
343
343
}
344
344
}
345
345
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
347
347
// directories and any ArchiveFileFilter matches. While archiving, any environment specific data (for example,
348
348
// the user and group name) is stripped from file headers.
349
349
// 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 ) {
351
351
if f , err := os .Stat (dir ); os .IsNotExist (err ) || ! f .IsDir () {
352
352
return fmt .Errorf ("invalid dir path: %s" , dir )
353
353
}
@@ -467,9 +467,9 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
467
467
return nil
468
468
}
469
469
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.
471
471
// 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 ) {
473
473
localPath := s .LocalPath (* artifact )
474
474
tf , err := os .CreateTemp (filepath .Split (localPath ))
475
475
if err != nil {
@@ -509,9 +509,9 @@ func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader,
509
509
return nil
510
510
}
511
511
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.
513
513
// 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 ) {
515
515
localPath := s .LocalPath (* artifact )
516
516
tf , err := os .CreateTemp (filepath .Split (localPath ))
517
517
if err != nil {
@@ -547,9 +547,9 @@ func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error
547
547
return nil
548
548
}
549
549
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.
551
551
// 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 ) {
553
553
f , err := os .Open (path )
554
554
if err != nil {
555
555
return err
@@ -564,7 +564,7 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er
564
564
}
565
565
566
566
// 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 {
568
568
// create a tmp directory to store artifact
569
569
tmp , err := os .MkdirTemp ("" , "flux-include-" )
570
570
if err != nil {
@@ -602,8 +602,8 @@ func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string
602
602
return nil
603
603
}
604
604
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 ) {
607
607
localPath := s .LocalPath (artifact )
608
608
dir := filepath .Dir (localPath )
609
609
link := filepath .Join (dir , linkName )
@@ -621,19 +621,18 @@ func (s *Storage) Symlink(artifact sourcev1.Artifact, linkName string) (string,
621
621
return "" , err
622
622
}
623
623
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
626
625
}
627
626
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 ) {
630
629
lockFile := s .LocalPath (artifact ) + ".lock"
631
630
mutex := lockedfile .MutexAt (lockFile )
632
631
return mutex .Lock ()
633
632
}
634
633
635
634
// 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 {
637
636
if artifact .Path == "" {
638
637
return ""
639
638
}
@@ -644,7 +643,7 @@ func (s *Storage) LocalPath(artifact sourcev1.Artifact) string {
644
643
return path
645
644
}
646
645
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
648
647
// of bytes written.
649
648
type writeCounter struct {
650
649
written int64
0 commit comments