Opened 3 weeks ago

Closed 3 weeks ago

Last modified 2 weeks ago

#131 closed defect (fixed)

Unix time parser uses wrong year if server time is in the next year relative to client time

Reported by: schwa Owned by: schwa
Priority: major Milestone: 4.0.0
Component: Library Version: 3.4
Keywords: stat time timezones unix parser Cc:

Description

The method ftputil.stat.Parser.parse_unix_time is responsible for parsing unix timestamps in directory lines. The code contains the following heuristics to guess the correct year on the server side:

# Try the current year
year = time.localtime()[0]
st_mtime = self._mktime((year, month, day, hour, minute, 0, 0, 0, -1))

The problem with this code is that it implicitly assumes that the year on the client side is the same as the year on the server side. This assumption is wrong if the years actually differ. For example, if the directory line on the server is

-rw-r--r--   1   45854   200   4604   Jan 01 01:49   index.html

but the local time on the client side is 2019-12-31T23:49, the code assumes that the January in the directory line refers to the previous January 1st from the point of view of the client. Consequently, the st_mtime of the stat result is about one year in the past for a file that was just created.

Change History (4)

comment:1 Changed 3 weeks ago by schwa

The bug should be fixed in [435b04a1c040].

comment:2 Changed 3 weeks ago by schwa

Resolution: fixed
Status: assignedclosed

comment:3 Changed 3 weeks ago by schwa

Summary: Unix time parser fails if server time is in the next year relative to client timeUnix time parser uses wrong year if server time is in the next year relative to client time

comment:4 Changed 2 weeks ago by schwa

The fix [435b04a1c040] also fixes the bug that the time shift wasn't taken into account. Commit [f5ee6970ff95] fixes the same type of bug for the MS parser.

Note: See TracTickets for help on using tickets.