                 if file
                     doc._rev = file._rev
                     doc.creationDate ?= file.creationDate
-                    if file.checksum is doc.checksum
+                    if @sameBinary file, doc
                         doc.size  ?= file.size
                         doc.class ?= file.class
                         doc.mime  ?= file.mime

    # Expectations:
    #   - the new file path and name are present and valid
    #   - the old file path and name are present and valid
    #   - the checksum is present
    #   - the two paths are not the same
    #   - the revision for the old file is present
    # Actions:

        if doc.checksum?
            doc.checksum = doc.checksum.toLowerCase()
            return not doc.checksum.match /^[a-f0-9]{40}$/
        else
            return false

    # TODO comments, tests
    sameBinary: (one, two, callback) ->
        if one.checksum? and one.checksum is two.checksum
            return true
        else if one.remote?.file
            oneId = one.remote.file._id
            twoId = two.remote.file._id
            return oneId and oneId is twoId
        else
            return false

