The external special remote protocol CHECKPRESENT command has no support for checking the file size.
In many cases a special remote is able to fetch the size of an object as it checks its availability with no additional cost (for example when you use the stat()
function: the size is already included in the response). The remote protocol could be extended so that the backend returns the size with the CHECKPRESENT-SUCCESS command, so that git-annex can provide a primitive but probably useful additional integrity check. This is helpful, for example, to detect bugs that result in the truncation of a file in the special remote; or to detect the case of an aborted upload that resulted in the file being checked into the remote anyway.
When it is not easy to get the file size without incurring in additional costs, the backend can simply return a flag value like -1
to tell git-annex to ignore it.
There is a delicate point in how git-annex computes the expected object size for an encrypted remote. I do not know if there is a way to compute the size of a file after it has been encrypted with HMAC/GPG without actually performing all the computation. In line of principle it should not be difficult, but I do not know the details.
The encrypted content size is not constant, and not known to git-annex.
The only git-annex remote that checks the size in its checkpresent implementation is the web special remote, precisely because it's never encrypted. Also because files on the web change content from time to time and so that needs to be detected.
What would make sense is to extend the reply to
CHECKPRESENT-SUCCESS Key [size]
or perhapsCHECKPRESENT-SIZE Key size
. git-annex can then compare the value with the key's known size, if any. If the key is encrypted, it would need to skip this check.Note that chunk keys currently have their keySize inherited from the parent key, and the keyChunkSize of each chunk key is set to the key size. The last chunk of a key will typically be shorter than its keyChunkSize. That would need to be cleaned up.