~unity-api-team/storage-framework/vivid

« back to all changes in this revision

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

  • Committer: Michi Henning
  • Date: 2016-05-23 02:27:16 UTC
  • mto: (8.12.2 add-etag)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: michi.henning@canonical.com-20160523022716-jpaudmuan8vxxgch
More fleshing out of the local client implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include <unity/storage/qt/client/internal/DownloaderImpl.h>
7
7
 
8
8
#include <boost/filesystem.hpp>
 
9
#include <QtConcurrent>
9
10
 
10
11
using namespace std;
11
12
 
20
21
namespace internal
21
22
{
22
23
 
 
24
FileImpl::FileImpl(QString const& identity)
 
25
    : ItemImpl(identity, common::ItemType::file)
 
26
{
 
27
}
 
28
 
23
29
QFuture<void> FileImpl::destroy()
24
30
{
25
 
    QFutureInterface<void> qf;
26
31
    if (destroyed_)
27
32
    {
 
33
        QFutureInterface<void> qf;
28
34
        qf.reportException(DestroyedException());
29
35
        return qf.future();
30
36
    }
31
37
 
32
 
    int rc = ::unlink(identity_.toStdString().c_str());
33
 
    if (rc == 0)
34
 
    {
35
 
        destroyed_ = true;
36
 
        qf.reportFinished();
37
 
    }
38
 
    else
39
 
    {
40
 
        qf.reportException(StorageException());
41
 
    }
42
 
    return qf.future();
 
38
    auto This = static_pointer_cast<FileImpl>(shared_from_this());  // Keep this file alive while the lambda is alive.
 
39
    auto destroy = [This]()
 
40
    {
 
41
        using namespace boost::filesystem;
 
42
 
 
43
        try
 
44
        {
 
45
            This->destroyed_ = true;
 
46
            remove(This->native_identity().toStdString());
 
47
        }
 
48
        catch (std::exception const&)
 
49
        {
 
50
            throw StorageException();  // TODO
 
51
        }
 
52
    };
 
53
    return QtConcurrent::run(destroy);
43
54
}
44
55
 
45
56
int64_t FileImpl::size() const