Example #1
0
func (m *Mapper) remap(from, to string, arg ...string) (res []string, err error) {
	logx.Tracef("remapping from %s to %s %s", from, to, arg)
	if filepath.ToSlash(from) == filepath.ToSlash(to) {
		res = arg
		return
	}
	var one string
	for _, p := range arg {
		if one, err = filepath.Rel(OSFromSlash(to), OSFromSlash(OSJoin(from, p))); err != nil {
			logx.Errorf(">>> %s %s %s", err, OSJoin(from, p), to)
			return
		}
		res = append(res, one)
	}
	logx.Tracef("remapped %s", res)

	return
}
Example #2
0
File: model.go Project: akaspin/bar
func (m *Model) getManifest(name string, blobs, manifests bool) (res *proto.Manifest, err error) {
	lock, err := m.FdLocks.Take()
	if err != nil {
		return
	}
	defer lock.Release()

	logx.Tracef("feeding manifest from %s",
		lists.OSFromSlash(lists.OSJoin(m.WD, name)))
	f, err := os.Open(lists.OSFromSlash(lists.OSJoin(m.WD, name)))
	if err != nil {
		logx.Errorf("!!! %s", err)
		return
	}
	defer f.Close()

	var r io.Reader
	var isManifest bool
	if r, isManifest, err = proto.PeekManifest(f); err != nil {
		return
	}
	if (isManifest && !manifests) || (!isManifest && !blobs) {
		return
	}

	if isManifest {
		res, err = proto.NewFromManifest(r)
		return
	}
	// Hard way. First - try git
	var sideR io.Reader
	if m.Git != nil {
		if sideR = m.getGitReader(name); sideR != nil {
			res, err = proto.NewFromAny(sideR, m.chunkSize)
			return
		}
	}
	// No git - make from blob
	res, err = proto.NewFromBLOB(r, m.chunkSize)
	return
}
Example #3
0
func (h *Handlers) HandleSpec(w http.ResponseWriter, r *http.Request) {
	id := proto.ID(strings.TrimPrefix(r.URL.Path, "/v1/spec/"))

	logx.Debugf("serving spec %s", id)

	ok, err := h.Storage.IsSpecExists(id)
	if err != nil {
		logx.Error(err)
		w.WriteHeader(500)
		return
	}
	if !ok {
		logx.Errorf("bad spec id %s", id)
		w.WriteHeader(404)
		return
	}
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	h.handleTpl(w, "spec", map[string]interface{}{
		"Info":    h.options.Info,
		"ID":      id,
		"ShortID": id[:12],
	})
}