Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 0 additions & 24 deletions .github/license/LICENSE-WITH-3RD-PARTY-LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -791,30 +791,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


For vendor/github.com/sirupsen/logrus:

The MIT License (MIT)

Copyright (c) 2014 Simon Eskildsen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


For vendor/github.com/lunixbochs/vtclean:

Expand Down
4 changes: 2 additions & 2 deletions actor/sharedaction/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"errors"
"fmt"
"log"
"log/slog"
"strings"
"time"

logcache "code.cloudfoundry.org/go-log-cache/v2"
"code.cloudfoundry.org/go-log-cache/v2/rpc/logcache_v1"
"code.cloudfoundry.org/go-loggregator/v9/rpc/loggregator_v2"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -123,7 +123,7 @@ func (b *cliRetryBackoff) Reset() {

func GetStreamingLogs(appGUID string, client LogCacheClient) (<-chan LogMessage, <-chan error, context.CancelFunc) {

logrus.Info("Start Tailing Logs")
slog.Info("Start Tailing Logs")

outgoingLogStream := make(chan LogMessage, 1000)
outgoingErrStream := make(chan error, 1000)
Expand Down
88 changes: 34 additions & 54 deletions actor/sharedaction/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha1"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"strings"
Expand All @@ -14,7 +15,6 @@ import (
"code.cloudfoundry.org/cli/v9/actor/actionerror"
"code.cloudfoundry.org/ykk"
ignore "github.com/sabhiram/go-gitignore"
log "github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -81,7 +81,7 @@ func (actor Actor) GatherArchiveResources(archivePath string) ([]Resource, error

gitIgnore, err := actor.generateArchiveCFIgnoreMatcher(reader.File)
if err != nil {
log.Errorln("reading .cfignore file:", err)
slog.Error("reading .cfignore file", "err", err)
return nil, err
}

Expand Down Expand Up @@ -135,13 +135,13 @@ func (actor Actor) GatherDirectoryResources(sourceDir string) ([]Resource, error

gitIgnore, err := actor.generateDirectoryCFIgnoreMatcher(sourceDir)
if err != nil {
log.Errorln("reading .cfignore file:", err)
slog.Error("reading .cfignore file", "err", err)
return nil, err
}

evalDir, err := filepath.EvalSymlinks(sourceDir)
if err != nil {
log.Errorln("evaluating symlink:", err)
slog.Error("evaluating symlink", "err", err)
return nil, err
}

Expand Down Expand Up @@ -212,7 +212,7 @@ func (actor Actor) GatherDirectoryResources(sourceDir string) ([]Resource, error
// path/filename) list of resources and returns the location. On Windows, the
// filemode for user is forced to be readable and executable.
func (actor Actor) ZipArchiveResources(sourceArchivePath string, filesToInclude []Resource) (string, error) {
log.WithField("sourceArchive", sourceArchivePath).Info("zipping source files from archive")
slog.Info("zipping source files from archive", "sourceArchive", sourceArchivePath)
zipFile, err := os.CreateTemp("", "cf-cli-")
if err != nil {
return "", err
Expand All @@ -237,15 +237,15 @@ func (actor Actor) ZipArchiveResources(sourceArchivePath string, filesToInclude
for _, archiveFile := range reader.File {
resource, ok := actor.findInResources(archiveFile.Name, filesToInclude)
if !ok {
log.WithField("archiveFileName", archiveFile.Name).Debug("skipping file")
slog.Debug("skipping file", "archiveFileName", archiveFile.Name)
continue
}

log.WithField("archiveFileName", archiveFile.Name).Debug("zipping file")
slog.Debug("zipping file", "archiveFileName", archiveFile.Name)
// archiveFile.Open opens the symlink file, not the file it points too
reader, openErr := archiveFile.Open()
if openErr != nil {
log.WithField("archiveFile", archiveFile.Name).Errorln("opening path in dir:", openErr)
slog.Error("opening path in dir", "archiveFile", archiveFile.Name, "err", openErr)
return zipPath, openErr
}
defer reader.Close()
Expand All @@ -255,24 +255,21 @@ func (actor Actor) ZipArchiveResources(sourceArchivePath string, filesToInclude
resource, writer,
)
if err != nil {
log.WithField("archiveFileName", archiveFile.Name).Errorln("zipping file:", err)
slog.Error("zipping file", "archiveFileName", archiveFile.Name, "err", err)
return zipPath, err
}
reader.Close()
}

log.WithFields(log.Fields{
"zip_file_location": zipFile.Name(),
"zipped_file_count": len(filesToInclude),
}).Info("zip file created")
slog.Info("zip file created", "zip_file_location", zipFile.Name(), "zipped_file_count", len(filesToInclude))
return zipPath, nil
}

// ZipDirectoryResources zips a directory and a sorted (based on full
// path/filename) list of resources and returns the location. On Windows, the
// filemode for user is forced to be readable and executable.
func (actor Actor) ZipDirectoryResources(sourceDir string, filesToInclude []Resource) (string, error) {
log.WithField("sourceDir", sourceDir).Info("zipping source files from directory")
slog.Info("zipping source files from directory", "sourceDir", sourceDir)
zipFile, err := os.CreateTemp("", "cf-cli-")
if err != nil {
return "", err
Expand All @@ -285,26 +282,26 @@ func (actor Actor) ZipDirectoryResources(sourceDir string, filesToInclude []Reso

for _, resource := range filesToInclude {
fullPath := filepath.Join(sourceDir, resource.Filename)
log.WithField("fullPath", fullPath).Debug("zipping file")
slog.Debug("zipping file", "fullPath", fullPath)

fileInfo, err := os.Lstat(fullPath)
if err != nil {
log.WithField("fullPath", fullPath).Errorln("stat error in dir:", err)
slog.Error("stat error in dir", "fullPath", fullPath, "err", err)
return zipPath, err
}

log.WithField("file-mode", fileInfo.Mode().String()).Debug("resource file info")
slog.Debug("resource file info", "file-mode", fileInfo.Mode().String())
if fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
// we need to user os.Readlink to read a symlink file from a directory
err = actor.addLinkToZipFromFileSystem(fullPath, fileInfo, resource, writer)
if err != nil {
log.WithField("fullPath", fullPath).Errorln("zipping file:", err)
slog.Error("zipping file", "fullPath", fullPath, "err", err)
return zipPath, err
}
} else {
srcFile, err := os.Open(fullPath)
if err != nil {
log.WithField("fullPath", fullPath).Errorln("opening path in dir:", err)
slog.Error("opening path in dir", "fullPath", fullPath, "err", err)
return zipPath, err
}
defer srcFile.Close()
Expand All @@ -315,16 +312,13 @@ func (actor Actor) ZipDirectoryResources(sourceDir string, filesToInclude []Reso
)
srcFile.Close()
if err != nil {
log.WithField("fullPath", fullPath).Errorln("zipping file:", err)
slog.Error("zipping file", "fullPath", fullPath, "err", err)
return zipPath, err
}
}
}

log.WithFields(log.Fields{
"zip_file_location": zipFile.Name(),
"zipped_file_count": len(filesToInclude),
}).Info("zip file created")
slog.Info("zip file created", "zip_file_location", zipFile.Name(), "zipped_file_count", len(filesToInclude))
return zipPath, nil
}

Expand All @@ -334,33 +328,29 @@ func (Actor) addLinkToZipFromFileSystem(srcPath string,
) error {
header, err := zip.FileInfoHeader(fileInfo)
if err != nil {
log.WithField("srcPath", srcPath).Errorln("getting file info in dir:", err)
slog.Error("getting file info in dir", "srcPath", srcPath, "err", err)
return err
}

header.Name = resource.Filename
header.Method = zip.Deflate

log.WithFields(log.Fields{
"srcPath": srcPath,
"destPath": header.Name,
"mode": header.Mode().String(),
}).Debug("setting mode for file")
slog.Debug("setting mode for file", "srcPath", srcPath, "destPath", header.Name, "mode", header.Mode().String())

destFileWriter, err := zipFile.CreateHeader(header)
if err != nil {
log.Errorln("creating header:", err)
slog.Error("creating header", "err", err)
return err
}

pathInSymlink, err := os.Readlink(srcPath)
if err != nil {
return err
}
log.WithField("path", pathInSymlink).Debug("resolving symlink")
slog.Debug("resolving symlink", "path", pathInSymlink)
symLinkContents := strings.NewReader(pathInSymlink)
if _, err := io.Copy(destFileWriter, symLinkContents); err != nil {
log.WithField("srcPath", srcPath).Errorln("copying data in dir:", err)
slog.Error("copying data in dir", "srcPath", srcPath, "err", err)
return err
}

Expand All @@ -373,7 +363,7 @@ func (Actor) addFileToZipFromFileSystem(srcPath string,
) error {
header, err := zip.FileInfoHeader(fileInfo)
if err != nil {
log.WithField("srcPath", srcPath).Errorln("getting file info in dir:", err)
slog.Error("getting file info in dir", "srcPath", srcPath, "err", err)
return err
}

Expand All @@ -386,15 +376,11 @@ func (Actor) addFileToZipFromFileSystem(srcPath string,
header.Method = zip.Deflate
header.SetMode(resource.Mode)

log.WithFields(log.Fields{
"srcPath": srcPath,
"destPath": header.Name,
"mode": header.Mode().String(),
}).Debug("setting mode for file")
slog.Debug("setting mode for file", "srcPath", srcPath, "destPath", header.Name, "mode", header.Mode().String())

destFileWriter, err := zipFile.CreateHeader(header)
if err != nil {
log.Errorln("creating header:", err)
slog.Error("creating header", "err", err)
return err
}

Expand All @@ -403,15 +389,12 @@ func (Actor) addFileToZipFromFileSystem(srcPath string,
multi := io.MultiWriter(sum, destFileWriter)

if _, err := io.Copy(multi, srcFile); err != nil {
log.WithField("srcPath", srcPath).Errorln("copying data in dir:", err)
slog.Error("copying data in dir", "srcPath", srcPath, "err", err)
return err
}

if currentSum := fmt.Sprintf("%x", sum.Sum(nil)); resource.SHA1 != currentSum {
log.WithFields(log.Fields{
"expected": resource.SHA1,
"currentSum": currentSum,
}).Error("setting mode for file")
slog.Error("setting mode for file", "expected", resource.SHA1, "currentSum", currentSum)
return actionerror.FileChangedError{Filename: srcPath}
}
} else if fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
Expand Down Expand Up @@ -446,10 +429,7 @@ func (Actor) generateArchiveCFIgnoreMatcher(files []*zip.File) (*ignore.GitIgnor

func (actor Actor) generateDirectoryCFIgnoreMatcher(sourceDir string) (*ignore.GitIgnore, error) {
pathToCFIgnore := filepath.Join(sourceDir, ".cfignore")
log.WithFields(log.Fields{
"pathToCFIgnore": pathToCFIgnore,
"sourceDir": sourceDir,
}).Debug("using ignore file")
slog.Debug("using ignore file", "pathToCFIgnore", pathToCFIgnore, "sourceDir", sourceDir)

additionalIgnoreLines := DefaultIgnoreLines

Expand All @@ -461,7 +441,7 @@ func (actor Actor) generateDirectoryCFIgnoreMatcher(sourceDir string) (*ignore.G
}
}

log.Debugf("ignore rules: %v", additionalIgnoreLines)
slog.Debug("ignore rules", "rules", additionalIgnoreLines)

if _, err := os.Stat(pathToCFIgnore); !os.IsNotExist(err) {
return ignore.CompileIgnoreFileAndLines(pathToCFIgnore, additionalIgnoreLines...)
Expand All @@ -472,12 +452,12 @@ func (actor Actor) generateDirectoryCFIgnoreMatcher(sourceDir string) (*ignore.G
func (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")
slog.Debug("found resource in files to include", "resource", resource.Filename)
return resource, true
}
}

log.WithField("path", path).Debug("did not find resource in files to include")
slog.Debug("did not find resource in files to include", "path", path)
return Resource{}, false
}

Expand All @@ -500,14 +480,14 @@ func (actor Actor) CreateArchive(bitsPath string, resources []Resource) (io.Read
func (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)
slog.Error("opening temp archive", "archivePath", archivePath, "err", err)
return nil, -1, err
}

archiveInfo, err := archive.Stat()
if err != nil {
archive.Close()
log.WithField("archivePath", archivePath).Errorln("stat temp archive:", err)
slog.Error("stat temp archive", "archivePath", archivePath, "err", err)
return nil, -1, err
}

Expand Down
7 changes: 4 additions & 3 deletions actor/sharedaction/sharedaction_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ package sharedaction_test
import (
"archive/zip"
"io"
"log/slog"
"os"
"path/filepath"
"strings"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
)

func TestSharedAction(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Shared Actions Suite")
}

var _ = BeforeEach(func() {
log.SetLevel(log.PanicLevel)
var _ = BeforeSuite(func() {
// Suppress log output during tests. This equates with setting to panic-level severity in older logging libraries
slog.SetDefault(slog.New(slog.NewTextHandler(io.Discard, nil)))
})

// Thanks to Svett Ralchev
Expand Down
Loading