Beispiel #1
0
func parseSyncPackage(r *tar.Reader) (pkg *pkginfo.Package, err error) {
	var hdr *tar.Header

	if hdr, err = r.Next(); err != nil {
		return nil, err
	}

	if hdr.Typeflag != tar.TypeDir {
		return nil, errors.New(fmt.Sprintf("expected directory, found %s (%d)", hdr.Name, hdr.Typeflag))
	}

	dirPath := hdr.Name
	descPath := path.Join(dirPath, "desc")
	depsPath := path.Join(dirPath, "depends")

	var desc *pkginfo.Desc
	var deps *pkginfo.Deps

	for desc == nil || deps == nil {
		if hdr, err = tarMustNext(r.Next()); err != nil {
			return
		}

		if hdr.Typeflag != tar.TypeReg && hdr.Typeflag != tar.TypeRegA {
			err = errors.New(fmt.Sprintf("expected file, found %d (%s)", hdr.Typeflag, hdr.Name))
			return
		}

		pkgReader := paclist.NewReader(r)

		switch hdr.Name {
		default:
			err = errors.New(fmt.Sprintf("expected %s | %s, found %s", descPath, depsPath, hdr.Name))
		case descPath:
			desc, err = pkginfo.DecodeDesc(pkgReader)
		case depsPath:
			deps, err = pkginfo.DecodeDeps(pkgReader)
		}

		if err != nil {
			err = errors.New(fmt.Sprintf("couldn't load package %s: %s", dirPath, err))
			return
		}
	}

	return &pkginfo.Package{*desc, *deps}, nil
}
Beispiel #2
0
func main() {
	fmt.Println(paclist.Decode(paclist.NewReader(os.Stdin)))
}