amnong / easywebdav

A WebDAV Client in Python
http://pypi.python.org/pypi/easywebdav/
ISC License
207 stars 113 forks source link

Timestamp not preserved in downloaded file #63

Closed kk-hiraskar closed 3 years ago

kk-hiraskar commented 4 years ago

Hi, Timestamps are not preserved in downloaded file, both created and modified, I see some workarounds on another link https://github.com/mar10/wsgidav/issues/112

is it possible to fix this issue ?

bdlabitt commented 3 years ago

I am experiencing this as well in Raspberry Pi OS 32 (Buster). Are there extensions to webdav that fix this? This bug makes easywebdav not useful, as it destroys time order of medical files.

kk-hiraskar commented 3 years ago

I am experiencing this as well in Raspberry Pi OS 32 (Buster). Are there extensions to webdav that fix this? This bug makes easywebdav not useful, as it destroys time order of medical files.

Last year when I faced this, handled with some alternative, I will check my code archive and let you know tomorrow.

kk-hiraskar commented 3 years ago

Webdav file download seems just the old method of data download, so file properties are not preserved!

To preserve timestamp, here is a solution:

  1. list directory and get the details necessary in some dictionary

    list=webdav.ls(dir)
    for f in list:
    name = re.sub(r'^\/content\/dav\/','',f.name)
    (modifiedTime, createdTime) = (f.mtime, f.ctime)
  2. download the file,

    webdav.download(srcFileName, targetFileName)
  3. and now, on individual files apply the respective time stamps

    
    # for Linux
    os.utime(targetFileName, (modifiedTime, createdTime))

for windows

import win32file win32file.SetFileTime(targetFile, createdTime, modifiedTime, modifiedTime)



for understanding, just required code is explained above.

kindly handle loops, exceptions and all other factors.