{"action":"created","issue":{"url":"https://api.github.com/repos/aws/aws-cli/issues/855","labels_url":"https://api.github.com/repos/aws/aws-cli/issues/855/labels{/name}","comments_url":"https://api.github.com/repos/aws/aws-cli/issues/855/comments","events_url":"https://api.github.com/repos/aws/aws-cli/issues/855/events","html_url":"https://github.com/aws/aws-cli/issues/855","id":38954833,"number":855,"title":"Sync/Copy fails completely if even one file's timestamp is \"out of range\".","user":{"login":"ionFish","id":2279261,"avatar_url":"https://avatars.githubusercontent.com/u/2279261?v=3","gravatar_id":"","url":"https://api.github.com/users/ionFish","html_url":"https://github.com/ionFish","followers_url":"https://api.github.com/users/ionFish/followers","following_url":"https://api.github.com/users/ionFish/following{/other_user}","gists_url":"https://api.github.com/users/ionFish/gists{/gist_id}","starred_url":"https://api.github.com/users/ionFish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ionFish/subscriptions","organizations_url":"https://api.github.com/users/ionFish/orgs","repos_url":"https://api.github.com/users/ionFish/repos","events_url":"https://api.github.com/users/ionFish/events{/privacy}","received_events_url":"https://api.github.com/users/ionFish/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aws/aws-cli/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/aws/aws-cli/labels/confirmed","name":"confirmed","color":"006b75"},{"url":"https://api.github.com/repos/aws/aws-cli/labels/s3","name":"s3","color":"eb6420"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-07-29T03:18:06Z","updated_at":"2015-12-09T21:14:48Z","closed_at":"2015-12-09T21:14:48Z","body":"**OVERVIEW:**\r\nI wrote an application that interfaces with AWS-CLI to perform various operations such as `sync` and `cp` given parameters that are sent to it from the web application. The client-side code is PHP which runs `system()` calls like `aws s3 ...`. **This is from LOCAL --> BUCKET!** (I do not know if Amazon S3 can store invalid-timestamp files, so I cannot test that it would happen the other way around).\r\n\r\nI started a backup on a Friday before I left work, and noticed when I got home that it had \"already completed\". This was not possible. I initially suspected that the cause was simply a bad filename, possibly containing strange characters and backticks and spaces and other junk. That turned out not to be the case. It's simply *invalid timestamps*. With over a half-million files to upload, having a backup fail on EACH file (then moving/deleting that file or correcting its timestamp) is NOT a feasible approach.\r\n\r\n**ANALYSIS:**\r\nScanning through the error logs of the failed backup returned something like this:\r\n\r\n    Completed 499 part(s) with ... file(s) remaining\r\n    Could not retrieve file stat of \"\\\\SHARE\\path\\to\\bad_file.ttf\": timestamp out of range for platform localtime()/gmtime() function\r\n    Completed 500 part(s) with ... file(s) remaining\r\n\r\nSo obviously the file has a bad timestamp (that particular file is from the year 2045, apparently). Manual review of the file reveals (Windows Explorer) that there is no file modification time even displayed. After some more testing, I uncover the following:\r\n\r\n![Image of Explorer timestamp threshold](http://i.imgur.com/FaEvSjY.png)\r\n\r\n*Please note, that in MS/DOS (and cmd.exe) the use of `dir` returns valid timestamps all the way from 01/01/1601 to some date after the year 2035 (year 5555 failed also).*\r\n\r\nThe tool I used to manually set these values with can be found [here](https://code.google.com/p/stexbar/downloads/list).\r\n\r\nSearching online for \"Could not retrieve file stat of : timestamp out of range for platform localtime()/gmtime() function\" yielded a large PDF Python book [here](http://marvin.cs.uidaho.edu/Teaching/CS270/pythonLibrary.pdf). Searching the term \"out of the range\" returns two results, pages 140 and 143 respectively (\"fromtimestamp\" and \"utcfromtimestamp\").\r\n\r\nI'm not a Python guru, so I do not know where-from Python grabs the times in Windows (if MS/DOS can do it but not Explorer).\r\n\r\nA logical next-step would be to grep for those function calls in the AWS-CLI source, which I downloaded from GitHub on 7/28/2014.\r\n\r\n    # grep -r \"fromtimestamp\" .\r\n    ./tests/unit/customizations/s3/test_utils.py:                f.fromtimestamp.side_effect = ValueError(\r\n    ./awscli/customizations/s3/utils.py:        update_time = datetime.fromtimestamp(stats.st_mtime, tzlocal())\r\n\r\nAnd as you can see, these are the two offending files.\r\n\r\n**PROPOSAL:**\r\nI suggest that the timestamp is checked that it is in fact in-range, and if it is from PRE-1970 or 1980, simply set it to the lowest valid timestamp possible (according to the PDF book linked above, 1970, but based on my tests, 1980 at the least).\r\n\r\nFor files that are newer than \"now\" (when the file is checked by the program), just set the timestamp to the current time.\r\n\r\n**REMARKS:**\r\n1. as a result of a failed transfer *due to an invalid timestamp*, other *unrelated* errors will occur shortly after, before the entire process dies **without a specific error**. You might see `unable to read from source or disk` types of things.\r\n2. I will work on a patch tomorrow or tomorrow-evening. **If anyone has any \"better\" idea (than setting the file to the oldest valid timestamp), PLEASE comment accordingly.**\r\n3. I currently have a semi-working .exe file (easily compiled for Linux; it's in C) that will scan any directory recursively (not sure if it works on network drives yet -- will work on it tomorrow) and checks for valid 32-bit timestamps (though I may have to change that since I believe Windows uses 64-bit timestamps), and prints out bad files by path/name for manual correction."},"comment":{"url":"https://api.github.com/repos/aws/aws-cli/issues/comments/163393697","html_url":"https://github.com/aws/aws-cli/issues/855#issuecomment-163393697","issue_url":"https://api.github.com/repos/aws/aws-cli/issues/855","id":163393697,"user":{"login":"JordonPhillips","id":2643092,"avatar_url":"https://avatars.githubusercontent.com/u/2643092?v=3","gravatar_id":"","url":"https://api.github.com/users/JordonPhillips","html_url":"https://github.com/JordonPhillips","followers_url":"https://api.github.com/users/JordonPhillips/followers","following_url":"https://api.github.com/users/JordonPhillips/following{/other_user}","gists_url":"https://api.github.com/users/JordonPhillips/gists{/gist_id}","starred_url":"https://api.github.com/users/JordonPhillips/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JordonPhillips/subscriptions","organizations_url":"https://api.github.com/users/JordonPhillips/orgs","repos_url":"https://api.github.com/users/JordonPhillips/repos","events_url":"https://api.github.com/users/JordonPhillips/events{/privacy}","received_events_url":"https://api.github.com/users/JordonPhillips/received_events","type":"User","site_admin":false},"created_at":"2015-12-09T21:14:48Z","updated_at":"2015-12-09T21:14:48Z","body":"This was fixed in #1657 \r\n\r\nNow a file with an invalid timestamp will not be skipped. Instead, we will default to epoch time and throw a warning with a non-zero rc."}}