Changeset 1925:68fd6debe77c


Ignore:
Timestamp:
Apr 11, 2020, 7:24:57 PM (4 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
histedit_source:
7f3ba32cfa16bef74c388c6ea2ecc963c06edc3a
Message:
Clear cache if time shift changes

If the time shift changes, all timestamps in the cache will be wrong
with respect to the _new_ time shift. Depending on the cache, reusing
the old timestamps may not be a problem, but in some cases it might
be. Therefore stay on the safe side and clear the cache, sacrificing
efficiency in favor of correct timestamps.

At first sight, we could "correct" the cache entries by applying the
difference between old and new time shift to the existing cache
entries. However, I think the interactions in ftputil are already so
complicated that I'd like to avoid any probably unnecessary
optimizations. Also, the time shift would probably be set soon after
creating the `FTPHost` instance, so anyway only relatively few cache
entries would be affected.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/host.py

    r1924 r1925  
    9090        # Set default time shift (used in `upload_if_newer` and
    9191        # `download_if_newer`).
    92         self.set_time_shift(0.0)
     92        self._time_shift = 0.0
    9393        # Don't use `LIST -a` option by default. If the server doesn't
    9494        # understand the `-a` option and interprets it as a path, the
     
    321321        The time shift is measured in seconds.
    322322        """
    323         # Implicitly set via `set_time_shift` call in constructor
    324         # pylint: disable=attribute-defined-outside-init
    325         self._time_shift = time_shift
     323        old_time_shift = self.time_shift()
     324        if time_shift != old_time_shift:
     325            # If the time shift changed, all entries in the cache will have
     326            # wrong times with respect to the updated time shift, therefore
     327            # clear the cache.
     328            self.stat_cache.clear()
     329            self._time_shift = time_shift
    326330
    327331    def time_shift(self):
Note: See TracChangeset for help on using the changeset viewer.