// populateSymlinks adds an isolated.File to files for each provided symlink
545378
func (ut *UploadTracker) populateSymlinks(symlinks []*Item) error {
	for _, item := range symlinks {
		l, err := ut.lOS.Readlink(item.Path)
		if err != nil {
			return fmt.Errorf("unable to resolve symlink for %q: %v", item.Path, err)
		}
		ut.isol.Files[item.RelPath] = isolated.SymLink(l)
	}
	return nil
}
943783
func makeSymlinks(targetName string, commandFns []func() *cobra.Command) error {
	wd, err := os.Getwd()
	if err != nil {
		return err
	}

	var errs bool
	for _, commandFn := range commandFns {
		command := commandFn()
		link := path.Join(wd, command.Name())

		err := os.Symlink(targetName, link)
		if err != nil {
			errs = true
			fmt.Println(err)
		}
	}

	if errs {
		return errors.New("Error creating one or more symlinks")
	}
	return nil
}
862434
func (n *NetNs) SymlinkCreate(name string) error {
	if n.netNS == nil {
		return errors.New("no netns set up")
	}
	b := make([]byte, 4)
	_, randErr := rand.Reader.Read(b)
	if randErr != nil {
		return randErr
	}

	nsName := fmt.Sprintf("%s-%x", name, b)
	symlinkPath := filepath.Join(NsRunDir, nsName)

	if err := os.Symlink(n.Path(), symlinkPath); err != nil {
		return err
	}

	fd, err := os.Open(symlinkPath)
	if err != nil {
		if removeErr := os.RemoveAll(symlinkPath); removeErr != nil {
			return removeErr
		}

		return err
	}

	n.symlink = fd

	return nil
}
674510
func (i *InternalTokenHelper) populateTokenPath() {
	homePath, err := homedir.Dir()
	if err != nil {
		panic(fmt.Sprintf("error getting user's home directory: %v", err))
	}
	i.tokenPath = filepath.Join(homePath, ".vault-token")
}
1206098
func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error {
	for key, values := range values {
		re, err := regexp.Compile("^(.*)\\[(.*)\\]$")
		if err != nil {
			return err
		}
		match := re.FindStringSubmatch(key)
		if len(match) == 3 {
			key = match[1]
			values = append([]string{match[2]}, values...)
		}
		fieldPath := strings.Split(key, ".")
		if filter.HasCommonPrefix(fieldPath) {
			continue
		}
		if err := populateFieldValueFromPath(msg, fieldPath, values); err != nil {
			return err
		}
	}
	return nil
}
978055
func ReadSymlinkedDirectory(path string) (string, error) {
	var realPath string
	var err error
	if realPath, err = filepath.Abs(path); err != nil {
		return "", fmt.Errorf("unable to get absolute path for %s: %s", path, err)
	}
	if realPath, err = filepath.EvalSymlinks(realPath); err != nil {
		return "", fmt.Errorf("failed to canonicalise path for %s: %s", path, err)
	}
	realPathInfo, err := os.Stat(realPath)
	if err != nil {
		return "", fmt.Errorf("failed to stat target '%s' of '%s': %s", realPath, path, err)
	}
	if !realPathInfo.Mode().IsDir() {
		return "", fmt.Errorf("canonical path points to a file '%s'", realPath)
	}
	return realPath, nil
}
479474
func (f *sendReceiveFolder) handleSymlink(file protocol.FileInfo, dbUpdateChan chan<- dbUpdateJob, scanChan chan<- string) {
	// Used in the defer closure below, updated by the function body. Take
	// care not declare another err.
	var err error

	events.Default.Log(events.ItemStarted, map[string]string{
		"folder": f.folderID,
		"item":   file.Name,
		"type":   "symlink",
		"action": "update",
	})

	defer func() {
		events.Default.Log(events.ItemFinished, map[string]interface{}{
			"folder": f.folderID,
			"item":   file.Name,
			"error":  events.Error(err),
			"type":   "symlink",
			"action": "update",
		})
	}()

	if shouldDebug() {
		curFile, _ := f.fset.Get(protocol.LocalDeviceID, file.Name)
		l.Debugf("need symlink\n\t%v\n\t%v", file, curFile)
	}

	if len(file.SymlinkTarget) == 0 {
		// Index entry from a Syncthing predating the support for including
		// the link target in the index entry. We log this as an error.
		f.newPullError(file.Name, errIncompatibleSymlink)
		return
	}

	// There is already something under that name, we need to handle that.
	if info, err := f.fs.Lstat(file.Name); err == nil {
		// Check that it is what we have in the database.
		curFile, hasCurFile := f.model.CurrentFolderFile(f.folderID, file.Name)
		if changed, err := f.itemChanged(info, curFile, hasCurFile, scanChan); err != nil {
			f.newPullError(file.Name, err)
			return
		} else if changed {
			l.Debugln("item changed on disk compared to db; not replacing with symlink:", file.Name)
			scanChan <- curFile.Name
			f.newPullError(file.Name, errModified)
			return
		}
		// Remove it to replace with the symlink. This also handles the
		// "change symlink type" path.
		if !curFile.IsDirectory() && !curFile.IsSymlink() && f.inConflict(curFile.Version, file.Version) {
			// The new file has been changed in conflict with the existing one. We
			// should file it away as a conflict instead of just removing or
			// archiving. Also merge with the version vector we had, to indicate
			// we have resolved the conflict.
			// Directories and symlinks aren't checked for conflicts.

			file.Version = file.Version.Merge(curFile.Version)
			err = osutil.InWritableDir(func(name string) error {
				return f.moveForConflict(name, file.ModifiedBy.String(), scanChan)
			}, f.fs, curFile.Name)
		} else {
			err = f.deleteItemOnDisk(curFile, scanChan)
		}
		if err != nil {
			f.newPullError(file.Name, errors.Wrap(err, "symlink remove"))
			return
		}
	}

	// We declare a function that acts on only the path name, so
	// we can pass it to InWritableDir.
	createLink := func(path string) error {
		if err := f.fs.CreateSymlink(file.SymlinkTarget, path); err != nil {
			return err
		}
		return f.maybeCopyOwner(path)
	}

	if err = osutil.InWritableDir(createLink, f.fs, file.Name); err == nil {
		dbUpdateChan <- dbUpdateJob{file, dbUpdateHandleSymlink}
	} else {
		f.newPullError(file.Name, errors.Wrap(err, "symlink create"))
	}
}
179541
func (r *Response) populatePageValues() {
	if links, ok := r.Response.Header["Link"]; ok && len(links) > 0 {
		for _, link := range strings.Split(links[0], ",") {
			segments := strings.Split(strings.TrimSpace(link), ";")

			// link must at least have href and rel
			if len(segments) < 2 {
				continue
			}

			// ensure href is properly formatted
			if !strings.HasPrefix(segments[0], "<") || !strings.HasSuffix(segments[0], ">") {
				continue
			}

			// try to pull out page parameter
			url, err := url.Parse(segments[0][1 : len(segments[0])-1])
			if err != nil {
				continue
			}
			page := url.Query().Get("page")
			if page == "" {
				continue
			}

			for _, segment := range segments[1:] {
				switch strings.TrimSpace(segment) {
				case `rel="next"`:
					r.NextPage, _ = strconv.Atoi(page)
				case `rel="prev"`:
					r.PrevPage, _ = strconv.Atoi(page)
				case `rel="first"`:
					r.FirstPage, _ = strconv.Atoi(page)
				case `rel="last"`:
					r.LastPage, _ = strconv.Atoi(page)
				}

			}
		}
	}
}
73521
func (bb *Builder) PopulateDirectoryMap(staticSetRef blob.Ref) *Builder {
	bb.m["camliType"] = "directory"
	bb.m["entries"] = staticSetRef.String()
	return bb
}
1359909
func (sf StaticFile) AsStaticSymlink() (s StaticSymlink, ok bool) {
	if sf.b.ss.Type == "symlink" {
		return StaticSymlink{sf}, true
	}

	return
}
40110
func (n *roFileVersionsDir) populate(ctx context.Context) error {
	n.mu.Lock()
	defer n.mu.Unlock()

	// Things never change here, so if we've ever populated, we're
	// populated.
	if n.children != nil {
		return nil
	}

	Logger.Printf("roFileVersionsDir.populate(%q)", n.fullPath())
	res, err := n.fs.client.GetClaims(ctx, &search.ClaimsRequest{n.permanode, "camliContent"})
	if err != nil {
		return errors.New("error while getting claims")
	}

	n.children = make(map[string]roFileOrDir)
	for _, cl := range res.Claims {
		pn, ok := blob.Parse(cl.Value)
		if !ok {
			return errors.New("invalid blobref")
		}
		res, err := n.fs.client.Describe(ctx, &search.DescribeRequest{
			BlobRef: pn, // this is camliContent
			Depth:   1,
			At:      cl.Date,
		})
		if err != nil {
			return errors.New("blobref not described")
		}
		db := res.Meta[cl.Value]
		if db == nil {
			return errors.New("blobref not described")
		}
		name := cl.Date.String()
		n.children[name] = &roFileVersion{
			fs:        n.fs,
			permanode: n.permanode,
			parent:    n,
			name:      name,
			content:   db.BlobRef,
			size:      db.File.Size,
			mtime:     cl.Date.Time(),
		}

	}
	return nil
}
322800
func (cMgr *ConfigurationManager) populateMap(prefix string, mapType reflect.Type, rValues reflect.Value) (reflect.Value, error) {
	tagList := cMgr.getTagList(prefix, rValues)

	rValuePtr := reflect.New(mapType)
	rValue := rValuePtr.Elem()
	rValue.Set(reflect.MakeMap(mapType))
	//rValue := reflect.MakeMap(mapType)
	mapValueType := rValue.Type().Elem()

	configValue := cMgr.GetConfigurations()

	prefixForInline, inlineVal, mapKeys := cMgr.getMapKeys(configValue, prefix, tagList)

	if strings.Contains(prefix, "inline") {
		return cMgr.setValuesForInline(mapValueType, inlineVal, prefixForInline, rValue)
	}
	for _, key := range mapKeys {
		// if key itself has map value stored
		if key == "" {
			val := cMgr.GetConfigurationsByKey(prefix)
			setVal := reflect.ValueOf(val)
			if mapType != setVal.Type() {
				return rValue, fmt.Errorf("invalid value for map %s", mapType.String())

			}
			if rValue.CanSet() {
				rValue.Set(setVal)
			}
			return rValue, nil
		}

		switch mapValueType.Kind() {
		// for '.' separated configurations
		case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
			reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16,
			reflect.Uint32, reflect.Uint64, reflect.Bool, reflect.Interface:
			val := cMgr.GetConfigurationsByKey(prefix + key)
			setVal := reflect.ValueOf(val)

			if mapValueType != setVal.Type() {
				returnCongValue, err := ToRvalueType(setVal.Interface(), mapValueType)
				if err != nil {
					return rValue, fmt.Errorf("value types of %s not matched. expect type : %s, config client type : %s",
						prefix+key, mapValueType, setVal.String())
				}

				setVal = returnCongValue
			}

			if rValue.CanSet() {
				rValue.SetMapIndex(reflect.ValueOf(key[1:]), setVal)
			}
		default:
			splitKey := strings.Split(key, `.`)
			mapKey := splitKey[1]
			mapValue := reflect.New(mapValueType)
			err := cMgr.unmarshal(mapValue, getTagKey(prefix, mapKey))
			if err != nil {
				return rValue, err
			}

			if rValue.CanSet() {
				rValue.SetMapIndex(reflect.ValueOf(mapKey), mapValue.Elem())
			}
		}
	}

	return rValue, nil
}
933575
func (n *node) populateAttr() error {
	meta := n.meta

	n.attr.Mode = meta.FileMode()

	if n.fs.IgnoreOwners {
		n.attr.Uid = uint32(os.Getuid())
		n.attr.Gid = uint32(os.Getgid())
		executeBit := n.attr.Mode & 0100
		n.attr.Mode = (n.attr.Mode ^ n.attr.Mode.Perm()) | 0400 | executeBit
	} else {
		n.attr.Uid = uint32(meta.MapUid())
		n.attr.Gid = uint32(meta.MapGid())
	}

	// TODO: inode?

	if mt := meta.ModTime(); !mt.IsZero() {
		n.attr.Mtime = mt
	} else {
		n.attr.Mtime = n.pnodeModTime
	}

	switch meta.Type() {
	case "file":
		n.attr.Size = uint64(meta.PartsSize())
		n.attr.Blocks = 0 // TODO: set?
		n.attr.Mode |= 0400
	case "directory":
		n.attr.Mode |= 0500
	case "symlink":
		n.attr.Mode |= 0400
	default:
		Logger.Printf("unknown attr ss.Type %q in populateAttr", meta.Type())
	}
	return nil
}
1112842
func (sc *Client) ResolveSymlink(path string) string {
	pointer, err := sc.ReadLink(path)
	if err != nil {
		return path
	}
	return pointer
}
111438
func (v VolumePathHandler) GetDeviceSymlinkRefs(devPath string, mapPath string) ([]string, error) {
	var refs []string
	files, err := ioutil.ReadDir(mapPath)
	if err != nil {
		return nil, fmt.Errorf("Directory cannot read %v", err)
	}
	for _, file := range files {
		if file.Mode()&os.ModeSymlink != os.ModeSymlink {
			continue
		}
		filename := file.Name()
		fp, err := os.Readlink(filepath.Join(mapPath, filename))
		if err != nil {
			return nil, fmt.Errorf("Symbolic link cannot be retrieved %v", err)
		}
		klog.V(5).Infof("GetDeviceSymlinkRefs: filepath: %v, devPath: %v", fp, devPath)
		if fp == devPath {
			refs = append(refs, filepath.Join(mapPath, filename))
		}
	}
	klog.V(5).Infof("GetDeviceSymlinkRefs: refs %v", refs)
	return refs, nil
}
1114829
func (ts *TxStore) PopulateAdrs() error {
	keys := ts.keyManager.GetKeys()
	ts.addrMutex.Lock()
	ts.adrs = []btcutil.Address{}
	for _, k := range keys {
		addr, err := k.Address(ts.params)
		if err != nil {
			continue
		}
		ts.adrs = append(ts.adrs, addr)
	}
	ts.addrMutex.Unlock()

	ts.watchedScripts, _ = ts.WatchedScripts().GetAll()
	txns, _ := ts.Txns().GetAll(true)
	ts.txidsMutex.Lock()
	for _, t := range txns {
		ts.txids[t.Txid] = t.Height
	}
	ts.txidsMutex.Unlock()

	return nil
}
64830
func (RealOS) Symlink(oldname string, newname string) error {
	return os.Symlink(oldname, newname)
}