[CMake] file( DOWNLOAD ) problem

Robert Dailey rcdailey.lists at gmail.com
Wed Oct 3 13:36:43 EDT 2012


I have some weird logic for the download. If the file is NOT on the
server, that is not an error -- it simply means we do not have
includes, or do not have binaries (either is not erroneous, as not
every library will have or need both). So I've had to write custom
logic for each protocol to handle this (doesn't seem safe). Is there a
better way to verify if a file exists or not on an FTP/HTTP server? If
not, could I possibly add a feature for this? Such as:

file( EXISTS path result )

(This would be slightly more functional than if(EXISTS), as it will
work with FTP/HTTP/HTTPS as well as file paths)

Here is the logic I use currently (as I said, it seems unreliable, I
had to replicate a missing file on each protocol to see what error it
returned). What's most concerning is that I think all errors return
error code 22 on HTTP, so I have no way of knowing reliably if a file
exists or not:

    file( DOWNLOAD ${source} ${destination} STATUS status )

    list( GET status 0 error_code )
    if( error_code )
        file( REMOVE ${destination} )

        # If the file cannot be found on the server,
        # we assume it isn't supposed to have it.
        # We fail with all other errors.
        if( NOT error_code EQUAL 19 AND     # FTP: Invalid file / file not found
            NOT error_code EQUAL 22         # HTTP: HTTP response code
said error
        )
            list( GET status 1 error_message )
            message( FATAL_ERROR "Failed to download file via
HTTP/FTP: ${error_message}" )
        endif()
    endif()

On Fri, Sep 28, 2012 at 7:50 PM, David Cole <david.cole at kitware.com> wrote:
>> What I'm saying is that it _does_ work properly, which is the problem
>
> Ha!!
>
> Wish all our problems were that things worked properly!
>
> :-)
>


More information about the CMake mailing list