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

« back to all changes in this revision

Viewing changes to src/qt/local_client/AccountImpl.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:
12
12
 
13
13
#include <cassert>
14
14
 
 
15
#include <iostream>  // TODO: remove this
 
16
 
15
17
using namespace std;
16
18
 
17
19
namespace unity
31
33
 
32
34
// Return ${STORAGE_FRAMEWORK_ROOT}/storage-framework. If STORAGE_FRAMEWORK_ROOT
33
35
// is not set, return ${XDG_DATA_HOME}/storage-framework.
 
36
// ${STORAGE_FRAMEWORK_ROOT} or ${XDG_DATA_HOME} must exist and be a directory.
 
37
// If the storage-framework underneath that data directory does not exist, it is created.
34
38
 
35
39
string get_data_dir()
36
40
{
39
43
    {
40
44
        dir = g_get_user_data_dir();
41
45
    }
 
46
 
 
47
    boost::system::error_code ec;
 
48
 
 
49
    // The directory must exist.
 
50
    bool is_dir = boost::filesystem::is_directory(dir, ec);
 
51
    if (ec || !is_dir)
 
52
    {
 
53
        throw StorageException();  // TODO
 
54
    }
 
55
 
 
56
    // Create the storage-framework directory if it doesn't exist yet.
42
57
    string data_dir(dir);
43
58
    data_dir += "/storage-framework";
 
59
    if (!boost::filesystem::exists(data_dir))
 
60
    {
 
61
        boost::filesystem::create_directories(data_dir, ec);
 
62
        if (ec)
 
63
        {
 
64
            throw StorageException();  // TODO
 
65
        }
 
66
    }
44
67
    return data_dir;
45
68
}
46
69
 
82
105
    return description_;
83
106
}
84
107
 
85
 
QFuture<QVector<Root::SPtr>> AccountImpl::get_roots()
 
108
QFuture<QVector<Root::SPtr>> AccountImpl::roots()
86
109
{
87
110
    using namespace boost::filesystem;
88
111
 
89
112
    QFutureInterface<QVector<Root::SPtr>> qf;
90
113
 
91
 
    if (roots_.isEmpty())
 
114
    if (!roots_.isEmpty())
 
115
    {
 
116
        qf.reportResult(roots_);
 
117
        return qf.future();
 
118
    }
 
119
 
 
120
    try
92
121
    {
93
122
        // Create the root on first access.
94
123
        auto rpath = canonical(get_data_dir()).native();
96
125
        Root::SPtr root(new Root(impl));
97
126
        impl->set_root(root);
98
127
        impl->set_public_instance(root);
99
 
        try
100
 
        {
101
 
            file_status st = status(roots_[0]->native_identity().toStdString());
102
 
            if (!is_directory(st))
103
 
            {
104
 
                qf.reportException(StorageException());  // TODO
105
 
                return qf.future();
106
 
            }
107
 
        }
108
 
        catch (std::exception const&)
109
 
        {
110
 
            qf.reportException(StorageException());  // TODO
111
 
            return qf.future();
112
 
        }
113
128
        roots_.append(root);
114
129
    }
115
 
 
 
130
    catch (std::exception const&)
 
131
    {
 
132
        qf.reportException(StorageException());  // TODO
 
133
        return qf.future();
 
134
    }
116
135
    qf.reportResult(roots_);
117
136
    return qf.future();
118
137
}