Changeset 0759f0018198c010a53e009a3841cb7a68f192fc

Show
Ignore:
Timestamp:
11/04/2009 04:57:42 PM (3 years ago)
Author:
Jeremy Lainé <jeremy.laine@…>
Parents:
1ae82be93ee904c7ed68b90aacef05a3e593b505
git-committer:
Jeremy Lainé <jeremy.laine@…> (11/04/2009 04:57:42 PM)
Message:

improve cURL detection

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/boc-flash.cpp

    r1ae82be r0759f00  
    5656    string command = string("curl -sI ") + url + " 2> /dev/null"; 
    5757 
    58     // check whether curl is present 
     58    // if curl is not present return bogus size of 1 byte 
    5959    if (!use_curl) 
     60        return 1; 
     61 
     62    if (!(in = popen(command.c_str(), "r"))) 
    6063        return -1; 
    61     if (!(in = popen(command.c_str(), "r"))) 
    62     { 
    63         use_curl = false; 
    64         return -1; 
    65     } 
    6664 
    6765    // read headers 
     
    7169    int ret = pclose(in); 
    7270    if  (ret < 0 || WEXITSTATUS(ret)) 
    73     { 
    74         use_curl = false; 
    7571        return -1; 
    76     } 
    7772 
    7873    // parse headers 
     
    125120    } 
    126121 
    127     /* temporary file */ 
    128     string tempfile; 
    129     if (stat("/media/ram", &test) == 0) 
     122    /* detect curl */ 
     123    int ret = system("curl -h > /dev/null 2>&1"); 
     124    if  (ret < 0 || WEXITSTATUS(ret)) 
    130125    { 
    131         tempfile = "/media/ram/boc-flash"; 
     126        cerr << "Using wget for downloads" << endl; 
     127        use_curl = false; 
    132128    } else { 
    133         tempfile = "/tmp/boc-flash"; 
     129        cerr << "Using cURL for downloads" << endl; 
     130        use_curl = true; 
    134131    } 
    135132 
     
    142139        task.partition = string(argv[optind]); 
    143140        task.url = string(argv[optind + 1]); 
     141        task.size = getSize(task.url); 
    144142 
    145         /* optionaly determine file size */ 
    146         int size = getSize(task.url); 
    147         if (size > 0) 
    148             task.size = size; 
    149         else 
    150             task.size = 1; 
     143        /* check we got a file size */ 
     144        if (task.size < 0) 
     145        { 
     146            cerr << "Could not determine size of " << task.url << endl; 
     147            return EXIT_FAILURE; 
     148        } 
    151149 
    152150        tasks.push_back(task); 
    153151        taskTotal += task.size; 
    154152    } 
    155     if (use_curl) 
    156         cerr << "Using cURL for downloads" << endl; 
    157     else 
    158         cerr << "Using wget for downloads" << endl; 
     153    /* temporary file */ 
     154    string tempfile; 
     155    if (stat("/media/ram", &test) == 0) 
     156    { 
     157        tempfile = "/media/ram/boc-flash"; 
     158    } else { 
     159        tempfile = "/tmp/boc-flash"; 
     160    } 
    159161 
    160162    /* run tasks */