question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can we get md5sum of a file from its info without downloading it?

See original GitHub issue

For example gdrive has a feature to obtain the md5sum of a single file such as a tar.gz, which will help to verify its md5sum hash before downloading it.

$ gdrive info 1Qhn-_Zh5EY4NHcQASCvASUzioOd2jH42
Id: 1Qhn-_Zh5EY4NHcQASCvASUzioOd2jH42
Name: QmSSNXFKFF2H6oJ37g3ZUAg58TWWWZY3wY8nPzCPAAyybU.tar.gz
Path: QmSSNXFKFF2H6oJ37g3ZUAg58TWWWZY3wY8nPzCPAAyybU.tar.gz
Mime: application/gzip
Size: 159.0 B
Created: 2019-09-26 11:10:42
Modified: 2019-09-26 11:10:44
Md5sum: 5ca2c9bc2d1b2c0fd6c03bd038d6066a
Shared: True
Parents: 0AIbqFF7bUOe8Uk9PVA
ViewUrl: https://drive.google.com/file/d/1Qhn-_Zh5EY4NHcQASCvASUzioOd2jH42/view?usp=drivesdk
DownloadUrl: https://drive.google.com/uc?id=1Qhn-_Zh5EY4NHcQASCvASUzioOd2jH42&export=download

[Q] Does/can pyocclient provide similar approach?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
scycommented, Mar 2, 2022

Basically, you should be able to retrieve the checksums using something like this:

>>> client.file_info("/myfile.mp4", ["oc:checksums"]).attributes
{'{http://owncloud.org/ns}checksums': None}

Why is it None? Does the server not have any checksums for my file? Yes it does, you can check by running the request manually:

>>> client._session.request("PROPFIND", client._webdav_url + "/myfile.mp4", data='<?xml version="1.0" encoding="utf-8" ?><a:propfind xmlns:a="DAV:" xmlns:oc="http://owncloud.org/ns"><a:prop><oc:checksums/></a:prop></a:propfind>').content
b'<?xml version="1.0"?>\n<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns"><d:response><d:href>/public.php/webdav/myfile.mp4</d:href><d:propstat><d:prop><oc:checksums><oc:checksum>SHA1:22df8f2cde13f524aa3c5282cd97f85e14144b55 MD5:149f3471328e79e2cb93fdde6be42450 ADLER32:1cda0a57</oc:checksum></oc:checksums></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response></d:multistatus>\n'

The problem here is that the <oc:checksums> element contains an embedded <oc:checksum> element (singular). But since Client._parse_dav_element only checks for text nodes that are direct children of the returned property, it doesn’t find the checksums in the returned XML.

@PVince81, this could be fixed by implementing special handling for oc:checksums (because other properties like oc:fileid or oc:owner-id don’t have that additional wrapper), or by beefing up _parse_dav_element to find text nodes recursively. I don’t have time for a PR right now though, sorry.

0reactions
avatar-lavventuracommented, Dec 1, 2021

@PVince81 is the PR merge into latest version of pyocclient? When I fetch file info I am not able to see its md5sum

I get following output:

File(path=/5760616759ab148e9633f0dfe2095040/5760616759ab148e9633f0dfe2095040.tar.gz,file_type=file,attributes={'{DAV:}getlastmodified': 'Wed, 01 Dec 2021 19:22:50 GMT', '{DAV:}getcontentlength': '156105780', '{DAV:}resourcetype': None, '{DAV:}getetag': '"dca03dee180caa17dfdc62f82ab5ece7"', '{DAV:}getcontenttype': 'application/x-gzip'})

Is there any other function that I should use to fetch the md5sum? Should I call file_info() with a property flag?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Check an MD5 Checksum on desktop/laptop (PC/MAC)
Go to the folder that contains the file whose MD5 checksum you want to check and verify. Command: Type cd followed by the...
Read more >
How to get md5sum for online video without download
It is impossible to do it on the fly, because md5sum is calculated by reading the file from the beginning till the end...
Read more >
Calculate the checksum for a file before it has been ...
I believe this is easily possible once the external file is stored locally (i.e. after it has been downloaded), but I would ideally...
Read more >
How to check the MD5 checksum of a downloaded file
WINDOWS: · Open a terminal window. · Type the following command: md5sum [type file name with extension here] [path of the file] --...
Read more >
How to do a remote 'md5sum' on a remote file without ...
To do a remote md5sum, you need to run md5sum on the web server. If you don't have login access to the web...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found