MoveItemRequest.cpp 2.35 KB
Newer Older
Paweł Wegner's avatar
Paweł Wegner committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*****************************************************************************
 * MoveItemRequest.cpp : MoveItemRequest implementation
 *
 *****************************************************************************
 * Copyright (C) 2016-2016 VideoLAN
 *
 * Authors: Paweł Wegner <pawel.wegner95@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include "MoveItemRequest.h"

#include "CloudProvider/CloudProvider.h"

namespace cloudstorage {

MoveItemRequest::MoveItemRequest(std::shared_ptr<CloudProvider> p,
                                 IItem::Pointer source,
                                 IItem::Pointer destination,
                                 MoveItemCallback callback)
34
    : Request(p, callback, [=](Request::Pointer request) {
35 36 37
        if (destination->type() != IItem::FileType::Directory)
          return request->done(
              Error{IHttpRequest::Forbidden, "destination not a directory"});
38
        this->request(
39 40 41
            [=](util::Output stream) {
              return p->moveItemRequest(*source, *destination, *stream);
            },
42
            [=](EitherError<Response> e) {
43 44
              if (e.left()) return request->done(e.left());
              try {
45 46
                request->done(p->moveItemResponse(*source, *destination,
                                                  e.right()->output()));
47
              } catch (const std::exception&) {
48 49
                request->done(
                    Error{IHttpRequest::Failure, e.right()->output().str()});
50
              }
51
            });
52
      }) {}
Paweł Wegner's avatar
Paweł Wegner committed
53 54 55 56

MoveItemRequest::~MoveItemRequest() { cancel(); }

}  // namespace cloudstorage