github.com/nilium/gitlab-runner@v12.5.0+incompatible/commands/helpers/cache_init.go (about)

     1  package helpers
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/sirupsen/logrus"
     7  	"github.com/urfave/cli"
     8  
     9  	"gitlab.com/gitlab-org/gitlab-runner/common"
    10  )
    11  
    12  // CacheInitCommand will take a single directory/file path and initialize it
    13  // correctly for it to be used for cache. This command tries to support spaces
    14  // in directories name by using the the flags to specify which entries you want
    15  // to initialize.
    16  type CacheInitCommand struct{}
    17  
    18  func (c *CacheInitCommand) Execute(ctx *cli.Context) {
    19  	if ctx.NArg() == 0 {
    20  		logrus.Fatal("No arguments passed, at least 1 path is required.")
    21  	}
    22  
    23  	for _, path := range ctx.Args() {
    24  		err := os.Chmod(path, os.ModePerm)
    25  		if err != nil {
    26  			logrus.WithError(err).Error("failed to chmod path")
    27  		}
    28  	}
    29  }
    30  
    31  func init() {
    32  	common.RegisterCommand2("cache-init", "changed permissions for cache paths (internal)", &CacheInitCommand{})
    33  }