diff --git a/TODO b/TODO index 9afd5d9..5f9663f 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ * compaction * parallel reads * round-robin writing -* LastModified instead of Version * DELETE support * efficient range requests * remember Content-Type diff --git a/src/monic_file.erl b/src/monic_file.erl index 54bdf24..3f42dc0 100644 --- a/src/monic_file.erl +++ b/src/monic_file.erl @@ -102,7 +102,7 @@ init(Path) -> handle_call({start_writing, Key, Cookie, Size}, _From, #state{main_fd=MainFd, write_pos=Pos, writer=nil}=State) -> Ref = make_ref(), - LastModified = now(), + LastModified = erlang:universaltime(), Header = #header{cookie=Cookie, key=Key, size=Size, last_modified=LastModified}, Index = #index{cookie=Cookie, key=Key, location=Pos, size=Size, last_modified=LastModified}, case monic_utils:pwrite_term(MainFd, Pos, Header) of diff --git a/src/monic_item_resource.erl b/src/monic_item_resource.erl index b180703..042602b 100644 --- a/src/monic_item_resource.erl +++ b/src/monic_item_resource.erl @@ -17,6 +17,7 @@ allowed_methods/2, content_types_accepted/2, content_types_provided/2, + last_modified/2, resource_exists/2, valid_entity_length/2]). -export([get_item/2, put_item/2]). @@ -38,6 +39,22 @@ content_types_provided(ReqData, Context) -> content_types_accepted(ReqData, Context) -> {[{?ITEM_MIME_TYPE, put_item}], ReqData, Context}. +last_modified(ReqData, Context) -> + Key = wrq:path_info(key, ReqData), + Cookie = list_to_integer(wrq:path_info(cookie, ReqData)), + LastModified1 = case monic_utils:open(ReqData, Context) of + {ok, Pid} -> + case monic_file:info(Pid, Key, Cookie) of + {ok, {_, _, LastModified}} -> + LastModified; + {error, not_found} -> + undefined + end; + _ -> + undefined + end, + {LastModified1, ReqData, Context}. + resource_exists(ReqData, Context) -> Key = wrq:path_info(key, ReqData), Cookie = list_to_integer(wrq:path_info(cookie, ReqData)),