apjanke / octave-packajoozle

A just-for-fun reworking of GNU Octave's `pkg` tool
GNU General Public License v3.0
4 stars 1 forks source link

Octave Forge cache file always out of date, depending on the current timezone. #66

Closed siko1056 closed 4 years ago

siko1056 commented 4 years ago

Unfortunately, the OF meta data caching strategy seems to be time zone depended.

https://github.com/apjanke/octave-packajoozle/blob/25540c63fe10fbdde5e2e9971f81f8bc4299fb5f/inst/%2Bpackajoozle/%2Binternal/OctaveForgeClient.m#L113-L116

The problem is, Octave's stat() function returns UTC time stamps (which might be better documented upstream), whereas now() returns the local time. Thus in my current JST time zone, the cache file is always outdated and has to annoyingly be refreshed quite often.

diff --git a/inst/+packajoozle/+internal/OctaveForgeClient.m b/inst/+packajoozle/+internal/OctaveForgeClient.m
index 1658a9d..0cdf068 100644
--- a/inst/+packajoozle/+internal/OctaveForgeClient.m
+++ b/inst/+packajoozle/+internal/OctaveForgeClient.m
@@ -113,6 +113,10 @@ classdef OctaveForgeClient < packajoozle.internal.IPackageMetaSource
         [st, err, msg] = stat (cached_file);
         mtime = packajoozle.internal.Util.posixtime2datenum (st.mtime);
         expiry_time = mtime + this.cached_meta_ttl;
+        printf ("\tDownload OF cache file with \n");
+        printf ("\t\t       mime = %s\n", datestr (mtime));
+        printf ("\t\texpiry_time = %s\n", datestr (expiry_time));
+        printf ("\t\t        now = %s\n", datestr (now ()));
         if now < expiry_time
           # Cache hit
           out = cached_file;
>> pkj install -forge io
        Download OF cache file with
                       mime = 13-Dec-2019 07:02:05
                expiry_time = 13-Dec-2019 08:02:05
                        now = 13-Dec-2019 16:07:23
        Download OF cache file with
                       mime = 13-Dec-2019 07:07:27
                expiry_time = 13-Dec-2019 08:07:27
                        now = 13-Dec-2019 16:07:27

Unfortunately, I do not know a solution myself, as Octave has not yet implemented datetime, which is one of your projects as well, I think.

apjanke commented 4 years ago

Ah, good catch!

I think on Linux and Mac, we can just call out to the date command to do time zone conversion, as described here: https://superuser.com/questions/164339/timezone-conversion-by-command-line. There's probably an equivalent on Windows.

apjanke commented 4 years ago

Fixed in https://github.com/apjanke/octave-packajoozle/commit/69223688c4d2282960231925d5217cf33a034df9, I think.

Can you give it another try now?

siko1056 commented 4 years ago

Thank you for the fix. Almost at speed of light now, but less time for coffee breaks :wink:

apjanke commented 4 years ago

Excellent. And thank you for the report. I never would have noticed this myself, because I'm in US Eastern Time, a few hours behind UTC.