~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to src/modules/copy/copy.cpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2015-07-31 13:17:55 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150731131755-mizprbmn7ogv33te
Tags: 0.4.1-1
* Update to version 0.4.1
* Implement Multi-Arch support

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
    std::string destination(dst.getString());
102
102
    std::string delegationEndpoint;
103
103
    DavixError *internalError = NULL;
 
104
    bool isS3endpoint = false;
104
105
 
105
106
    // nstreams as string
106
107
    char nstreamsStr[16];
110
111
    Davix::RequestParams requestParams(parameters);
111
112
    requestParams.setTransparentRedirectionSupport(false);
112
113
 
 
114
    size_t start_pos;
 
115
 
 
116
    // if destination is s3 endpoint, change prefix to http(s) and pre-sign the request as a PUT
 
117
    if(destination.compare(0,2,"s3") == 0){ 
 
118
        destination.replace(0, 2, "http");
 
119
        time_t expiration_time = time(NULL) +3600;
 
120
        Davix::HeaderVec vec;
 
121
        Uri tmp = Davix::S3::tokenizeRequest(requestParams, "PUT", destination, vec, expiration_time);
 
122
        destination = tmp.getString();
 
123
        isS3endpoint = true;
 
124
    }
 
125
 
113
126
    // Perform COPY hopping through redirections
114
127
    HttpRequest* request = NULL;
115
128
    do {
138
151
        request->setRequestMethod("COPY");
139
152
        request->addHeaderField("Destination", destination);
140
153
        request->addHeaderField("X-Number-Of-Streams", nstreamsStr);
 
154
        // for lcgdm-dav -> S3, add NoHead flag to suppress final head-to-close request
 
155
        if(isS3endpoint)
 
156
            request->addHeaderField("Copy-Flags", "NoHead");
141
157
        request->setParameters(requestParams);
142
158
        request->beginRequest(&internalError);
143
159
        if (internalError) {
193
209
                                   "Could not COPY. The source service does not allow it");
194
210
        }
195
211
        else if (responseStatus == 400) {
 
212
            std::string err_msg(request->getAnswerContentVec().begin(), request->getAnswerContentVec().end());
196
213
                DavixError::setupError(error, COPY_SCOPE, StatusCode::InvalidArgument,
197
 
                                                           std::string("Could not COPY. The server rejected the request: ") +
198
 
                                                           request->getAnswerContent());
 
214
                                   fmt::format("Could not COPY. The server rejected the request: {}", err_msg));
199
215
        }
200
216
        else if (responseStatus >= 300) {
201
217
            std::ostringstream msg;
231
247
    PerformanceData performance;
232
248
    time_t lastPerfCallback = time(NULL);
233
249
 
234
 
    while ((line_len = request->readLine(buffer, sizeof(buffer), &daverr)) >= 0
235
 
            && !daverr)
 
250
    while ((line_len = request->readLine(buffer, sizeof(buffer), &daverr)) >= 0 && !daverr)
236
251
    {
237
252
        buffer[line_len] = '\0';
 
253
 
 
254
        if (line_len > 0)
 
255
            DAVIX_SLOG(DAVIX_LOG_VERBOSE, DAVIX_LOG_GRID, "Received: {}", buffer);
 
256
 
238
257
        // Skip heading whitespaces
239
258
        p = buffer;
240
259
        while (*p && p < buffer + sizeof(buffer) && isspace(*p))
281
300
                    "Transfer aborted in the remote end");
282
301
            break;
283
302
        }
284
 
        else if (strncasecmp("failed", p, 6) == 0)
 
303
        else if (strncasecmp("failed", p, 6) == 0 || strncasecmp("failure", p, 7) == 0)
285
304
        {
286
305
            Davix::DavixError::setupError(error, COPY_SCOPE, StatusCode::RemoteError,
287
306
                    std::string("Transfer failed: ") + p);
288
307
            break;
289
308
        }
290
 
        else
 
309
        else if(line_len> 0)
291
310
        {
292
 
            Davix::DavixError::setupError(error, COPY_SCOPE, StatusCode::SystemError,
293
 
                    std::string("Unexpected message from remote host: ") + p);
294
 
            break;
 
311
            DAVIX_SLOG(DAVIX_LOG_WARNING, DAVIX_LOG_GRID, "Unknown performance marker, ignoring: {}", buffer);
295
312
        }
296
313
    }
297
314
}