Beispiel #1
0
func handleBatchRemove(req *http.Request, storage blobserver.Storage) (interface{}, error) {
	res := new(protocol.RemoveResponse)
	n := 0
	toRemove := make([]blob.Ref, 0)

	for {
		n++
		if n > maxRemovesPerRequest {
			return nil, newRateLimitError(maxRemovesPerRequest)
		}

		key := fmt.Sprintf("blob%v", n)
		value := req.FormValue(key)
		ref, ok := blob.Parse(value)

		if !ok {
			break
		}

		toRemove = append(toRemove, ref)
	}

	err := storage.RemoveBlobs(toRemove)

	if err != nil {
		log.Errorf("Server error during remove: %v", err)
		return nil, newHTTPError("Server error", http.StatusInternalServerError)
	}

	res.Removed = toRemove
	return res, nil
}
Beispiel #2
0
func handleStat(req *http.Request, storage blobserver.BlobStatter, blobs []string) (interface{}, error) {
	res := new(protocol.StatResponse)
	needStat := map[blob.Ref]bool{}
	n := 0

	for _, value := range blobs {
		n++
		if value == "" {
			n--
			break
		}
		if n > maxStatBlobs {
			return nil, newRateLimitError(maxStatBlobs)
		}
		ref, ok := blob.Parse(value)
		if !ok {
			return nil, newHTTPError("Bogus blobref for value", http.StatusBadRequest)
		}
		needStat[ref] = true
	}

	toStat := make([]blob.Ref, 0, len(needStat))

	for br := range needStat {
		toStat = append(toStat, br)
	}

	log.Printf("Need to stat blob cnt: %d, got %d", len(needStat), len(blobs))
	blobch := make(chan blob.SizedInfoRef)
	errch := make(chan error, 1)

	go func() {
		err := storage.StatBlobs(blobch, toStat)
		close(blobch)
		errch <- err
	}()

	for sb := range blobch {
		res.Stat = append(res.Stat, protocol.RefInfo{
			Ref:  sb.Ref,
			Size: uint32(sb.Size),
			MD5:  sb.MD5,
		})
		delete(needStat, sb.Ref)
	}

	err := <-errch

	if err != nil {
		log.Errorf("Stat error: %v", err)
		return nil, newHTTPError("Server Error", http.StatusInternalServerError)
	}

	return res, nil
}
Beispiel #3
0
func handleRemove(req *http.Request, storage blobserver.Storage) (interface{}, error) {
	res := new(protocol.RemoveResponse)
	vars := mux.Vars(req)
	ref, ok := blob.Parse(vars["blobRef"])
	if !ok {
		return nil, newHTTPError("Invalid blob ref", http.StatusBadRequest)
	}
	toRemove := []blob.Ref{ref}
	err := storage.RemoveBlobs(toRemove)

	if err != nil {
		log.Errorf("Server error during remove: %v", err)
		return nil, newHTTPError("Server error", http.StatusInternalServerError)
	}

	res.Removed = toRemove
	return res, nil
}