+ // Sanity check to verify that we have RW permission and path-mapping is correct
+ dir := cfg.ClientPath
+ if !common.Exists(dir) {
+ // try to create if not existing
+ if err := os.MkdirAll(dir, 0755); err != nil {
+ return nil, fmt.Errorf("Cannot create ClientPath directory: %s", dir)
+ }
+ }
+ if !common.Exists(dir) {
+ return nil, fmt.Errorf("ClientPath directory is not accessible: %s", dir)
+ }
+ if file, err = ioutil.TempFile(dir, ".xds_pathmap_check"); err != nil {
+ return nil, fmt.Errorf(errMsg, 1, err)
+ }
+ // Write a specific message that will be check by server during folder add
+ msg := "Pathmap checked message written by xds-agent ID: " + p.Config.AgentUID + "\n"
+ if n, err := file.WriteString(msg); n != len(msg) || err != nil {
+ return nil, fmt.Errorf(errMsg, 2, err)
+ }
+ defer func() {
+ if file != nil {
+ os.Remove(file.Name())
+ file.Close()
+ }
+ }()