Changeset 1023:6d59213b9b9a


Ignore:
Timestamp:
Jan 13, 2011, 8:25:12 PM (8 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Added fix for ticket #55 (thanks to Thomas L. Shinnick).

Ticket URL: http://ftputil.sschwarzer.net/trac/ticket/55 .
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil.py

    r1020 r1023  
    415415                  "could write helper file but not unlink it")
    416416        # Calculate the difference between server and client.
    417         time_shift = server_time - time.time()
     417        now = time.time()
     418        time_shift = server_time - now
     419        # As the time shift for this host instance isn't set yet, the
     420        #  directory parser will calculate times one year in the past if
     421        #  the time zone of the server is east from ours. Thus the time
     422        #  shift will be off by a year as well (see ticket #55).
     423        if time_shift < -360 * 24 * 60 * 60:
     424            # Re-add one year and re-calculate the time shift. We don't
     425            #  know how many days made up that year (it might have been
     426            #  a leap year), so go the route via `time.localtime` and
     427            #  `time.mktime`.
     428            server_time_struct = time.localtime(server_time)
     429            server_time_struct = (server_time_struct.tm_year+1,) + \
     430                                 server_time_struct[1:]
     431            server_time = time.mktime(server_time_struct)
     432            time_shift = server_time - now
    418433        # Do some sanity checks.
    419434        self.__assert_valid_time_shift(time_shift)
Note: See TracChangeset for help on using the changeset viewer.