object-level API HeadObject returns the object properties; can be conventionally used to establish local (in cluster) presence.
(baseParams BaseParams, bck cmn.Bck, object string, checkExists ...bool)
| 140 | // HeadObject returns the object properties; can be conventionally used to establish |
| 141 | // local (in cluster) presence. |
| 142 | func HeadObject(baseParams BaseParams, bck cmn.Bck, object string, checkExists ...bool) (*cmn.ObjectProps, error) { |
| 143 | var ( |
| 144 | q url.Values |
| 145 | checkIsCached bool |
| 146 | ) |
| 147 | if len(checkExists) > 0 { |
| 148 | checkIsCached = checkExists[0] |
| 149 | } |
| 150 | baseParams.Method = http.MethodHead |
| 151 | |
| 152 | if checkIsCached { |
| 153 | q = make(url.Values, 4) |
| 154 | q = bck.AddToQuery(q) |
| 155 | q.Set(apc.QparamHeadObj, strconv.Itoa(apc.HeadObjAvoidRemote)) // TODO: support the entire enum |
| 156 | q.Set(apc.QparamSilent, "true") |
| 157 | } else { |
| 158 | q = bck.AddToQuery(nil) |
| 159 | } |
| 160 | |
| 161 | reqParams := AllocRp() |
| 162 | defer FreeRp(reqParams) |
| 163 | { |
| 164 | reqParams.BaseParams = baseParams |
| 165 | reqParams.Path = apc.URLPathObjects.Join(bck.Name, object) |
| 166 | reqParams.Query = q |
| 167 | } |
| 168 | resp, err := reqParams.doResp(nil) |
| 169 | if err != nil { |
| 170 | return nil, err |
| 171 | } |
| 172 | if checkIsCached { |
| 173 | return nil, err |
| 174 | } |
| 175 | |
| 176 | // NOTE: compare with `headObject()` in target.go |
| 177 | // first, cnm.ObjAttrs |
| 178 | op := &cmn.ObjectProps{} |
| 179 | op.Cksum = op.ObjAttrs.FromHeader(resp.Header) |
| 180 | // second, all the rest |
| 181 | err = cmn.IterFields(op, func(tag string, field cmn.IterField) (error, bool) { |
| 182 | headerName := cmn.PropToHeader(tag) |
| 183 | // skip the missing ones |
| 184 | if _, ok := resp.Header[textproto.CanonicalMIMEHeaderKey(headerName)]; !ok { |
| 185 | return nil, false |
| 186 | } |
| 187 | // single-value |
| 188 | return field.SetValue(resp.Header.Get(headerName), true /*force*/), false |
| 189 | }, cmn.IterOpts{OnlyRead: false}) |
| 190 | if err != nil { |
| 191 | return nil, err |
| 192 | } |
| 193 | return op, nil |
| 194 | } |
| 195 | |
| 196 | // Given cos.SimpleKVs (map[string]string) keys and values, sets object's custom properties. |
| 197 | // By default, adds new or updates existing custom keys. |