Skip to content

Fix method receivers and error handling in sharedaction/resource.go #3513

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions actor/sharedaction/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (actor Actor) ZipDirectoryResources(sourceDir string, filesToInclude []Reso
return zipPath, nil
}

func (Actor) addLinkToZipFromFileSystem(srcPath string,
func (actor Actor) addLinkToZipFromFileSystem(srcPath string,
fileInfo os.FileInfo, resource Resource,
zipFile *zip.Writer,
) error {
Expand Down Expand Up @@ -367,7 +367,7 @@ func (Actor) addLinkToZipFromFileSystem(srcPath string,
return nil
}

func (Actor) addFileToZipFromFileSystem(srcPath string,
func (actor Actor) addFileToZipFromFileSystem(srcPath string,
srcFile io.Reader, fileInfo os.FileInfo, resource Resource,
zipFile *zip.Writer,
) error {
Expand Down Expand Up @@ -424,7 +424,7 @@ func (Actor) addFileToZipFromFileSystem(srcPath string,
return nil
}

func (Actor) generateArchiveCFIgnoreMatcher(files []*zip.File) (*ignore.GitIgnore, error) {
func (actor Actor) generateArchiveCFIgnoreMatcher(files []*zip.File) (*ignore.GitIgnore, error) {
for _, item := range files {
if strings.HasSuffix(item.Name, ".cfignore") {
fileReader, err := item.Open()
Expand All @@ -438,10 +438,18 @@ func (Actor) generateArchiveCFIgnoreMatcher(files []*zip.File) (*ignore.GitIgnor
return nil, err
}
s := append(DefaultIgnoreLines, strings.Split(string(raw), "\n")...)
return ignore.CompileIgnoreLines(s...)
gitIgnore, err := ignore.CompileIgnoreLines(s...)
if err != nil {
return nil, err
}
return gitIgnore, nil
}
}
return ignore.CompileIgnoreLines(DefaultIgnoreLines...)
gitIgnore, err := ignore.CompileIgnoreLines(DefaultIgnoreLines...)
if err != nil {
return nil, err
}
return gitIgnore, nil
}

func (actor Actor) generateDirectoryCFIgnoreMatcher(sourceDir string) (*ignore.GitIgnore, error) {
Expand All @@ -464,12 +472,20 @@ func (actor Actor) generateDirectoryCFIgnoreMatcher(sourceDir string) (*ignore.G
log.Debugf("ignore rules: %v", additionalIgnoreLines)

if _, err := os.Stat(pathToCFIgnore); !os.IsNotExist(err) {
return ignore.CompileIgnoreFileAndLines(pathToCFIgnore, additionalIgnoreLines...)
gitIgnore, err := ignore.CompileIgnoreFileAndLines(pathToCFIgnore, additionalIgnoreLines...)
if err != nil {
return nil, err
}
return gitIgnore, nil
}
gitIgnore, err := ignore.CompileIgnoreLines(additionalIgnoreLines...)
if err != nil {
return nil, err
}
return ignore.CompileIgnoreLines(additionalIgnoreLines...)
return gitIgnore, nil
}

func (Actor) findInResources(path string, filesToInclude []Resource) (Resource, bool) {
func (actor Actor) findInResources(path string, filesToInclude []Resource) (Resource, bool) {
for _, resource := range filesToInclude {
if resource.Filename == filepath.ToSlash(path) {
log.WithField("resource", resource.Filename).Debug("found resource in files to include")
Expand All @@ -481,7 +497,7 @@ func (Actor) findInResources(path string, filesToInclude []Resource) (Resource,
return Resource{}, false
}

func (Actor) newArchiveReader(archive *os.File) (*zip.Reader, error) {
func (actor Actor) newArchiveReader(archive *os.File) (*zip.Reader, error) {
info, err := archive.Stat()
if err != nil {
return nil, err
Expand All @@ -492,12 +508,14 @@ func (Actor) newArchiveReader(archive *os.File) (*zip.Reader, error) {

func (actor Actor) CreateArchive(bitsPath string, resources []Resource) (io.ReadCloser, int64, error) {
archivePath, err := actor.ZipDirectoryResources(bitsPath, resources)
_ = err
if err != nil {
return nil, -1, err
}

return actor.ReadArchive(archivePath)
}

func (Actor) ReadArchive(archivePath string) (io.ReadCloser, int64, error) {
func (actor Actor) ReadArchive(archivePath string) (io.ReadCloser, int64, error) {
archive, err := os.Open(archivePath)
if err != nil {
log.WithField("archivePath", archivePath).Errorln("opening temp archive:", err)
Expand Down
Loading