From 2ba01bbb8b085752d248bfec116b70d5b83d7c88 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 24 Aug 2011 15:02:01 -0700 Subject: [PATCH] rgw: fix prepare_get_obj when ENOENT --- src/rgw/rgw_rados.cc | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 9b7855183ccba..49ce62f565dc8 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -784,6 +784,7 @@ int RGWRados::get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, librados::IoCtx& io if (r == -ENOENT) { s->exists = false; s->has_attrs = true; + s->mtime = 0; return 0; } if (r < 0) @@ -1095,6 +1096,11 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj, if (r < 0) goto done_err; + if (!astate->exists) { + r = -ENOENT; + goto done_err; + } + if (attrs) { *attrs = astate->attrset; if (g_conf->rgw_log >= 20) { @@ -1107,26 +1113,34 @@ int RGWRados::prepare_get_obj(void *ctx, rgw_obj& obj, } /* Convert all times go GMT to make them compatible */ - struct tm mtm; - ctime = mktime(gmtime_r(&astate->mtime, &mtm)); + if (mod_ptr || unmod_ptr) { + struct tm mtm; + struct tm *gmtm = gmtime_r(&astate->mtime, &mtm); + if (!gmtm) { + RGW_LOG(0) << "could not get translate mtime for object" << dendl; + r = -EINVAL; + goto done_err; + } + ctime = mktime(gmtm); - r = -ECANCELED; - if (mod_ptr) { - RGW_LOG(10) << "If-Modified-Since: " << *mod_ptr << " Last-Modified: " << ctime << dendl; - if (ctime < *mod_ptr) { - err->http_ret = 304; - err->s3_code = "NotModified"; + r = -ECANCELED; + if (mod_ptr) { + RGW_LOG(10) << "If-Modified-Since: " << *mod_ptr << " Last-Modified: " << ctime << dendl; + if (ctime < *mod_ptr) { + err->http_ret = 304; + err->s3_code = "NotModified"; - goto done_err; + goto done_err; + } } - } - if (unmod_ptr) { - RGW_LOG(10) << "If-UnModified-Since: " << *unmod_ptr << " Last-Modified: " << ctime << dendl; - if (ctime > *unmod_ptr) { - err->http_ret = 412; - err->s3_code = "PreconditionFailed"; - goto done_err; + if (unmod_ptr) { + RGW_LOG(10) << "If-UnModified-Since: " << *unmod_ptr << " Last-Modified: " << ctime << dendl; + if (ctime > *unmod_ptr) { + err->http_ret = 412; + err->s3_code = "PreconditionFailed"; + goto done_err; + } } } if (if_match || if_nomatch) { -- 2.39.5