当前位置: 首页>>代码示例>>Golang>>正文


Golang binarydist.Patch函数代码示例

本文整理汇总了Golang中github.com/kr/binarydist.Patch函数的典型用法代码示例。如果您正苦于以下问题:Golang Patch函数的具体用法?Golang Patch怎么用?Golang Patch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Patch函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: rebuild_file

func rebuild_file(c []child, patch_num int, dest string) string {
	if patch_num == 0 {
		return "restored/.tmp/" + c[0].Name
	}

	err := os.Rename("restored/.tmp/"+c[0].Name, "restored/.tmp/base")
	if err != nil {
		log.Fatal(err)
	}

	for i := 1; i <= patch_num; i++ {
		f, err := os.Open("restored/.tmp/base")
		if err != nil {
			log.Fatal(err)
		}
		m, err := os.OpenFile("restored/.tmp/master", os.O_CREATE|os.O_WRONLY, 0777)
		if err != nil {
			log.Fatal(err)
		}
		p, err := os.Open("restored/.tmp/" + c[i].Name)
		if err != nil {
			log.Fatal(err)
		}
		err = binarydist.Patch(f, m, p)
		if err != nil {
			log.Fatal(err)
		}
		m.Close()
		f.Close()
		p.Close()

		os.Rename("restored/.tmp/master", "restored/.tmp/base")
	}
	return "restored/.tmp/base"
}
开发者ID:rubiojr,项目名称:smog,代码行数:35,代码来源:smog.go

示例2: fetchAndApplyPatch

func (u *Updater) fetchAndApplyPatch(old io.Reader) ([]byte, error) {
	r, err := fetch(u.diffURL + u.cmdName + "/" + Version + "/" + u.info.Version + "/" + plat)
	if err != nil {
		return nil, err
	}
	defer r.Close()
	var buf bytes.Buffer
	err = binarydist.Patch(old, &buf, r)
	return buf.Bytes(), err
}
开发者ID:herokai,项目名称:hk,代码行数:10,代码来源:update.go

示例3: applyPatch

func applyPatch(patch io.Reader, updatePath string) ([]byte, error) {
	// open the file to update
	old, err := os.Open(updatePath)
	if err != nil {
		return nil, err
	}
	defer old.Close()

	// apply the patch
	applied := new(bytes.Buffer)
	if err = binarydist.Patch(old, applied, patch); err != nil {
		return nil, err
	}

	return applied.Bytes(), nil
}
开发者ID:ZhangBanger,项目名称:go-update,代码行数:16,代码来源:update.go

示例4: UpdateTo

// Update the currently running binary to a specific version
func (d *Dist) UpdateTo(to string) (err error) {
	if d.Version == to {
		return errors.New("nothing to update")
	}
	binary, _ := osext.Executable()
	reader, err := os.Open(binary)
	if err != nil {
		return err
	}
	defer reader.Close()
	url := fmt.Sprintf("%s/projects/%s/diff/%s/%s/%s-%s", d.Host, d.Project, d.Version, to, runtime.GOOS, runtime.GOARCH)
	patch, err := d.httpGet(url)
	if err != nil {
		return err
	}
	writer := new(bytes.Buffer)
	err = binarydist.Patch(reader, writer, bytes.NewReader(patch))
	if err != nil {
		return err
	}
	reader.Close()
	err, _ = update.FromStream(writer)
	return
}
开发者ID:ChaitanyaRanade,项目名称:force,代码行数:25,代码来源:dist.go

示例5: fetchAndApply

func (u *Updater) fetchAndApply() {
	instPath, err := exec.LookPath("hk")
	if err != nil {
		log.Fatal(err)
	}

	old, err := os.Open(instPath)
	if err != nil {
		log.Fatal(err)
	}

	plat := runtime.GOOS + "-" + runtime.GOARCH
	resp, err := http.Get(u.url + plat + "/" + Version + "/next.hkdiff")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		log.Fatal(resp.Status)
	}

	var header struct {
		Magic    [8]byte
		OldHash  [sha1.Size]byte
		NewHash  [sha1.Size]byte
		DiffHash [sha1.Size]byte
	}
	err = binary.Read(resp.Body, binary.BigEndian, &header)
	if err != nil {
		log.Fatal(err)
	}

	if header.Magic != magic {
		log.Fatal("format error in update file")
	}

	patch, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	if !sha1matches(header.OldHash, old) {
		log.Fatal("existing version hash match update")
	}

	if !sha1matches(header.DiffHash, bytes.NewReader(patch)) {
		log.Fatal("bad patch file")
	}

	_, err = old.Seek(0, 0)
	if err != nil {
		log.Fatal(err)
	}

	part := u.dir + upnextPath + ".part"
	newPart, err := os.OpenFile(part, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
	if err != nil {
		log.Fatal(err)
	}

	err = binarydist.Patch(old, newPart, bytes.NewReader(patch))
	if err != nil {
		log.Fatal(err)
	}

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

	newPart, err = os.Open(part)
	if err != nil {
		log.Fatal(err)
	}
	if !sha1matches(header.NewHash, newPart) {
		log.Fatal("checksum mismatch after patch")
	}

	err = os.Rename(part, u.dir+upnextPath)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:bmizerany,项目名称:hk,代码行数:84,代码来源:update.go

示例6: fetchAndApply

func (u *Updater) fetchAndApply() error {
	instPath, err := exec.LookPath("hk")
	if err != nil {
		return err
	}

	old, err := os.Open(instPath)
	if err != nil {
		return err
	}

	plat := runtime.GOOS + "-" + runtime.GOARCH
	name := "hk-" + Version + "-next-" + plat + ".hkdiff"
	resp, err := http.Get(u.url + name)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		log.Fatal(resp.Status)
	}

	var header struct {
		Magic    [8]byte
		OldHash  [sha1.Size]byte
		NewHash  [sha1.Size]byte
		DiffHash [sha1.Size]byte
	}
	err = binary.Read(resp.Body, binary.BigEndian, &header)
	if err != nil {
		return err
	}

	if header.Magic != magic {
		log.Fatal("format error in update file")
	}

	patch, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	if readSha1(old) != header.OldHash {
		log.Fatal("old hash mismatch")
	}

	if readSha1(bytes.NewReader(patch)) != header.DiffHash {
		log.Fatal("bad patch file")
	}

	_, err = old.Seek(0, 0)
	if err != nil {
		return err
	}

	var buf bytes.Buffer
	err = binarydist.Patch(old, &buf, bytes.NewReader(patch))
	if err != nil {
		return err
	}

	if readSha1(bytes.NewReader(buf.Bytes())) != header.NewHash {
		log.Fatal("checksum mismatch after patch")
	}

	part := path.Dir(instPath) + "/.hk.part"
	dstf, err := os.OpenFile(part, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
	if err != nil {
		return err
	}
	defer os.Remove(part)

	_, err = dstf.Write(buf.Bytes())
	if err != nil {
		return err
	}

	err = dstf.Close()
	if err != nil {
		return err
	}

	return os.Rename(part, instPath)
}
开发者ID:rmacy,项目名称:hk,代码行数:85,代码来源:update.go


注:本文中的github.com/kr/binarydist.Patch函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。