github.com/secure-build/gitlab-runner@v12.5.0+incompatible/helpers/archives/path_check_helper.go (about)

     1  package archives
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"os"
     7  	"path/filepath"
     8  	"strings"
     9  
    10  	"github.com/sirupsen/logrus"
    11  )
    12  
    13  func isPathAGitDirectory(path string) bool {
    14  	parts := strings.Split(filepath.Clean(path), string(filepath.Separator))
    15  	if len(parts) > 0 && parts[0] == ".git" {
    16  		return true
    17  	}
    18  	return false
    19  
    20  }
    21  
    22  func errorIfGitDirectory(path string) *os.PathError {
    23  	if !isPathAGitDirectory(path) {
    24  		return nil
    25  	}
    26  
    27  	return &os.PathError{
    28  		Op:   ".git inside of archive",
    29  		Path: path,
    30  		Err:  errors.New("Trying to archive or extract .git path"),
    31  	}
    32  }
    33  
    34  func printGitArchiveWarning(operation string) {
    35  	logrus.Warn(fmt.Sprintf("Part of .git directory is on the list of files to %s", operation))
    36  	logrus.Warn("This may introduce unexpected problems")
    37  }