Changeset 1580:95647a76b6c5


Ignore:
Timestamp:
Oct 4, 2014, 6:38:55 PM (7 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Be explicit about unknown datetime precisions.

Instead of relying on default handling of pre-epoch times, explicitly
consider unknown precisions and in this case, consider the source file
newer. That is, if in doubt, transfer the file (as was the assumption
before).
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ftputil/file_transfer.py

    r1575 r1580  
    1111import io
    1212import os
     13
     14import ftputil.stat
    1315
    1416
     
    120122    before the first possible actual target modification time.
    121123    """
    122     # We don't need special handling for pre-epoch datetimes since
    123     # they always result in a modification datetime of 0.0, so the
    124     # following algorithm will insist that the file is retransmitted.
    125     return (source_file.mtime() + source_file.mtime_precision() >=
    126             target_file.mtime())
     124    if source_file.mtime_precision() is ftputil.stat.UNKNOWN_PRECISION:
     125        return True
     126    else:
     127        return (source_file.mtime() + source_file.mtime_precision() >=
     128                target_file.mtime())
    127129
    128130
  • test/test_file_transfer.py

    r1564 r1580  
    1 # Copyright (C) 2010-2013, Stefan Schwarzer <sschwarzer@sschwarzer.net>
     1# Copyright (C) 2010-2014, Stefan Schwarzer <sschwarzer@sschwarzer.net>
    22# and ftputil contributors (see `doc/contributors.txt`)
    33# See the file LICENSE for licensing terms.
     
    1111import ftputil.compat
    1212import ftputil.file_transfer
     13import ftputil.stat
    1314
    1415
     
    3940        hour = 60 * minute
    4041        day = 24 * hour
     42        unknown = ftputil.stat.UNKNOWN_PRECISION
    4143        # Define input arguments; modification datetimes are in seconds.
    4244        # Fields are source datetime/precision, target datetime/precision,
     
    5658          (10000.0+0.2*hour, 0.2*hour,  10000.0, hour,  True),
    5759          (10000.0-0.2*hour, 2*hour,    10000.0, hour,  True),
     60          # Unknown precision
     61          (1000.0, None,    1000.0, second,  True),
     62          (1000.0, second,  1000.0, None,    True),
     63          (1000.0, None,    1000.0, None,    True),
    5864        ]
    5965        for (source_mtime, source_mtime_precision,
Note: See TracChangeset for help on using the changeset viewer.