func (ds *Directory) statUnlocked(key string) (store.Stat, string, error) { fh, path, err := ds.findAndOpen(key) if err != nil { return store.Stat{}, "", err } if fh == nil { return store.Stat{}, "", store.ErrNotFound } defer fh.Close() st := store.Stat{} _, err = fh.ReadAt(st.SHA256[:], 8) if err != nil { return store.Stat{}, "", err } fi, err := fh.Stat() if err != nil { return store.Stat{}, "", err } st.Size = fi.Size() - 40 st.WriteTime = fi.ModTime().Unix() return st, path, nil }
func ShouldStatNoTime(t testing.TB, s store.Store, key string, stat store.Stat) { st, err := s.Stat(key, nil) if err != nil { t.Errorf("Stat(%#v) returned unexpected error %v", key, err) return } stat.WriteTime = st.WriteTime if st != stat { t.Errorf("Stat(%#v) = %#v, but wanted %#v", key, st, stat) } }
func (cc *Client) Stat(key string, cancel <-chan struct{}) (store.Stat, error) { resp, err := cc.startReq("HEAD", cc.url+url.QueryEscape(key), nil, nil, cancel) if err != nil { return store.Stat{}, err } defer resp.Body.Close() if resp.StatusCode == 404 { return store.Stat{}, store.ErrNotFound } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return store.Stat{}, httputil.ReadResponseAsError(resp) } st := store.Stat{} if sha := resp.Header.Get("X-Content-Sha256"); sha != "" { shaBytes, err := hex.DecodeString(sha) if err != nil || len(shaBytes) != 32 { return store.Stat{}, ErrUnparsableSHAResponse } copy(st.SHA256[:], shaBytes) } if timeStr := resp.Header.Get("Last-Modified"); timeStr != "" { t, err := time.Parse(http.TimeFormat, timeStr) if err == nil { st.WriteTime = t.Unix() } } st.Size = resp.ContentLength return st, nil }