~michihenning/storage-framework/no-exception-on-unknown-metadata

« back to all changes in this revision

Viewing changes to src/qt/client/internal/local_client/FileImpl.cpp

  • Committer: Michi Henning
  • Date: 2016-08-10 06:45:41 UTC
  • mfrom: (10.10.15 more-coverage)
  • Revision ID: michi.henning@canonical.com-20160810064541-ty9vzh6dff8jgfpw
Merged lp:~michihenning/storage-framework/more-coverage:
Improved coverage. Better error reporting/handling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <unity/storage/qt/client/Exceptions.h>
23
23
#include <unity/storage/qt/client/File.h>
24
24
#include <unity/storage/qt/client/internal/local_client/DownloaderImpl.h>
 
25
#include <unity/storage/qt/client/internal/local_client/storage_exception.h>
25
26
#include <unity/storage/qt/client/internal/local_client/UploaderImpl.h>
26
27
#include <unity/storage/qt/client/internal/make_future.h>
27
28
#include <unity/storage/qt/client/Uploader.h>
50
51
 
51
52
QString FileImpl::name() const
52
53
{
53
 
    lock_guard<mutex> guard(mutex_);
 
54
    lock_guard<decltype(mutex_)> guard(mutex_);
54
55
 
55
 
    if (deleted_)
56
 
    {
57
 
        throw deleted_ex("File::name()");
58
 
    }
 
56
    throw_if_destroyed("File::name()");
59
57
    return name_;
60
58
}
61
59
 
62
60
int64_t FileImpl::size() const
63
61
{
64
 
    lock_guard<mutex> guard(mutex_);
65
 
 
66
 
    if (deleted_)
67
 
    {
68
 
        throw deleted_ex("File::size()");
69
 
    }
70
 
 
 
62
    lock_guard<decltype(mutex_)> guard(mutex_);
 
63
 
 
64
    throw_if_destroyed("File::size()");
71
65
    try
72
66
    {
73
67
        boost::filesystem::path p = identity_.toStdString();
74
68
        return file_size(p);
75
69
    }
76
 
    catch (std::exception const& e)
 
70
    catch (std::exception const&)
77
71
    {
78
 
        throw ResourceException(e.what());
 
72
        throw_storage_exception(QString("File::size()"), current_exception());
79
73
    }
80
74
}
81
75
 
82
76
QFuture<Uploader::SPtr> FileImpl::create_uploader(ConflictPolicy policy, int64_t size)
83
77
{
84
 
    lock_guard<mutex> guard(mutex_);
 
78
    lock_guard<decltype(mutex_)> guard(mutex_);
85
79
 
86
 
    if (deleted_)
87
 
    {
88
 
        return make_exceptional_future<Uploader::SPtr>(deleted_ex("File::create_uploader()"));
 
80
    try
 
81
    {
 
82
        throw_if_destroyed("File::create_uploader()");
 
83
    }
 
84
    catch (StorageException const& e)
 
85
    {
 
86
        return internal::make_exceptional_future<Uploader::SPtr>(e);
89
87
    }
90
88
    if (size < 0)
91
89
    {
92
90
        QString msg = "File::create_uploader(): size must be >= 0";
93
 
        return make_exceptional_future<shared_ptr<Uploader>>(InvalidArgumentException(msg));
 
91
        return internal::make_exceptional_future<shared_ptr<Uploader>>(InvalidArgumentException(msg));
94
92
    }
95
93
 
96
94
    auto file = dynamic_pointer_cast<File>(public_instance_.lock());
102
100
 
103
101
QFuture<Downloader::SPtr> FileImpl::create_downloader()
104
102
{
105
 
    lock_guard<mutex> guard(mutex_);
 
103
    lock_guard<decltype(mutex_)> guard(mutex_);
106
104
 
107
 
    if (deleted_)
108
 
    {
109
 
        return make_exceptional_future<Downloader::SPtr>(deleted_ex("File::create_downloader()"));
 
105
    try
 
106
    {
 
107
        throw_if_destroyed("File::create_downloader()");
 
108
    }
 
109
    catch (StorageException const& e)
 
110
    {
 
111
        return internal::make_exceptional_future<Downloader::SPtr>(e);
110
112
    }
111
113
 
112
114
    auto pi = public_instance_.lock();