Changeset 0759f0018198c010a53e009a3841cb7a68f192fc
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r1ae82be
|
r0759f00
|
|
| 56 | 56 | string command = string("curl -sI ") + url + " 2> /dev/null"; |
| 57 | 57 | |
| 58 | | // check whether curl is present |
| | 58 | // if curl is not present return bogus size of 1 byte |
| 59 | 59 | if (!use_curl) |
| | 60 | return 1; |
| | 61 | |
| | 62 | if (!(in = popen(command.c_str(), "r"))) |
| 60 | 63 | return -1; |
| 61 | | if (!(in = popen(command.c_str(), "r"))) |
| 62 | | { |
| 63 | | use_curl = false; |
| 64 | | return -1; |
| 65 | | } |
| 66 | 64 | |
| 67 | 65 | // read headers |
| … |
… |
|
| 71 | 69 | int ret = pclose(in); |
| 72 | 70 | if (ret < 0 || WEXITSTATUS(ret)) |
| 73 | | { |
| 74 | | use_curl = false; |
| 75 | 71 | return -1; |
| 76 | | } |
| 77 | 72 | |
| 78 | 73 | // parse headers |
| … |
… |
|
| 125 | 120 | } |
| 126 | 121 | |
| 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)) |
| 130 | 125 | { |
| 131 | | tempfile = "/media/ram/boc-flash"; |
| | 126 | cerr << "Using wget for downloads" << endl; |
| | 127 | use_curl = false; |
| 132 | 128 | } else { |
| 133 | | tempfile = "/tmp/boc-flash"; |
| | 129 | cerr << "Using cURL for downloads" << endl; |
| | 130 | use_curl = true; |
| 134 | 131 | } |
| 135 | 132 | |
| … |
… |
|
| 142 | 139 | task.partition = string(argv[optind]); |
| 143 | 140 | task.url = string(argv[optind + 1]); |
| | 141 | task.size = getSize(task.url); |
| 144 | 142 | |
| 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 | } |
| 151 | 149 | |
| 152 | 150 | tasks.push_back(task); |
| 153 | 151 | taskTotal += task.size; |
| 154 | 152 | } |
| 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 | } |
| 159 | 161 | |
| 160 | 162 | /* run tasks */ |