// UpdateFromFile populates the Config from the TOML-encoded file at the given path.
// Returns errors encountered when reading or parsing the files, or nil
// otherwise.
508743
func (c *Config) UpdateFromFile(path string) error {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return err
	}

	t := new(tomlConfig)
	t.fromConfig(c)

	_, err = toml.Decode(string(data), t)
	if err != nil {
		return fmt.Errorf("unable to decode configuration %v: %v", path, err)
	}

	t.toConfig(c)
	return nil
}
278449
func (c KbfsClient) FSPathUpdate(ctx context.Context, path string) (err error) {
	__arg := FSPathUpdateArg{Path: path}
	err = c.Cli.Notify(ctx, "keybase.1.kbfs.FSPathUpdate", []interface{}{__arg})
	return
}
668565
func (p *Project) LoadEnvFromFile(path string) error {
	p.Log.Debugf("load env from file %q", path)
	var env map[string]string

	f, err := os.Open(path)
	if err != nil {
		return err
	}
	defer f.Close()

	if err := json.NewDecoder(f).Decode(&env); err != nil {
		return err
	}

	for k, v := range env {
		p.Setenv(k, v)
	}

	return nil
}
825466
func (w *walker) updateFileInfo(file, curFile protocol.FileInfo) protocol.FileInfo {
	if file.Type == protocol.FileInfoTypeFile && runtime.GOOS == "windows" {
		// If we have an existing index entry, copy the executable bits
		// from there.
		file.Permissions |= (curFile.Permissions & 0111)
	}
	file.Version = curFile.Version.Update(w.ShortID)
	file.ModifiedBy = w.ShortID
	file.LocalFlags = w.LocalFlags
	return file
}
877694
func (l *UpdateableFileLock) Update(contents io.Reader) error {
	lockDir := filepath.Dir(l.path)
	newFile, err := ioutil.TempFile(lockDir, fmt.Sprintf(".%s", filepath.Base(l.path)))
	if err != nil {
		return err
	}
	defer newFile.Close()
	if err := newFile.Chmod(l.perms); err != nil {
		os.Remove(newFile.Name())
		return err
	}

	_, err = io.Copy(newFile, contents)
	if err != nil {
		os.Remove(newFile.Name())
		return err
	}

	newFileLock, err := lock.TryExclusiveLock(newFile.Name(), lock.RegFile)
	if err != nil {
		os.Remove(newFile.Name())
		return fmt.Errorf("could not lock tmpfile: %v", err)
	}

	l.lockLock.Lock()
	defer l.lockLock.Unlock()

	if !l.isLocked {
		os.Remove(newFile.Name())
		return AlreadyUnlockedErr
	}
	// Overwrite the old lock with our new one that has the correct contents
	err = os.Rename(newFile.Name(), l.path)
	if err != nil {
		return err
	}
	// Lock overwritten, update our internal state while we still hold the mutex
	oldLock := l.lock
	l.lock = newFileLock
	oldLock.Unlock()
	return nil
}
904755
func certificatesFromFile(file string) ([]*x509.Certificate, error) {
	if len(file) == 0 {
		return nil, errors.New("error reading certificates from an empty filename")
	}
	pemBlock, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, err
	}
	certs, err := CertsFromPEM(pemBlock)
	if err != nil {
		return nil, fmt.Errorf("error reading %s: %s", file, err)
	}
	return certs, nil
}
1195864
func (rc *RequestConfig) SetFileFromPath(uploads []UploadFile, params ...H) *RequestConfig {
	body := new(bytes.Buffer)
	writer := multipart.NewWriter(body)

	for _, f := range uploads {
		reader := bytes.NewReader(f.Content)
		if reader.Size() == 0 {
			file, err := os.Open(f.Path)
			if err != nil {
				log.Fatal(err)
			}

			defer file.Close()
			part, err := writer.CreateFormFile(f.Name, filepath.Base(f.Path))
			if err != nil {
				log.Fatal(err)
			}
			_, err = io.Copy(part, file)
			if err != nil {
				log.Fatal(err)
			}
		} else {
			part, err := writer.CreateFormFile(f.Name, filepath.Base(f.Path))
			if err != nil {
				log.Fatal(err)
			}
			_, err = reader.WriteTo(part)
			if err != nil {
				log.Fatal(err)
			}
		}
	}

	if len(params) > 0 {
		for key, val := range params[0] {
			_ = writer.WriteField(key, val)
		}
	}

	err := writer.Close()
	if err != nil {
		log.Fatal(err)
	}

	rc.ContentType = writer.FormDataContentType()
	rc.Body = body.String()

	return rc
}
815714
func (v *Context) SetFile(path string) {
	if v.file != path {
		v.file = path
		v.element = nil
	}
}
805235
func (vl VersionList) update(folder, device []byte, file protocol.FileInfo, t readOnlyTransaction) (_ VersionList, removedFV FileVersion, removedAt int, insertedAt int) {
	vl, removedFV, removedAt = vl.pop(device)

	nv := FileVersion{
		Device:  device,
		Version: file.Version,
		Invalid: file.IsInvalid(),
	}
	i := 0
	if nv.Invalid {
		i = sort.Search(len(vl.Versions), func(j int) bool {
			return vl.Versions[j].Invalid
		})
	}
	for ; i < len(vl.Versions); i++ {
		switch vl.Versions[i].Version.Compare(file.Version) {
		case protocol.Equal:
			fallthrough

		case protocol.Lesser:
			// The version at this point in the list is equal to or lesser
			// ("older") than us. We insert ourselves in front of it.
			vl = vl.insertAt(i, nv)
			return vl, removedFV, removedAt, i

		case protocol.ConcurrentLesser, protocol.ConcurrentGreater:
			// The version at this point is in conflict with us. We must pull
			// the actual file metadata to determine who wins. If we win, we
			// insert ourselves in front of the loser here. (The "Lesser" and
			// "Greater" in the condition above is just based on the device
			// IDs in the version vector, which is not the only thing we use
			// to determine the winner.)
			//
			// A surprise missing file entry here is counted as a win for us.
			if of, ok := t.getFile(folder, vl.Versions[i].Device, []byte(file.Name)); !ok || file.WinsConflict(of) {
				vl = vl.insertAt(i, nv)
				return vl, removedFV, removedAt, i
			}
		}
	}

	// We didn't find a position for an insert above, so append to the end.
	vl.Versions = append(vl.Versions, nv)

	return vl, removedFV, removedAt, len(vl.Versions) - 1
}
247699
func tokenFromFile(say func(string), oauthCfg adal.OAuthConfig, tokenPath, clientID, resource string,
	callback adal.TokenRefreshCallback) (*adal.ServicePrincipalToken, error) {
	say(fmt.Sprintf("Loading auth token from file: %s", tokenPath))
	if _, err := os.Stat(tokenPath); err != nil {
		if os.IsNotExist(err) { // file not found
			return nil, nil
		}
		return nil, err
	}

	token, err := adal.LoadToken(tokenPath)
	if err != nil {
		return nil, fmt.Errorf("Failed to load token from file: %v", err)
	}

	spt, err := adal.NewServicePrincipalTokenFromManualToken(oauthCfg, clientID, resource, *token, callback)
	if err != nil {
		return nil, fmt.Errorf("Error constructing service principal token: %v", err)
	}
	return spt, nil
}
894048
func (v *StrVCS) SetFile(revision, path string, contents []byte) {
	if v.files == nil {
		v.files = make(map[string]map[string][]byte)
	}
	if _, ok := v.files[revision]; !ok {
		v.files[revision] = make(map[string][]byte)
	}
	v.files[revision][path] = contents
}
79322
func (c Config) ToFile(file string) error {
	if err := validateConfig(c); err != nil {
		return errors.Wrap(err, "config isn't valid")
	}
	b, _ := yaml.Marshal(c)
	if err := ioutil.WriteFile(file, b, 0600); err != nil {
		return errors.Errorf("failed writing file %s: %v", file, err)
	}
	return nil
}
1111993
func NewTomlSourceFromFile(file string) (InputSourceContext, error) {
	tsc := &tomlSourceContext{FilePath: file}
	var results tomlMap = tomlMap{}
	if err := readCommandToml(tsc.FilePath, &results); err != nil {
		return nil, fmt.Errorf("Unable to load TOML file '%s': inner error: \n'%v'", tsc.FilePath, err.Error())
	}
	return &MapInputSource{valueMap: results.Map}, nil
}
1051849
func NewJSONFromFile(path string) *JSON {
	return NewJSON(func() (io.Reader, error) {
		return os.Open(path)
	})
}
608124
func (client *Client) UpdateLIFF(liffID string, view View) *UpdateLIFFCall {
	return &UpdateLIFFCall{
		c:      client,
		liffID: liffID,
		view:   view,
	}
}
581460
func (c *Config) ToFile(path string) error {
	var w bytes.Buffer
	e := toml.NewEncoder(&w)

	t := new(tomlConfig)
	t.fromConfig(c)

	if err := e.Encode(*t); err != nil {
		return err
	}

	return ioutil.WriteFile(path, w.Bytes(), 0644)
}
33621
func Update(i Installer) error {
	if _, pathErr := os.Stat(i.Path()); os.IsNotExist(pathErr) {
		return errors.New("plugin does not exist")
	}

	return i.Update()
}