Ejemplo n.º 1
0
func (h *Handler) GetManifests(ids [][]byte) (r []*wire.Manifest, err error) {
	var req proto.IDSlice
	if err = (&req).UnmarshalThrift(ids); err != nil {
		return
	}
	logx.Debugf("serving manifests %s", req)

	res, err := h.Storage.GetManifests(req)
	if err != nil {
		logx.Error(err)
		return
	}

	r, err = proto.ManifestSlice(res).MarshalThrift()
	logx.Debugf("manifests served %s", req)

	return
}
Ejemplo n.º 2
0
func (u *Upload) SendCreateUpload(links lists.BlobMap) (missing []proto.ID, err error) {
	cli, err := u.Transport.tPool.Take()
	if err != nil {
		return
	}
	defer cli.Release()

	mans := proto.ManifestSlice(links.GetManifestSlice())
	tSlice, err := mans.MarshalThrift()
	if err != nil {
		return
	}

	res1, err := cli.CreateUpload((*u.UUID)[:], tSlice, int64(u.ttl))
	if err != nil {
		return
	}
	var r2 proto.IDSlice
	err = (&r2).UnmarshalThrift(res1)
	missing = r2
	return
}
Ejemplo n.º 3
0
func (s *BlockStorage) CreateUploadSession(uploadID uuid.UUID, in []proto.Manifest, ttl time.Duration) (missing []proto.ID, err error) {
	hexid := proto.ID(hex.EncodeToString(uploadID[:]))

	// take lock
	lock, err := s.FDLocks.Take()
	if err != nil {
		return
	}
	defer lock.Release()

	// Create directories and write support data
	base := filepath.Join(s.idPath(upload_ns,
		proto.ID(hex.EncodeToString(uploadID[:]))), manifests_ns)
	if err = os.MkdirAll(base, 0755); err != nil {
		return
	}

	var missingBlobs []proto.Manifest

	for _, m := range in {
		if err = func(m proto.Manifest) (err error) {
			var statErr error
			_, statErr = os.Stat(s.idPath(manifests_ns, m.ID))
			if os.IsNotExist(statErr) {
				missingBlobs = append(missingBlobs, m)
			} else if statErr != nil {
				err = statErr
				return
			} else {
				// exists - ok
				return
			}

			w, err := os.OpenFile(filepath.Join(base, m.ID.String()+"-manifest.json"),
				os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644)
			if err != nil {
				return
			}
			defer w.Close()
			err = json.NewEncoder(w).Encode(&m)
			return
		}(m); err != nil {
			return
		}
	}

	missing = proto.ManifestSlice(missingBlobs).GetChunkSlice()

	w, err := os.OpenFile(filepath.Join(s.idPath(upload_ns, hexid), "expires.timestamp"),
		os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644)
	if err != nil {
		return
	}
	defer w.Close()

	if _, err = w.Write([]byte(fmt.Sprintf("%d", time.Now().Add(ttl).UnixNano()))); err != nil {
		return
	}
	logx.Debugf("upload session %s created succefully", hexid)
	return
}