// writeEtcHosts writes the file /etc/rkt-hosts into the stage1 rootfs.
// This will read defaults from <rootfs>/etc/hosts-fallback if it exists.
// Therefore, this should be called after the stage1 is mounted
347850
func writeEtcHosts(cfg *RunConfig, rootfs string) {
	if cfg.DNSConfMode.Hosts != "stage0" {
		return
	}

	// Read <stage1>/rootfs/etc/hosts-fallback to get some sane defaults
	hostsTextb, err := ioutil.ReadFile(filepath.Join(rootfs, "etc/hosts-fallback"))
	if err != nil {
		// fallback-fallback :-)
		hostsTextb = []byte("#created by rkt stage0\n127.0.0.1 localhost localhost.localdomain\n")
	}
	hostsText := string(hostsTextb)

	hostsText += "\n\n# Added by rkt run --hosts-entry\n"

	for ip, hostnames := range cfg.HostsEntries {
		hostsText = fmt.Sprintf("%s%s %s\n", hostsText, ip, strings.Join(hostnames, " "))
	}

	// Create /etc if it does not exist
	etcPath := filepath.Join(rootfs, "etc")
	if _, err := os.Stat(etcPath); err != nil && os.IsNotExist(err) {
		err = os.Mkdir(etcPath, 0755)
		if err != nil {
			log.FatalE("failed to make stage1 etc directory", err)
		}
	} else if err != nil {
		log.FatalE("Failed to stat stage1 etc", err)
	}

	hostsPath := filepath.Join(etcPath, "rkt-hosts")
	err = ioutil.WriteFile(hostsPath, []byte(hostsText), 0644)
	if err != nil {
		log.FatalE("failed to write etc/rkt-hosts", err)
	}
}
909948
func (h *Hostsfile) readHosts() {
	file, err := os.Open(h.path)
	if err != nil {
		// We already log a warning if the file doesn't exist or can't be opened on setup. No need to return the error here.
		return
	}
	defer file.Close()

	stat, err := file.Stat()
	if err == nil && h.mtime.Equal(stat.ModTime()) && h.size == stat.Size() {
		return
	}

	h.Lock()
	defer h.Unlock()
	h.parseReader(file)

	// Update the data cache.
	h.mtime = stat.ModTime()
	h.size = stat.Size()
}
312000
func uploadRemoteBoshAssets(dm *enaml.DeploymentManifest, boshClient *enamlbosh.Client, poll bool) (err error) {
	var errStemcells error
	var errReleases error
	var remoteStemcells []enaml.Stemcell
	defer UIPrint("remote asset check complete.")
	UIPrint("Checking product deployment for remote assets...")

	if remoteStemcells, err = stemcellsToUpload(dm.Stemcells, boshClient); err == nil {
		if errStemcells = uploadRemoteStemcells(remoteStemcells, boshClient, poll); errStemcells != nil {
			lo.G.Info("issues processing stemcell: ", errStemcells)
		}
	}

	if errReleases = uploadRemoteReleases(dm.Releases, boshClient, poll); errReleases != nil {
		lo.G.Info("issues processing release: ", errReleases)
	}

	if errReleases != nil || errStemcells != nil {
		err = fmt.Errorf("stemcell err: %v   release err: %v", errStemcells, errReleases)
	}
	return
}
349724
func (m *MailYak) writeAttachments(mixed partCreator, splitter writeWrapper) error {
	h := make([]byte, sniffLen)

	for _, item := range m.attachments {
		hLen, err := item.content.Read(h)
		if err != nil && err != io.EOF {
			return err
		}

		if item.mimeType == "" {
			item.mimeType = http.DetectContentType(h[:hLen])
		}

		ctype := fmt.Sprintf("%s;\n\tfilename=%q", item.mimeType, item.filename)

		part, err := mixed.CreatePart(getMIMEHeader(item, ctype))
		if err != nil {
			return err
		}

		encoder := base64.NewEncoder(base64.StdEncoding, splitter.new(part))
		if _, err := encoder.Write(h[:hLen]); err != nil {
			return err
		}

		// More to write?
		if hLen == sniffLen {
			if _, err := io.Copy(encoder, item.content); err != nil {
				return err
			}
		}

		if err := encoder.Close(); err != nil {
			return err
		}
	}

	return nil
}
1238796
func writeNode(w io.Writer, fset *token.FileSet, x interface{}) {
	// convert trailing tabs into spaces using a tconv filter
	// to ensure a good outcome in most browsers (there may still
	// be tabs in comments and strings, but converting those into
	// the right number of spaces is much harder)
	//
	// TODO(gri) rethink printer flags - perhaps tconv can be eliminated
	//           with an another printer mode (which is more efficiently
	//           implemented in the printer than here with another layer)
	mode := printer.TabIndent | printer.UseSpaces
	err := (&printer.Config{Mode: mode, Tabwidth: tabwidth}).Fprint(&tconv{output: w}, fset, x)
	if err != nil {
		log.Print(err)
	}
}
569070
func (ctxt *Context) WriteFiles(files map[string]*ast.File) error {
	// TODO should we try to continue changing files even after an error?
	for _, f := range files {
		name := ctxt.filename(f)
		newSrc, err := ctxt.gofmtFile(f)
		if err != nil {
			return fmt.Errorf("cannot format %q: %v", name, err)
		}
		err = ioutil.WriteFile(name, newSrc, 0666)
		if err != nil {
			return fmt.Errorf("cannot write %q: %v", name, err)
		}
	}
	return nil
}
845910
func (cfg *cloudConfig) ManageEtcHosts(manage bool) {
	if manage {
		cfg.SetAttr("manage_etc_hosts", true)
	} else {
		cfg.UnsetAttr("manage_etc_hosts")
	}
}
16758
func (o *LaunchSpecification) SetDisks(v []*Disk) *LaunchSpecification {
	if o.Disks = v; o.Disks == nil {
		o.nullFields = append(o.nullFields, "Disks")
	}
	return o
}
351282
func (md *RootMetadataV3) SetWriters(writers []keybase1.UserOrTeamID) {
	md.WriterMetadata.Writers = writers
}
995357
func (c *configV7) setHost(alias string, cfg hostConfigV7) {
	if _, ok := c.Hosts[alias]; !ok {
		c.Hosts[alias] = cfg
	}
}
844721
func (w *Writer) WriteStructs(st interface{}) error {
	rows, err := w.e.Marshal(st)
	if err != nil {
		return err
	}
	w.r = len(rows)
	w.w.WriteAll(rows)
	w.w.Flush()
	return w.w.Error()
}
1374763
func (d *DNSProvider) setHosts(sld, tld string, hosts []Record) error {
	req, err := d.newRequestPost("namecheap.domains.dns.setHosts",
		addParam("SLD", sld),
		addParam("TLD", tld),
		func(values url.Values) {
			for i, h := range hosts {
				ind := fmt.Sprintf("%d", i+1)
				values.Add("HostName"+ind, h.Name)
				values.Add("RecordType"+ind, h.Type)
				values.Add("Address"+ind, h.Address)
				values.Add("MXPref"+ind, h.MXPref)
				values.Add("TTL"+ind, h.TTL)
			}
		},
	)
	if err != nil {
		return err
	}

	var shr setHostsResponse
	err = d.do(req, &shr)
	if err != nil {
		return err
	}

	if len(shr.Errors) > 0 {
		return fmt.Errorf("%s [%d]", shr.Errors[0].Description, shr.Errors[0].Number)
	}
	if shr.Result.IsSuccess != "true" {
		return fmt.Errorf("setHosts failed")
	}

	return nil
}
875015
func (s *InstanceAccessDetails) SetHostKeys(v []*HostKeyAttributes) *InstanceAccessDetails {
	s.HostKeys = v
	return s
}
212528
func (file *File) WriteAt(buf []byte, offset int64) (int, error) {
	return file.Fid.Clnt.Write(file.Fid, buf, uint64(offset))
}
935767
func (s *rootfsFilesystemSource) CreateFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemParams) ([]storage.CreateFilesystemsResult, error) {
	results := make([]storage.CreateFilesystemsResult, len(args))
	for i, arg := range args {
		filesystem, err := s.createFilesystem(arg)
		if err != nil {
			results[i].Error = err
			continue
		}
		results[i].Filesystem = filesystem
	}
	return results, nil
}
816768
func (s *ProvisioningArtifactPreferences) SetStackSetRegions(v []*string) *ProvisioningArtifactPreferences {
	s.StackSetRegions = v
	return s
}
355283
func (s *InstanceHardware) SetDisks(v []*Disk) *InstanceHardware {
	s.Disks = v
	return s
}