in cmd/mount_all.go [265:340]
func mountAllContainers(containerList []string, configFile string, mountPath string, configFileExists bool) error {
// Now iterate filtered container list and prepare mount path, temp path, and config file for them
fileCachePath := ""
_ = config.UnmarshalKey("file_cache.path", &fileCachePath)
// Generate slice containing all the argument which we need to pass to each mount command
cliParams := buildCliParamForMount()
// Change the config file name per container
ext := filepath.Ext(configFile)
if ext == SecureConfigExtension {
ext = ".yaml"
}
// During mount all some extra config were set, we need to reset those now
viper.Set("mount-all-containers", nil)
//configFileName := configFile[:(len(configFile) - len(ext))]
configFileName := filepath.Join(os.ExpandEnv(common.DefaultWorkDir), "config")
failCount := 0
for _, container := range containerList {
contMountPath := filepath.Join(mountPath, container)
contConfigFile := configFileName + "_" + container + ext
if options.SecureConfig {
contConfigFile = contConfigFile + SecureConfigExtension
}
if _, err := os.Stat(contMountPath); os.IsNotExist(err) {
err = os.MkdirAll(contMountPath, 0777)
if err != nil {
fmt.Printf("Failed to create directory %s : %s\n", contMountPath, err.Error())
}
}
// NOTE : Add all the configs that need replacement based on container here
cliParams[1] = contMountPath
// If next instance is not mounted in background then mountall will hang up hence always mount in background
if configFileExists {
viper.Set("mount-path", contMountPath)
viper.Set("foreground", false)
viper.Set("azstorage.container", container)
viper.Set("file_cache.path", filepath.Join(fileCachePath, container))
// Create config file with container specific configs
err := writeConfigFile(contConfigFile)
if err != nil {
return err
}
cliParams[2] = "--config-file=" + contConfigFile
} else {
cliParams[2] = "--foreground=false"
updateCliParams(&cliParams, "container-name", container)
updateCliParams(&cliParams, "tmp-path", filepath.Join(fileCachePath, container))
}
// Now that we have mount path and config file for this container fire a mount command for this one
fmt.Println("Mounting container :", container, "to path ", contMountPath)
cmd := exec.Command(mountAllOpts.blobfuse2BinPath, cliParams...)
var errb bytes.Buffer
cmd.Stderr = &errb
cliOut, err := cmd.Output()
fmt.Println(string(cliOut))
if err != nil {
fmt.Printf("Failed to mount container %s : %s\n", container, errb.String())
failCount++
}
}
fmt.Printf("%d of %d containers were successfully mounted\n", (len(containerList) - failCount), len(containerList))
return nil
}