anybox / buttervolume

BTRFS Volume plugin for Docker
Apache License 2.0
81 stars 11 forks source link

parsing date from snapshots name #5

Closed petrus-v closed 7 years ago

petrus-v commented 7 years ago

At least while purging snapshots we are reading date that were generated by datetime.isoformat if we are unlucky we get the time with 0 microsecond, in that case the format is a bit different:

(Pdb) datetime(2017,4,3,21,24,0,101).isoformat()
'2017-04-03T21:24:00.000101'
(Pdb) datetime(2017,4,3,21,24,0,0).isoformat()
'2017-04-03T21:24:00'

So while parsing that string we can get a ValueError exception:

(Pdb) datetime.strptime("buttervolume-test-eaf7bb4c65ed4f2ea9c30ef6c33f0f00@2017-04-03T21:24:00@123".split('@')[1], "%Y-%m-%dT%H:%M:%S.%f")
*** ValueError: time data '2017-04-03T21:24:00' does not match format '%Y-%m-%dT%H:%M:%S.%f'
(Pdb) datetime.strptime("buttervolume-test-eaf7bb4c65ed4f2ea9c30ef6c33f0f00@2017-04-03T21:24:00.12@123".split('@')[1], "%Y-%m-%dT%H:%M:%S.%f")
datetime.datetime(2017, 4, 3, 21, 24, 0, 120000)
ccomb commented 7 years ago

thx for the report, I've replaced the isoformat with a strftime