You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:53:23 UTC

[46/50] git commit: Support all timezones for R14 series

Support all timezones for R14 series


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/5b175d01
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/5b175d01
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/5b175d01

Branch: refs/heads/import
Commit: 5b175d017bb601ba10e1da9348854606389262e4
Parents: 9ad7261
Author: Robert Newson <rn...@apache.org>
Authored: Wed Aug 15 22:32:15 2012 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Fri Jan 17 14:51:32 2014 -0800

----------------------------------------------------------------------
 src/mochiweb_request.erl | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/5b175d01/src/mochiweb_request.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_request.erl b/src/mochiweb_request.erl
index 2bc54c0..dfd439d 100644
--- a/src/mochiweb_request.erl
+++ b/src/mochiweb_request.erl
@@ -600,7 +600,7 @@ maybe_redirect(RelPath, FullPath, ExtraHeaders) ->
     end.
 
 maybe_serve_file(File, ExtraHeaders) ->
-    case file:read_file_info(File, [{time, universal}]) of
+    case read_file_info(File) of
         {ok, FileInfo} ->
             LastModified = couch_util:rfc1123_date(FileInfo#file_info.mtime),
             case get_header_value("if-modified-since") of
@@ -624,6 +624,25 @@ maybe_serve_file(File, ExtraHeaders) ->
             not_found(ExtraHeaders)
     end.
 
+read_file_info(File) ->
+    try
+        file:read_file_info(File, [{time, universal}])
+    catch error:undef ->
+        case file:read_file_info(File) of
+            {ok, FileInfo} ->
+                {ok, FileInfo#file_info{
+                       atime=to_universal(FileInfo#file_info.atime),
+                       mtime=to_universal(FileInfo#file_info.mtime),
+                       ctime=to_universal(FileInfo#file_info.ctime)
+                      }};
+            Else ->
+                Else
+        end
+    end.
+
+to_universal(LocalTime) ->
+    calendar:local_time_to_universal_time(LocalTime).
+
 server_headers() ->
     [{"Server", "MochiWeb/1.0 (" ++ ?QUIP ++ ")"},
      {"Date", couch_util:rfc1123_date()}].