Merge lp:~unity-api-team/storage-framework/merge-devel into lp:storage-framework
- merge-devel
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Michi Henning |
Approved revision: | 64 |
Merged at revision: | 11 |
Proposed branch: | lp:~unity-api-team/storage-framework/merge-devel |
Merge into: | lp:storage-framework |
Diff against target: |
14429 lines (+8069/-2223) 126 files modified
CMakeLists.txt (+5/-2) data/provider.xml (+12/-9) debian/bileto_pre_release_hook (+1/-1) debian/changelog (+6/-0) demo/provider_test/CMakeLists.txt (+0/-1) demo/provider_test/provider-test.cpp (+55/-60) include/unity/storage/internal/ItemMetadata.h (+4/-1) include/unity/storage/internal/TraceMessageHandler.h (+47/-0) include/unity/storage/internal/dbus_error.h (+32/-0) include/unity/storage/internal/dbusmarshal.h (+44/-0) include/unity/storage/provider/CMakeLists.txt (+2/-0) include/unity/storage/provider/Exceptions.h (+187/-0) include/unity/storage/provider/ProviderBase.h (+7/-3) include/unity/storage/provider/TempfileUploadJob.h (+6/-0) include/unity/storage/provider/internal/AccountData.h (+5/-0) include/unity/storage/provider/internal/DBusPeerCache.h (+5/-0) include/unity/storage/provider/internal/DownloadJobImpl.h (+0/-4) include/unity/storage/provider/internal/Handler.h (+2/-0) include/unity/storage/provider/internal/MainLoopExecutor.h (+1/-15) include/unity/storage/provider/internal/PendingJobs.h (+21/-11) include/unity/storage/provider/internal/ProviderInterface.h (+5/-0) include/unity/storage/provider/internal/ServerImpl.h (+2/-0) include/unity/storage/provider/internal/TempfileUploadJobImpl.h (+6/-1) include/unity/storage/provider/internal/TestServerImpl.h (+65/-0) include/unity/storage/provider/internal/UploadJobImpl.h (+4/-4) include/unity/storage/provider/internal/dbusmarshal.h (+7/-0) include/unity/storage/provider/metadata_keys.h (+19/-6) include/unity/storage/provider/testing/CMakeLists.txt (+5/-0) include/unity/storage/provider/testing/TestServer.h (+68/-0) include/unity/storage/qt/client/Account.h (+1/-1) include/unity/storage/qt/client/Exceptions.h (+13/-5) include/unity/storage/qt/client/Item.h (+1/-1) include/unity/storage/qt/client/Root.h (+1/-1) include/unity/storage/qt/client/Runtime.h (+13/-0) include/unity/storage/qt/client/Uploader.h (+8/-0) include/unity/storage/qt/client/internal/AccountBase.h (+1/-1) include/unity/storage/qt/client/internal/ItemBase.h (+6/-2) include/unity/storage/qt/client/internal/RootBase.h (+1/-1) include/unity/storage/qt/client/internal/RuntimeBase.h (+9/-4) include/unity/storage/qt/client/internal/UploaderBase.h (+4/-1) include/unity/storage/qt/client/internal/local_client/DownloaderImpl.h (+2/-1) include/unity/storage/qt/client/internal/local_client/FolderImpl.h (+1/-0) include/unity/storage/qt/client/internal/local_client/ItemImpl.h (+4/-7) include/unity/storage/qt/client/internal/local_client/RuntimeImpl.h (+2/-0) include/unity/storage/qt/client/internal/local_client/UploaderImpl.h (+2/-2) include/unity/storage/qt/client/internal/local_client/storage_exception.h (+94/-0) include/unity/storage/qt/client/internal/make_future.h (+21/-37) include/unity/storage/qt/client/internal/remote_client/AccountImpl.h (+2/-1) include/unity/storage/qt/client/internal/remote_client/Handler.h (+38/-2) include/unity/storage/qt/client/internal/remote_client/ItemImpl.h (+0/-3) include/unity/storage/qt/client/internal/remote_client/RuntimeImpl.h (+8/-0) include/unity/storage/qt/client/internal/remote_client/UploaderImpl.h (+4/-2) include/unity/storage/qt/client/internal/remote_client/dbusmarshal.h (+16/-17) include/unity/storage/qt/client/internal/remote_client/validate.h (+51/-0) src/internal/CMakeLists.txt (+5/-0) src/internal/TraceMessageHandler.cpp (+96/-0) src/internal/dbusmarshal.cpp (+113/-0) src/provider/CMakeLists.txt (+48/-17) src/provider/Exceptions.cpp (+157/-0) src/provider/TempfileUploadJob.cpp (+5/-0) src/provider/internal/DownloadJobImpl.cpp (+31/-15) src/provider/internal/Handler.cpp (+84/-13) src/provider/internal/MainLoopExecutor.cpp (+0/-4) src/provider/internal/PendingJobs.cpp (+109/-106) src/provider/internal/ProviderInterface.cpp (+9/-29) src/provider/internal/ServerImpl.cpp (+7/-2) src/provider/internal/TempfileUploadJobImpl.cpp (+21/-1) src/provider/internal/TestServerImpl.cpp (+84/-0) src/provider/internal/UploadJobImpl.cpp (+35/-18) src/provider/internal/dbusmarshal.cpp (+38/-9) src/provider/testing/TestServer.cpp (+60/-0) src/qt/client/Account.cpp (+1/-1) src/qt/client/CMakeLists.txt (+2/-1) src/qt/client/Exceptions.cpp (+14/-9) src/qt/client/Item.cpp (+1/-1) src/qt/client/Root.cpp (+2/-1) src/qt/client/Runtime.cpp (+6/-0) src/qt/client/Uploader.cpp (+5/-0) src/qt/client/internal/AccountBase.cpp (+10/-3) src/qt/client/internal/ItemBase.cpp (+39/-4) src/qt/client/internal/RootBase.cpp (+11/-2) src/qt/client/internal/RuntimeBase.cpp (+0/-5) src/qt/client/internal/UploaderBase.cpp (+11/-2) src/qt/client/internal/local_client/AccountImpl.cpp (+16/-3) src/qt/client/internal/local_client/CMakeLists.txt (+1/-0) src/qt/client/internal/local_client/DownloaderImpl.cpp (+27/-13) src/qt/client/internal/local_client/FileImpl.cpp (+25/-23) src/qt/client/internal/local_client/FolderImpl.cpp (+79/-50) src/qt/client/internal/local_client/ItemImpl.cpp (+148/-131) src/qt/client/internal/local_client/RootImpl.cpp (+88/-18) src/qt/client/internal/local_client/RuntimeImpl.cpp (+16/-1) src/qt/client/internal/local_client/UploaderImpl.cpp (+53/-36) src/qt/client/internal/local_client/storage_exception.cpp (+99/-0) src/qt/client/internal/remote_client/AccountImpl.cpp (+28/-10) src/qt/client/internal/remote_client/CMakeLists.txt (+1/-0) src/qt/client/internal/remote_client/DownloaderImpl.cpp (+7/-5) src/qt/client/internal/remote_client/FileImpl.cpp (+42/-26) src/qt/client/internal/remote_client/FolderImpl.cpp (+82/-42) src/qt/client/internal/remote_client/ItemImpl.cpp (+91/-68) src/qt/client/internal/remote_client/RootImpl.cpp (+67/-12) src/qt/client/internal/remote_client/RuntimeImpl.cpp (+81/-14) src/qt/client/internal/remote_client/UploaderImpl.cpp (+32/-17) src/qt/client/internal/remote_client/dbusmarshal.cpp (+102/-90) src/qt/client/internal/remote_client/validate.cpp (+169/-0) tests/CMakeLists.txt (+5/-2) tests/headers/CMakeLists.txt (+5/-0) tests/headers/compile_headers.py (+10/-13) tests/local-client/local-client_test.cpp (+1794/-338) tests/provider-AccountData/AccountData_test.cpp (+141/-0) tests/provider-AccountData/CMakeLists.txt (+8/-0) tests/provider-DBusPeerCache/CMakeLists.txt (+8/-0) tests/provider-DBusPeerCache/DBusPeerCache_test.cpp (+141/-0) tests/provider-ProviderInterface/CMakeLists.txt (+16/-0) tests/provider-ProviderInterface/ProviderInterface_test.cpp (+789/-0) tests/provider-ProviderInterface/TestProvider.cpp (+462/-0) tests/provider-ProviderInterface/TestProvider.h (+65/-0) tests/remote-client/CMakeLists.txt (+4/-3) tests/remote-client/MockProvider.cpp (+236/-0) tests/remote-client/MockProvider.h (+96/-0) tests/remote-client/remote-client_test.cpp (+947/-856) tests/utils/CMakeLists.txt (+16/-2) tests/utils/DBusEnvironment.cpp (+5/-0) tests/utils/DBusEnvironment.h (+1/-0) tests/utils/ProviderFixture.cpp (+84/-0) tests/utils/ProviderFixture.h (+50/-0) tests/utils/fake-online-accounts-daemon.py (+2/-0) |
To merge this branch: | bzr merge lp:~unity-api-team/storage-framework/merge-devel |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michi Henning (community) | Approve | ||
Review via email: mp+302665@code.launchpad.net |
Commit message
Merged devel at revision 64. Lots of fixes in preparation for integration with backup service and mcloud provider.
Description of the change
Merged devel at revision 64. Lots of fixes in preparation for integration with backup service and mcloud provider.
Michi Henning (michihenning) wrote : | # |
Oops, sorry, that wasn't meant to be approved.
- 57. By Michi Henning
-
Increased remote client coverage.
Approved by James Henstridge, unity-api-1-bot.
- 58. By Michi Henning
-
Added provider headers to unit tests.
Approved by unity-api-1-bot, James Henstridge.
- 59. By Michi Henning
-
Removed half-close on the provider side because this messes with QLocalSocket on the client side.
Approved by James Henstridge, unity-api-1-bot.
- 60. By Michi Henning
-
Increased test timeouts because CI builders are hopelessly overloaded.
Approved by unity-api-1-bot, James Henstridge.
- 61. By James Henstridge
-
Add a drain() method to UploadJob to allow the provider to read the last bit of data from the socket when the client asks to finish the upload.
Approved by unity-api-1-bot, Michi Henning.
- 62. By Michi Henning
-
Don't throw when unknown metadata key is received and log a warning instead.
Approved by unity-api-1-bot, Michi Henning, James Henstridge.
- 63. By Michi Henning
-
Removed stale debug trace. Suppressed more compile warnings from system headers that caused a lot of noise in the arm builds.
Approved by James Henstridge, unity-api-1-bot.
- 64. By Michi Henning
-
Merged devel at revision 64.
- 65. By Michi Henning
-
Merged devel at revision 68.
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2016-07-22 08:38:24 +0000 | |||
3 | +++ CMakeLists.txt 2016-09-09 02:13:43 +0000 | |||
4 | @@ -17,7 +17,7 @@ | |||
5 | 17 | # These two should be incremented when the ABI changes. | 17 | # These two should be incremented when the ABI changes. |
6 | 18 | set(SF_CLIENT_SOVERSION "0") | 18 | set(SF_CLIENT_SOVERSION "0") |
7 | 19 | execute_process( | 19 | execute_process( |
9 | 20 | COMMAND /bin/sh ${CMAKE_CURRENT_SOURCE_DIR}/get-provider-soversion.sh | 20 | COMMAND /bin/sh ${CMAKE_CURRENT_SOURCE_DIR}/tools/get-provider-soversion.sh |
10 | 21 | OUTPUT_VARIABLE SF_PROVIDER_SOVERSION | 21 | OUTPUT_VARIABLE SF_PROVIDER_SOVERSION |
11 | 22 | OUTPUT_STRIP_TRAILING_WHITESPACE | 22 | OUTPUT_STRIP_TRAILING_WHITESPACE |
12 | 23 | RESULT_VARIABLE result) | 23 | RESULT_VARIABLE result) |
13 | @@ -108,7 +108,7 @@ | |||
14 | 108 | 108 | ||
15 | 109 | include(GNUInstallDirs) | 109 | include(GNUInstallDirs) |
16 | 110 | 110 | ||
18 | 111 | find_package(Boost COMPONENTS filesystem system thread REQUIRED) | 111 | find_package(Boost 1.56 COMPONENTS filesystem system thread REQUIRED) |
19 | 112 | find_package(Qt5Concurrent REQUIRED) | 112 | find_package(Qt5Concurrent REQUIRED) |
20 | 113 | find_package(Qt5Core REQUIRED) | 113 | find_package(Qt5Core REQUIRED) |
21 | 114 | find_package(Qt5DBus REQUIRED) | 114 | find_package(Qt5DBus REQUIRED) |
22 | @@ -130,8 +130,11 @@ | |||
23 | 130 | enable_coverage_report( | 130 | enable_coverage_report( |
24 | 131 | TARGETS | 131 | TARGETS |
25 | 132 | qt-client-lib-common | 132 | qt-client-lib-common |
26 | 133 | storage-framework-common-internal | ||
27 | 133 | storage-framework-qt-client | 134 | storage-framework-qt-client |
28 | 134 | storage-framework-qt-local-client | 135 | storage-framework-qt-local-client |
29 | 136 | sf-provider-objects | ||
30 | 137 | storage-framework-provider | ||
31 | 135 | FILTER | 138 | FILTER |
32 | 136 | ${CMAKE_SOURCE_DIR}/tests/* | 139 | ${CMAKE_SOURCE_DIR}/tests/* |
33 | 137 | ${CMAKE_BINARY_DIR}/* | 140 | ${CMAKE_BINARY_DIR}/* |
34 | 138 | 141 | ||
35 | === modified file 'data/provider.xml' | |||
36 | --- data/provider.xml 2016-07-11 07:17:04 +0000 | |||
37 | +++ data/provider.xml 2016-09-09 02:13:43 +0000 | |||
38 | @@ -5,14 +5,17 @@ | |||
39 | 5 | com.canonical.StorageFramework.Provider: | 5 | com.canonical.StorageFramework.Provider: |
40 | 6 | @short_description: Interface providing access to a storage account | 6 | @short_description: Interface providing access to a storage account |
41 | 7 | 7 | ||
44 | 8 | For methods dealing with metadata, the representation | 8 | For methods returning metadata, the representation |
45 | 9 | "(ssssia{sv})" is used, where the struct members are: | 9 | "(sasssia{sv})" is used, where the struct members are: |
46 | 10 | - item_id | 10 | - item_id |
48 | 11 | - parent_id | 11 | - parent_ids |
49 | 12 | - name | 12 | - name |
50 | 13 | - etag | 13 | - etag |
51 | 14 | - type (enum: file, folder, root) | 14 | - type (enum: file, folder, root) |
52 | 15 | - metadata | 15 | - metadata |
53 | 16 | |||
54 | 17 | Note that parent_ids is a sequence of IDs instead of a single ID to allow the client to | ||
55 | 18 | navigate items in Google Drive, which permits more than one parent for a file or folder. | ||
56 | 16 | --> | 19 | --> |
57 | 17 | <interface name="com.canonical.StorageFramework.Provider"> | 20 | <interface name="com.canonical.StorageFramework.Provider"> |
58 | 18 | <!-- | 21 | <!-- |
59 | @@ -25,7 +28,7 @@ | |||
60 | 25 | of files, this list will contain a single item. | 28 | of files, this list will contain a single item. |
61 | 26 | --> | 29 | --> |
62 | 27 | <method name="Roots"> | 30 | <method name="Roots"> |
64 | 28 | <arg type="a(ssssia{sv})" name="roots" direction="out"/> | 31 | <arg type="a(sasssia{sv})" name="roots" direction="out"/> |
65 | 29 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList<unity::storage::internal::ItemMetadata>"/> | 32 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList<unity::storage::internal::ItemMetadata>"/> |
66 | 30 | </method> | 33 | </method> |
67 | 31 | 34 | ||
68 | @@ -45,7 +48,7 @@ | |||
69 | 45 | <method name="List"> | 48 | <method name="List"> |
70 | 46 | <arg type="s" name="item_id" direction="in"/> | 49 | <arg type="s" name="item_id" direction="in"/> |
71 | 47 | <arg type="s" name="page_token" direction="in"/> | 50 | <arg type="s" name="page_token" direction="in"/> |
73 | 48 | <arg type="a(ssssia{sv})" name="children" direction="out"/> | 51 | <arg type="a(sasssia{sv})" name="children" direction="out"/> |
74 | 49 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList<unity::storage::internal::ItemMetadata>"/> | 52 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList<unity::storage::internal::ItemMetadata>"/> |
75 | 50 | <arg type="s" name="next_token" direction="out"/> | 53 | <arg type="s" name="next_token" direction="out"/> |
76 | 51 | </method> | 54 | </method> |
77 | @@ -60,7 +63,7 @@ | |||
78 | 60 | <method name="Lookup"> | 63 | <method name="Lookup"> |
79 | 61 | <arg type="s" name="parent_id" direction="in"/> | 64 | <arg type="s" name="parent_id" direction="in"/> |
80 | 62 | <arg type="s" name="name" direction="in"/> | 65 | <arg type="s" name="name" direction="in"/> |
82 | 63 | <arg type="a(ssssia{sv})" name="items" direction="out"/> | 66 | <arg type="a(sasssia{sv})" name="items" direction="out"/> |
83 | 64 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList<unity::storage::internal::ItemMetadata>"/> | 67 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList<unity::storage::internal::ItemMetadata>"/> |
84 | 65 | </method> | 68 | </method> |
85 | 66 | 69 | ||
86 | @@ -72,7 +75,7 @@ | |||
87 | 72 | --> | 75 | --> |
88 | 73 | <method name="Metadata"> | 76 | <method name="Metadata"> |
89 | 74 | <arg type="s" name="item_id" direction="in"/> | 77 | <arg type="s" name="item_id" direction="in"/> |
91 | 75 | <arg type="(ssssia{sv})" name="metadata" direction="out"/> | 78 | <arg type="(sasssia{sv})" name="metadata" direction="out"/> |
92 | 76 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="unity::storage::internal::ItemMetadata"/> | 79 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="unity::storage::internal::ItemMetadata"/> |
93 | 77 | </method> | 80 | </method> |
94 | 78 | 81 | ||
95 | @@ -86,7 +89,7 @@ | |||
96 | 86 | <method name="CreateFolder"> | 89 | <method name="CreateFolder"> |
97 | 87 | <arg type="s" name="parent_id" direction="in"/> | 90 | <arg type="s" name="parent_id" direction="in"/> |
98 | 88 | <arg type="s" name="name" direction="in"/> | 91 | <arg type="s" name="name" direction="in"/> |
100 | 89 | <arg type="(ssssia{sv})" name="metadata" direction="out"/> | 92 | <arg type="(sasssia{sv})" name="metadata" direction="out"/> |
101 | 90 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="unity::storage::internal::ItemMetadata"/> | 93 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="unity::storage::internal::ItemMetadata"/> |
102 | 91 | </method> | 94 | </method> |
103 | 92 | 95 | ||
104 | @@ -160,7 +163,7 @@ | |||
105 | 160 | --> | 163 | --> |
106 | 161 | <method name="FinishUpload"> | 164 | <method name="FinishUpload"> |
107 | 162 | <arg type="s" name="upload_id" direction="in"/> | 165 | <arg type="s" name="upload_id" direction="in"/> |
109 | 163 | <arg type="(ssssia{sv})" name="metadata" direction="out"/> | 166 | <arg type="(sasssia{sv})" name="metadata" direction="out"/> |
110 | 164 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="unity::storage::internal::ItemMetadata"/> | 167 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="unity::storage::internal::ItemMetadata"/> |
111 | 165 | </method> | 168 | </method> |
112 | 166 | 169 | ||
113 | 167 | 170 | ||
114 | === modified file 'debian/bileto_pre_release_hook' | |||
115 | --- debian/bileto_pre_release_hook 2016-07-22 04:23:08 +0000 | |||
116 | +++ debian/bileto_pre_release_hook 2016-09-09 02:13:43 +0000 | |||
117 | @@ -2,7 +2,7 @@ | |||
118 | 2 | 2 | ||
119 | 3 | set -eu | 3 | set -eu |
120 | 4 | 4 | ||
122 | 5 | soversion=$(sh ./get-provider-soversion.sh) | 5 | soversion=$(sh ./tools/get-provider-soversion.sh) |
123 | 6 | 6 | ||
124 | 7 | infile=./debian/control.in | 7 | infile=./debian/control.in |
125 | 8 | outfile=./debian/control | 8 | outfile=./debian/control |
126 | 9 | 9 | ||
127 | === modified file 'debian/changelog' | |||
128 | --- debian/changelog 2016-08-04 07:20:09 +0000 | |||
129 | +++ debian/changelog 2016-09-09 02:13:43 +0000 | |||
130 | @@ -1,3 +1,9 @@ | |||
131 | 1 | storage-framework (0.1+16.10.20160804.1-0ubuntu2) UNRELEASED; urgency=medium | ||
132 | 2 | |||
133 | 3 | * Merged devel at revision 64. | ||
134 | 4 | |||
135 | 5 | -- Michi Henning <michi.henning@canonical.com> Fri, 26 Aug 2016 14:03:02 +1000 | ||
136 | 6 | |||
137 | 1 | storage-framework (0.1+16.10.20160804.1-0ubuntu1) yakkety; urgency=medium | 7 | storage-framework (0.1+16.10.20160804.1-0ubuntu1) yakkety; urgency=medium |
138 | 2 | 8 | ||
139 | 3 | [ Michi Henning ] | 9 | [ Michi Henning ] |
140 | 4 | 10 | ||
141 | === modified file 'demo/provider_test/CMakeLists.txt' | |||
142 | --- demo/provider_test/CMakeLists.txt 2016-05-23 02:27:16 +0000 | |||
143 | +++ demo/provider_test/CMakeLists.txt 2016-09-09 02:13:43 +0000 | |||
144 | @@ -1,4 +1,3 @@ | |||
145 | 1 | |||
146 | 2 | add_definitions(-DBOOST_THREAD_VERSION=4) | 1 | add_definitions(-DBOOST_THREAD_VERSION=4) |
147 | 3 | 2 | ||
148 | 4 | add_executable(provider-test provider-test.cpp) | 3 | add_executable(provider-test provider-test.cpp) |
149 | 5 | 4 | ||
150 | === modified file 'demo/provider_test/provider-test.cpp' | |||
151 | --- demo/provider_test/provider-test.cpp 2016-07-26 03:30:05 +0000 | |||
152 | +++ demo/provider_test/provider-test.cpp 2016-09-09 02:13:43 +0000 | |||
153 | @@ -17,6 +17,8 @@ | |||
154 | 17 | */ | 17 | */ |
155 | 18 | 18 | ||
156 | 19 | #include <unity/storage/provider/DownloadJob.h> | 19 | #include <unity/storage/provider/DownloadJob.h> |
157 | 20 | #include <unity/storage/provider/Exceptions.h> | ||
158 | 21 | #include <unity/storage/provider/metadata_keys.h> | ||
159 | 20 | #include <unity/storage/provider/ProviderBase.h> | 22 | #include <unity/storage/provider/ProviderBase.h> |
160 | 21 | #include <unity/storage/provider/Server.h> | 23 | #include <unity/storage/provider/Server.h> |
161 | 22 | #include <unity/storage/provider/TempfileUploadJob.h> | 24 | #include <unity/storage/provider/TempfileUploadJob.h> |
162 | @@ -32,47 +34,8 @@ | |||
163 | 32 | using namespace unity::storage::provider; | 34 | using namespace unity::storage::provider; |
164 | 33 | using namespace std; | 35 | using namespace std; |
165 | 34 | 36 | ||
166 | 35 | #if BOOST_VERSION >= 105600 | ||
167 | 36 | using boost::make_ready_future; | 37 | using boost::make_ready_future; |
168 | 37 | using boost::make_exceptional_future; | 38 | using boost::make_exceptional_future; |
169 | 38 | #else | ||
170 | 39 | namespace | ||
171 | 40 | { | ||
172 | 41 | |||
173 | 42 | boost::future<void> make_ready_future() | ||
174 | 43 | { | ||
175 | 44 | boost::promise<void> p; | ||
176 | 45 | p.set_value(); | ||
177 | 46 | return p.get_future(); | ||
178 | 47 | } | ||
179 | 48 | |||
180 | 49 | template <typename T> | ||
181 | 50 | boost::future<T> make_ready_future(T& value) | ||
182 | 51 | { | ||
183 | 52 | boost::promise<T> p; | ||
184 | 53 | p.set_value(value); | ||
185 | 54 | return p.get_future(); | ||
186 | 55 | } | ||
187 | 56 | |||
188 | 57 | template <typename T> | ||
189 | 58 | boost::future<T> make_ready_future(T&& value) | ||
190 | 59 | { | ||
191 | 60 | boost::promise<T> p; | ||
192 | 61 | p.set_value(std::move(value)); | ||
193 | 62 | return p.get_future(); | ||
194 | 63 | } | ||
195 | 64 | |||
196 | 65 | template <typename T, typename E> | ||
197 | 66 | boost::future<T> make_exceptional_future(E const& ex) | ||
198 | 67 | { | ||
199 | 68 | boost::promise<T> p; | ||
200 | 69 | p.set_exception(boost::copy_exception(ex)); | ||
201 | 70 | return p.get_future(); | ||
202 | 71 | } | ||
203 | 72 | |||
204 | 73 | } | ||
205 | 74 | #endif | ||
206 | 75 | |||
207 | 76 | 39 | ||
208 | 77 | class MyProvider : public ProviderBase | 40 | class MyProvider : public ProviderBase |
209 | 78 | { | 41 | { |
210 | @@ -140,7 +103,7 @@ | |||
211 | 140 | printf("roots() called by %s (%d)\n", ctx.security_label.c_str(), ctx.pid); | 103 | printf("roots() called by %s (%d)\n", ctx.security_label.c_str(), ctx.pid); |
212 | 141 | fflush(stdout); | 104 | fflush(stdout); |
213 | 142 | ItemList roots = { | 105 | ItemList roots = { |
215 | 143 | {"root_id", "", "Root", "etag", ItemType::root, {}}, | 106 | {"root_id", {}, "Root", "etag", ItemType::root, {}}, |
216 | 144 | }; | 107 | }; |
217 | 145 | return make_ready_future<ItemList>(roots); | 108 | return make_ready_future<ItemList>(roots); |
218 | 146 | } | 109 | } |
219 | @@ -153,14 +116,20 @@ | |||
220 | 153 | fflush(stdout); | 116 | fflush(stdout); |
221 | 154 | if (item_id != "root_id") | 117 | if (item_id != "root_id") |
222 | 155 | { | 118 | { |
224 | 156 | return make_exceptional_future<tuple<ItemList,string>>(runtime_error("unknown folder")); | 119 | string msg = string("Item::list(): no such item: \"") + item_id + "\""; |
225 | 120 | return make_exceptional_future<tuple<ItemList,string>>(NotExistsException(msg, item_id)); | ||
226 | 157 | } | 121 | } |
227 | 158 | if (page_token != "") | 122 | if (page_token != "") |
228 | 159 | { | 123 | { |
230 | 160 | return make_exceptional_future<tuple<ItemList,string>>(runtime_error("unknown page token")); | 124 | string msg = string("Item::list(): invalid page token: \"") + page_token + "\""; |
231 | 125 | return make_exceptional_future<tuple<ItemList,string>>(LogicException(msg)); | ||
232 | 161 | } | 126 | } |
235 | 162 | ItemList children = { | 127 | ItemList children = |
236 | 163 | {"child_id", "root_id", "Child", "etag", ItemType::file, {}} | 128 | { |
237 | 129 | { | ||
238 | 130 | "child_id", { "root_id" }, "Child", "etag", ItemType::file, | ||
239 | 131 | { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } } | ||
240 | 132 | } | ||
241 | 164 | }; | 133 | }; |
242 | 165 | boost::promise<tuple<ItemList,string>> p; | 134 | boost::promise<tuple<ItemList,string>> p; |
243 | 166 | p.set_value(make_tuple(children, string())); | 135 | p.set_value(make_tuple(children, string())); |
244 | @@ -172,12 +141,20 @@ | |||
245 | 172 | { | 141 | { |
246 | 173 | printf("lookup('%s', '%s') called by %s (%d)\n", parent_id.c_str(), name.c_str(), ctx.security_label.c_str(), ctx.pid); | 142 | printf("lookup('%s', '%s') called by %s (%d)\n", parent_id.c_str(), name.c_str(), ctx.security_label.c_str(), ctx.pid); |
247 | 174 | fflush(stdout); | 143 | fflush(stdout); |
254 | 175 | if (parent_id != "root_id" || name != "Child") | 144 | if (parent_id != "root_id") |
255 | 176 | { | 145 | { |
256 | 177 | return make_exceptional_future<ItemList>(runtime_error("file not found")); | 146 | string msg = string("Folder::lookup(): no such item: \"") + parent_id + "\""; |
257 | 178 | } | 147 | return make_exceptional_future<ItemList>(NotExistsException(msg, parent_id)); |
258 | 179 | ItemList children = { | 148 | } |
259 | 180 | {"child_id", "root_id", "Child", "etag", ItemType::file, {}} | 149 | if (name != "Child") |
260 | 150 | { | ||
261 | 151 | string msg = string("Folder::lookup(): no such item: \"") + name + "\""; | ||
262 | 152 | return make_exceptional_future<ItemList>(NotExistsException(msg, name)); | ||
263 | 153 | } | ||
264 | 154 | ItemList children = | ||
265 | 155 | { | ||
266 | 156 | { "child_id", { "root_id" }, "Child", "etag", ItemType::file, | ||
267 | 157 | { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } } } | ||
268 | 181 | }; | 158 | }; |
269 | 182 | return make_ready_future<ItemList>(children); | 159 | return make_ready_future<ItemList>(children); |
270 | 183 | } | 160 | } |
271 | @@ -189,15 +166,24 @@ | |||
272 | 189 | fflush(stdout); | 166 | fflush(stdout); |
273 | 190 | if (item_id == "root_id") | 167 | if (item_id == "root_id") |
274 | 191 | { | 168 | { |
276 | 192 | Item metadata{"root_id", "", "Root", "etag", ItemType::root, {}}; | 169 | Item metadata{"root_id", {}, "Root", "etag", ItemType::root, {}}; |
277 | 193 | return make_ready_future<Item>(metadata); | 170 | return make_ready_future<Item>(metadata); |
278 | 194 | } | 171 | } |
279 | 195 | else if (item_id == "child_id") | 172 | else if (item_id == "child_id") |
280 | 196 | { | 173 | { |
285 | 197 | Item metadata{"child_id", "root_id", "Child", "etag", ItemType::file, {}}; | 174 | Item metadata |
286 | 198 | return make_ready_future<Item>(metadata); | 175 | { |
287 | 199 | } | 176 | "child_id", { "root_id" }, "Child", "etag", ItemType::file, |
288 | 200 | return make_exceptional_future<Item>(runtime_error("no such file")); | 177 | { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } } |
289 | 178 | }; | ||
290 | 179 | return make_ready_future<Item>(metadata); | ||
291 | 180 | } | ||
292 | 181 | else if (item_id == "child_folder_id") | ||
293 | 182 | { | ||
294 | 183 | Item metadata{"child_folder_id", { "root_id" }, "Child_Folder", "etag", ItemType::folder, {}}; | ||
295 | 184 | return make_ready_future<Item>(metadata); | ||
296 | 185 | } | ||
297 | 186 | return make_exceptional_future<Item>(NotExistsException("metadata(): no such item: " + item_id, item_id)); | ||
298 | 201 | } | 187 | } |
299 | 202 | 188 | ||
300 | 203 | boost::future<Item> MyProvider::create_folder( | 189 | boost::future<Item> MyProvider::create_folder( |
301 | @@ -206,7 +192,7 @@ | |||
302 | 206 | { | 192 | { |
303 | 207 | printf("create_folder('%s', '%s') called by %s (%d)\n", parent_id.c_str(), name.c_str(), ctx.security_label.c_str(), ctx.pid); | 193 | printf("create_folder('%s', '%s') called by %s (%d)\n", parent_id.c_str(), name.c_str(), ctx.security_label.c_str(), ctx.pid); |
304 | 208 | fflush(stdout); | 194 | fflush(stdout); |
306 | 209 | Item metadata{"new_folder_id", parent_id, name, "etag", ItemType::folder, {}}; | 195 | Item metadata{"new_folder_id", { parent_id }, name, "etag", ItemType::folder, {}}; |
307 | 210 | return make_ready_future<Item>(metadata); | 196 | return make_ready_future<Item>(metadata); |
308 | 211 | } | 197 | } |
309 | 212 | 198 | ||
310 | @@ -242,7 +228,12 @@ | |||
311 | 242 | 228 | ||
312 | 243 | unique_ptr<DownloadJob> job(new MyDownloadJob(make_job_id())); | 229 | unique_ptr<DownloadJob> job(new MyDownloadJob(make_job_id())); |
313 | 244 | const char contents[] = "Hello world"; | 230 | const char contents[] = "Hello world"; |
315 | 245 | write(job->write_socket(), contents, sizeof(contents)); | 231 | if (write(job->write_socket(), contents, sizeof(contents)) != sizeof(contents)) |
316 | 232 | { | ||
317 | 233 | ResourceException e("download(): write failed", errno); | ||
318 | 234 | job->report_error(make_exception_ptr(e)); | ||
319 | 235 | return make_exceptional_future<unique_ptr<DownloadJob>>(e); | ||
320 | 236 | } | ||
321 | 246 | job->report_complete(); | 237 | job->report_complete(); |
322 | 247 | return make_ready_future(std::move(job)); | 238 | return make_ready_future(std::move(job)); |
323 | 248 | } | 239 | } |
324 | @@ -261,7 +252,7 @@ | |||
325 | 261 | { | 252 | { |
326 | 262 | printf("move('%s', '%s', '%s') called by %s (%d)\n", item_id.c_str(), new_parent_id.c_str(), new_name.c_str(), ctx.security_label.c_str(), ctx.pid); | 253 | printf("move('%s', '%s', '%s') called by %s (%d)\n", item_id.c_str(), new_parent_id.c_str(), new_name.c_str(), ctx.security_label.c_str(), ctx.pid); |
327 | 263 | fflush(stdout); | 254 | fflush(stdout); |
329 | 264 | Item metadata{item_id, new_parent_id, new_name, "etag", ItemType::file, {}}; | 255 | Item metadata{item_id, { new_parent_id }, new_name, "etag", ItemType::file, {}}; |
330 | 265 | return make_ready_future(metadata); | 256 | return make_ready_future(metadata); |
331 | 266 | } | 257 | } |
332 | 267 | 258 | ||
333 | @@ -271,7 +262,7 @@ | |||
334 | 271 | { | 262 | { |
335 | 272 | printf("copy('%s', '%s', '%s') called by %s (%d)\n", item_id.c_str(), new_parent_id.c_str(), new_name.c_str(), ctx.security_label.c_str(), ctx.pid); | 263 | printf("copy('%s', '%s', '%s') called by %s (%d)\n", item_id.c_str(), new_parent_id.c_str(), new_name.c_str(), ctx.security_label.c_str(), ctx.pid); |
336 | 273 | fflush(stdout); | 264 | fflush(stdout); |
338 | 274 | Item metadata{"new_item_id", new_parent_id, new_name, "etag", ItemType::file, {}}; | 265 | Item metadata{"new_item_id", { new_parent_id }, new_name, "etag", ItemType::file, {}}; |
339 | 275 | return make_ready_future(metadata); | 266 | return make_ready_future(metadata); |
340 | 276 | } | 267 | } |
341 | 277 | 268 | ||
342 | @@ -294,7 +285,11 @@ | |||
343 | 294 | unlink(new_filename.c_str()); | 285 | unlink(new_filename.c_str()); |
344 | 295 | link(old_filename.c_str(), new_filename.c_str()); | 286 | link(old_filename.c_str(), new_filename.c_str()); |
345 | 296 | 287 | ||
347 | 297 | Item metadata{"some_id", "", "some_upload", "etag", ItemType::file, {}}; | 288 | Item metadata |
348 | 289 | { | ||
349 | 290 | "some_id", { "root_id" }, "some_upload", "etag", ItemType::file, | ||
350 | 291 | { { SIZE_IN_BYTES, 10 }, { LAST_MODIFIED_TIME, "2011-04-05T14:30:10.005Z" } } | ||
351 | 292 | }; | ||
352 | 298 | return make_ready_future(metadata); | 293 | return make_ready_future(metadata); |
353 | 299 | } | 294 | } |
354 | 300 | 295 | ||
355 | 301 | 296 | ||
356 | === modified file 'include/unity/storage/internal/ItemMetadata.h' | |||
357 | --- include/unity/storage/internal/ItemMetadata.h 2016-07-12 02:22:05 +0000 | |||
358 | +++ include/unity/storage/internal/ItemMetadata.h 2016-09-09 02:13:43 +0000 | |||
359 | @@ -21,9 +21,12 @@ | |||
360 | 21 | #include <unity/storage/common.h> | 21 | #include <unity/storage/common.h> |
361 | 22 | 22 | ||
362 | 23 | #pragma GCC diagnostic push | 23 | #pragma GCC diagnostic push |
363 | 24 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
364 | 24 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" |
365 | 26 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
366 | 25 | #include <QMap> | 27 | #include <QMap> |
367 | 26 | #include <QVariant> | 28 | #include <QVariant> |
368 | 29 | #include <QVector> | ||
369 | 27 | #pragma GCC diagnostic pop | 30 | #pragma GCC diagnostic pop |
370 | 28 | 31 | ||
371 | 29 | namespace unity | 32 | namespace unity |
372 | @@ -36,7 +39,7 @@ | |||
373 | 36 | struct ItemMetadata | 39 | struct ItemMetadata |
374 | 37 | { | 40 | { |
375 | 38 | QString item_id; | 41 | QString item_id; |
377 | 39 | QString parent_id; | 42 | QVector<QString> parent_ids; |
378 | 40 | QString name; | 43 | QString name; |
379 | 41 | QString etag; | 44 | QString etag; |
380 | 42 | ItemType type; | 45 | ItemType type; |
381 | 43 | 46 | ||
382 | === added file 'include/unity/storage/internal/TraceMessageHandler.h' | |||
383 | --- include/unity/storage/internal/TraceMessageHandler.h 1970-01-01 00:00:00 +0000 | |||
384 | +++ include/unity/storage/internal/TraceMessageHandler.h 2016-09-09 02:13:43 +0000 | |||
385 | @@ -0,0 +1,47 @@ | |||
386 | 1 | /* | ||
387 | 2 | * Copyright (C) 2015 Canonical Ltd | ||
388 | 3 | * | ||
389 | 4 | * This program is free software: you can redistribute it and/or modify | ||
390 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
391 | 6 | * published by the Free Software Foundation. | ||
392 | 7 | * | ||
393 | 8 | * This program is distributed in the hope that it will be useful, | ||
394 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
395 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
396 | 11 | * GNU Lesser General Public License for more details. | ||
397 | 12 | * | ||
398 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
399 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
400 | 15 | * | ||
401 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
402 | 17 | */ | ||
403 | 18 | |||
404 | 19 | #pragma once | ||
405 | 20 | |||
406 | 21 | #pragma GCC diagnostic push | ||
407 | 22 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
408 | 23 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
409 | 24 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
410 | 25 | #include <QDebug> | ||
411 | 26 | #pragma GCC diagnostic pop | ||
412 | 27 | |||
413 | 28 | namespace unity | ||
414 | 29 | { | ||
415 | 30 | namespace storage | ||
416 | 31 | { | ||
417 | 32 | namespace internal | ||
418 | 33 | { | ||
419 | 34 | |||
420 | 35 | class TraceMessageHandler final | ||
421 | 36 | { | ||
422 | 37 | public: | ||
423 | 38 | TraceMessageHandler(std::string const& prog_name); | ||
424 | 39 | ~TraceMessageHandler(); | ||
425 | 40 | |||
426 | 41 | private: | ||
427 | 42 | QtMessageHandler old_message_handler_; | ||
428 | 43 | }; | ||
429 | 44 | |||
430 | 45 | } // namespace internal | ||
431 | 46 | } // namespace storage | ||
432 | 47 | } // namespace unity | ||
433 | 0 | 48 | ||
434 | === added file 'include/unity/storage/internal/dbus_error.h' | |||
435 | --- include/unity/storage/internal/dbus_error.h 1970-01-01 00:00:00 +0000 | |||
436 | +++ include/unity/storage/internal/dbus_error.h 2016-09-09 02:13:43 +0000 | |||
437 | @@ -0,0 +1,32 @@ | |||
438 | 1 | /* | ||
439 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
440 | 3 | * | ||
441 | 4 | * This program is free software: you can redistribute it and/or modify | ||
442 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
443 | 6 | * published by the Free Software Foundation. | ||
444 | 7 | * | ||
445 | 8 | * This program is distributed in the hope that it will be useful, | ||
446 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
447 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
448 | 11 | * GNU Lesser General Public License for more details. | ||
449 | 12 | * | ||
450 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
451 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
452 | 15 | * | ||
453 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
454 | 17 | */ | ||
455 | 18 | |||
456 | 19 | #pragma once | ||
457 | 20 | |||
458 | 21 | namespace unity | ||
459 | 22 | { | ||
460 | 23 | namespace storage | ||
461 | 24 | { | ||
462 | 25 | namespace internal | ||
463 | 26 | { | ||
464 | 27 | |||
465 | 28 | constexpr char DBUS_ERROR_PREFIX[] = "com.canonical.StorageFramework."; | ||
466 | 29 | |||
467 | 30 | } // namespace internal | ||
468 | 31 | } // namespace storage | ||
469 | 32 | } // namespace unity | ||
470 | 0 | 33 | ||
471 | === added file 'include/unity/storage/internal/dbusmarshal.h' | |||
472 | --- include/unity/storage/internal/dbusmarshal.h 1970-01-01 00:00:00 +0000 | |||
473 | +++ include/unity/storage/internal/dbusmarshal.h 2016-09-09 02:13:43 +0000 | |||
474 | @@ -0,0 +1,44 @@ | |||
475 | 1 | /* | ||
476 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
477 | 3 | * | ||
478 | 4 | * This program is free software: you can redistribute it and/or modify | ||
479 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
480 | 6 | * published by the Free Software Foundation. | ||
481 | 7 | * | ||
482 | 8 | * This program is distributed in the hope that it will be useful, | ||
483 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
484 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
485 | 11 | * GNU Lesser General Public License for more details. | ||
486 | 12 | * | ||
487 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
488 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
489 | 15 | * | ||
490 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
491 | 17 | */ | ||
492 | 18 | |||
493 | 19 | #pragma once | ||
494 | 20 | |||
495 | 21 | #include <unity/storage/internal/ItemMetadata.h> | ||
496 | 22 | |||
497 | 23 | #include <QDBusArgument> | ||
498 | 24 | #include <QMetaType> | ||
499 | 25 | |||
500 | 26 | namespace unity | ||
501 | 27 | { | ||
502 | 28 | namespace storage | ||
503 | 29 | { | ||
504 | 30 | namespace internal | ||
505 | 31 | { | ||
506 | 32 | |||
507 | 33 | QDBusArgument& operator<<(QDBusArgument& argument, ItemMetadata const& metadata); | ||
508 | 34 | QDBusArgument const& operator>>(QDBusArgument const& argument, ItemMetadata& metadata); | ||
509 | 35 | |||
510 | 36 | QDBusArgument& operator<<(QDBusArgument& argument, QList<ItemMetadata> const& md_list); | ||
511 | 37 | QDBusArgument const& operator>>(QDBusArgument const& argument, QList<ItemMetadata>& md_list); | ||
512 | 38 | |||
513 | 39 | } // namespace internal | ||
514 | 40 | } // storage | ||
515 | 41 | } // unity | ||
516 | 42 | |||
517 | 43 | Q_DECLARE_METATYPE(unity::storage::internal::ItemMetadata) | ||
518 | 44 | Q_DECLARE_METATYPE(QList<unity::storage::internal::ItemMetadata>) | ||
519 | 0 | 45 | ||
520 | === modified file 'include/unity/storage/provider/CMakeLists.txt' | |||
521 | --- include/unity/storage/provider/CMakeLists.txt 2016-07-11 03:28:40 +0000 | |||
522 | +++ include/unity/storage/provider/CMakeLists.txt 2016-09-09 02:13:43 +0000 | |||
523 | @@ -3,3 +3,5 @@ | |||
524 | 3 | 3 | ||
525 | 4 | install(FILES ${provider_headers} | 4 | install(FILES ${provider_headers} |
526 | 5 | DESTINATION ${provider_base_includedir}/${includeprefix}) | 5 | DESTINATION ${provider_base_includedir}/${includeprefix}) |
527 | 6 | |||
528 | 7 | add_subdirectory(testing) | ||
529 | 6 | 8 | ||
530 | === added file 'include/unity/storage/provider/Exceptions.h' | |||
531 | --- include/unity/storage/provider/Exceptions.h 1970-01-01 00:00:00 +0000 | |||
532 | +++ include/unity/storage/provider/Exceptions.h 2016-09-09 02:13:43 +0000 | |||
533 | @@ -0,0 +1,187 @@ | |||
534 | 1 | /* | ||
535 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
536 | 3 | * | ||
537 | 4 | * This program is free software: you can redistribute it and/or modify | ||
538 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
539 | 6 | * published by the Free Software Foundation. | ||
540 | 7 | * | ||
541 | 8 | * This program is distributed in the hope that it will be useful, | ||
542 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
543 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
544 | 11 | * GNU Lesser General Public License for more details. | ||
545 | 12 | * | ||
546 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
547 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
548 | 15 | * | ||
549 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
550 | 17 | */ | ||
551 | 18 | |||
552 | 19 | #pragma once | ||
553 | 20 | |||
554 | 21 | #include <unity/storage/visibility.h> | ||
555 | 22 | |||
556 | 23 | #include <string> | ||
557 | 24 | |||
558 | 25 | namespace unity | ||
559 | 26 | { | ||
560 | 27 | namespace storage | ||
561 | 28 | { | ||
562 | 29 | namespace provider | ||
563 | 30 | { | ||
564 | 31 | |||
565 | 32 | // Note: Adding new exception types also requires updating the marshaling and | ||
566 | 33 | // unmarshaling code for exceptions in the client and server APIs. | ||
567 | 34 | |||
568 | 35 | /** | ||
569 | 36 | \brief Base exception class for all server-side exceptions. | ||
570 | 37 | */ | ||
571 | 38 | class UNITY_STORAGE_EXPORT StorageException : public std::exception | ||
572 | 39 | { | ||
573 | 40 | public: | ||
574 | 41 | StorageException(std::string const& exception_type, std::string const& error_message); | ||
575 | 42 | ~StorageException(); | ||
576 | 43 | |||
577 | 44 | virtual char const* what() const noexcept override; | ||
578 | 45 | |||
579 | 46 | std::string type() const; | ||
580 | 47 | std::string error_message() const; | ||
581 | 48 | |||
582 | 49 | private: | ||
583 | 50 | std::string what_string_; | ||
584 | 51 | std::string type_; | ||
585 | 52 | std::string error_message_; | ||
586 | 53 | }; | ||
587 | 54 | |||
588 | 55 | /** | ||
589 | 56 | \brief Indicates errors in the communication between the storage provider and the cloud service. | ||
590 | 57 | */ | ||
591 | 58 | class UNITY_STORAGE_EXPORT RemoteCommsException : public StorageException | ||
592 | 59 | { | ||
593 | 60 | public: | ||
594 | 61 | RemoteCommsException(std::string const& error_message); | ||
595 | 62 | ~RemoteCommsException(); | ||
596 | 63 | }; | ||
597 | 64 | |||
598 | 65 | /** | ||
599 | 66 | \brief Indicates that an item does not exist or could not be found. | ||
600 | 67 | */ | ||
601 | 68 | class UNITY_STORAGE_EXPORT NotExistsException : public StorageException | ||
602 | 69 | { | ||
603 | 70 | public: | ||
604 | 71 | NotExistsException(std::string const& error_message, std::string const& key); | ||
605 | 72 | ~NotExistsException(); | ||
606 | 73 | |||
607 | 74 | std::string key() const; | ||
608 | 75 | |||
609 | 76 | private: | ||
610 | 77 | std::string key_; | ||
611 | 78 | }; | ||
612 | 79 | |||
613 | 80 | /** | ||
614 | 81 | \brief Indicates that an item cannot be created because it exists already. | ||
615 | 82 | */ | ||
616 | 83 | class UNITY_STORAGE_EXPORT ExistsException : public StorageException | ||
617 | 84 | { | ||
618 | 85 | public: | ||
619 | 86 | ExistsException(std::string const& error_message, std::string const& identity, std::string const& name); | ||
620 | 87 | ~ExistsException(); | ||
621 | 88 | |||
622 | 89 | std::string native_identity() const; | ||
623 | 90 | std::string name() const; | ||
624 | 91 | |||
625 | 92 | private: | ||
626 | 93 | std::string identity_; | ||
627 | 94 | std::string name_; | ||
628 | 95 | }; | ||
629 | 96 | |||
630 | 97 | /** | ||
631 | 98 | \brief Indicates that an upload detected a version mismatch. | ||
632 | 99 | */ | ||
633 | 100 | class UNITY_STORAGE_EXPORT ConflictException : public StorageException | ||
634 | 101 | { | ||
635 | 102 | public: | ||
636 | 103 | ConflictException(std::string const& error_message); | ||
637 | 104 | ~ConflictException(); | ||
638 | 105 | }; | ||
639 | 106 | |||
640 | 107 | /** | ||
641 | 108 | \brief Indicates that an operation failed because of a permission problem. | ||
642 | 109 | */ | ||
643 | 110 | class UNITY_STORAGE_EXPORT PermissionException : public StorageException | ||
644 | 111 | { | ||
645 | 112 | public: | ||
646 | 113 | PermissionException(std::string const& error_message); | ||
647 | 114 | ~PermissionException(); | ||
648 | 115 | }; | ||
649 | 116 | |||
650 | 117 | /** | ||
651 | 118 | \brief Indicates that an update failed because the provider ran out of space. | ||
652 | 119 | */ | ||
653 | 120 | class UNITY_STORAGE_EXPORT QuotaException : public StorageException | ||
654 | 121 | { | ||
655 | 122 | public: | ||
656 | 123 | QuotaException(std::string const& error_message); | ||
657 | 124 | ~QuotaException(); | ||
658 | 125 | }; | ||
659 | 126 | |||
660 | 127 | /** | ||
661 | 128 | \brief Indicates that an upload or download was cancelled before it could complete. | ||
662 | 129 | */ | ||
663 | 130 | class UNITY_STORAGE_EXPORT CancelledException : public StorageException | ||
664 | 131 | { | ||
665 | 132 | public: | ||
666 | 133 | CancelledException(std::string const& error_message); | ||
667 | 134 | ~CancelledException(); | ||
668 | 135 | }; | ||
669 | 136 | |||
670 | 137 | /** | ||
671 | 138 | \brief Indicates incorrect use of the API, such as calling methods in the wrong order. | ||
672 | 139 | */ | ||
673 | 140 | class UNITY_STORAGE_EXPORT LogicException : public StorageException | ||
674 | 141 | { | ||
675 | 142 | public: | ||
676 | 143 | LogicException(std::string const& error_message); | ||
677 | 144 | ~LogicException(); | ||
678 | 145 | }; | ||
679 | 146 | |||
680 | 147 | /** | ||
681 | 148 | \brief Indicates an invalid parameter, such as a negative value when a positive one was | ||
682 | 149 | expected, or a string that does not parse correctly or is empty when it should be non-empty. | ||
683 | 150 | */ | ||
684 | 151 | class UNITY_STORAGE_EXPORT InvalidArgumentException : public StorageException | ||
685 | 152 | { | ||
686 | 153 | public: | ||
687 | 154 | InvalidArgumentException(std::string const& error_message); | ||
688 | 155 | ~InvalidArgumentException(); | ||
689 | 156 | }; | ||
690 | 157 | |||
691 | 158 | /** | ||
692 | 159 | \brief Indicates a system error, such as failure to create a file or folder, | ||
693 | 160 | or any other (usually non-recoverable) kind of error that should not arise during normal operation. | ||
694 | 161 | */ | ||
695 | 162 | class UNITY_STORAGE_EXPORT ResourceException : public StorageException | ||
696 | 163 | { | ||
697 | 164 | public: | ||
698 | 165 | ResourceException(std::string const& error_message, int error_code); | ||
699 | 166 | ~ResourceException(); | ||
700 | 167 | |||
701 | 168 | int error_code() const noexcept; | ||
702 | 169 | |||
703 | 170 | private: | ||
704 | 171 | int error_code_; | ||
705 | 172 | }; | ||
706 | 173 | |||
707 | 174 | /** | ||
708 | 175 | \brief Indicates that the server side caught an exception that does not derive from | ||
709 | 176 | StorageException, such as a std::exception, or caught some other unknown type (such as `int`). | ||
710 | 177 | */ | ||
711 | 178 | class UNITY_STORAGE_EXPORT UnknownException : public StorageException | ||
712 | 179 | { | ||
713 | 180 | public: | ||
714 | 181 | UnknownException(std::string const& error_message); | ||
715 | 182 | ~UnknownException(); | ||
716 | 183 | }; | ||
717 | 184 | |||
718 | 185 | } // namespace provider | ||
719 | 186 | } // namespace storage | ||
720 | 187 | } // namespace unity | ||
721 | 0 | 188 | ||
722 | === modified file 'include/unity/storage/provider/ProviderBase.h' | |||
723 | --- include/unity/storage/provider/ProviderBase.h 2016-07-14 00:17:14 +0000 | |||
724 | +++ include/unity/storage/provider/ProviderBase.h 2016-09-09 02:13:43 +0000 | |||
725 | @@ -23,6 +23,7 @@ | |||
726 | 23 | #include <unity/storage/provider/Credentials.h> | 23 | #include <unity/storage/provider/Credentials.h> |
727 | 24 | 24 | ||
728 | 25 | #include <boost/thread/future.hpp> | 25 | #include <boost/thread/future.hpp> |
729 | 26 | #include <boost/variant.hpp> | ||
730 | 26 | 27 | ||
731 | 27 | #include <sys/types.h> | 28 | #include <sys/types.h> |
732 | 28 | #include <string> | 29 | #include <string> |
733 | @@ -48,15 +49,18 @@ | |||
734 | 48 | Credentials credentials; | 49 | Credentials credentials; |
735 | 49 | }; | 50 | }; |
736 | 50 | 51 | ||
737 | 52 | // Note: When growing the set of supported variant types, add new types | ||
738 | 53 | // to the *end* of the list, and update the marshaling code in dbusmarshal.cpp. | ||
739 | 54 | typedef boost::variant<std::string, int64_t> MetadataValue; | ||
740 | 55 | |||
741 | 51 | struct UNITY_STORAGE_EXPORT Item | 56 | struct UNITY_STORAGE_EXPORT Item |
742 | 52 | { | 57 | { |
743 | 53 | std::string item_id; | 58 | std::string item_id; |
745 | 54 | std::string parent_id; | 59 | std::vector<std::string> parent_ids; |
746 | 55 | std::string name; | 60 | std::string name; |
747 | 56 | std::string etag; | 61 | std::string etag; |
748 | 57 | unity::storage::ItemType type; | 62 | unity::storage::ItemType type; |
751 | 58 | // Should be map<string,variant> | 63 | std::map<std::string, MetadataValue> metadata; |
750 | 59 | std::map<std::string,std::string> metadata; | ||
752 | 60 | }; | 64 | }; |
753 | 61 | 65 | ||
754 | 62 | typedef std::vector<Item> ItemList; | 66 | typedef std::vector<Item> ItemList; |
755 | 63 | 67 | ||
756 | === modified file 'include/unity/storage/provider/TempfileUploadJob.h' | |||
757 | --- include/unity/storage/provider/TempfileUploadJob.h 2016-07-12 02:22:05 +0000 | |||
758 | +++ include/unity/storage/provider/TempfileUploadJob.h 2016-09-09 02:13:43 +0000 | |||
759 | @@ -44,6 +44,12 @@ | |||
760 | 44 | 44 | ||
761 | 45 | std::string file_name() const; | 45 | std::string file_name() const; |
762 | 46 | 46 | ||
763 | 47 | // This function should be called from your finish() | ||
764 | 48 | // implementation to read the remaining data from the socket. If | ||
765 | 49 | // the client has not closed the socket as expected, LogicError | ||
766 | 50 | // will be thrown. | ||
767 | 51 | void drain(); | ||
768 | 52 | |||
769 | 47 | protected: | 53 | protected: |
770 | 48 | TempfileUploadJob(internal::TempfileUploadJobImpl *p) UNITY_STORAGE_HIDDEN; | 54 | TempfileUploadJob(internal::TempfileUploadJobImpl *p) UNITY_STORAGE_HIDDEN; |
771 | 49 | }; | 55 | }; |
772 | 50 | 56 | ||
773 | === modified file 'include/unity/storage/provider/internal/AccountData.h' | |||
774 | --- include/unity/storage/provider/internal/AccountData.h 2016-07-12 02:22:05 +0000 | |||
775 | +++ include/unity/storage/provider/internal/AccountData.h 2016-09-09 02:13:43 +0000 | |||
776 | @@ -20,10 +20,15 @@ | |||
777 | 20 | 20 | ||
778 | 21 | #include <unity/storage/provider/Credentials.h> | 21 | #include <unity/storage/provider/Credentials.h> |
779 | 22 | 22 | ||
780 | 23 | #pragma GCC diagnostic push | ||
781 | 24 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
782 | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
783 | 26 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
784 | 23 | #include <OnlineAccounts/Account> | 27 | #include <OnlineAccounts/Account> |
785 | 24 | #include <OnlineAccounts/PendingCallWatcher> | 28 | #include <OnlineAccounts/PendingCallWatcher> |
786 | 25 | #include <QObject> | 29 | #include <QObject> |
787 | 26 | #include <QDBusConnection> | 30 | #include <QDBusConnection> |
788 | 31 | #pragma GCC diagnostic pop | ||
789 | 27 | 32 | ||
790 | 28 | #include <string> | 33 | #include <string> |
791 | 29 | 34 | ||
792 | 30 | 35 | ||
793 | === modified file 'include/unity/storage/provider/internal/DBusPeerCache.h' | |||
794 | --- include/unity/storage/provider/internal/DBusPeerCache.h 2016-07-12 02:22:05 +0000 | |||
795 | +++ include/unity/storage/provider/internal/DBusPeerCache.h 2016-09-09 02:13:43 +0000 | |||
796 | @@ -20,8 +20,13 @@ | |||
797 | 20 | #pragma once | 20 | #pragma once |
798 | 21 | 21 | ||
799 | 22 | #include <boost/thread/future.hpp> | 22 | #include <boost/thread/future.hpp> |
800 | 23 | #pragma GCC diagnostic push | ||
801 | 24 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
802 | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
803 | 26 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
804 | 23 | #include <QDBusConnection> | 27 | #include <QDBusConnection> |
805 | 24 | #include <QDBusPendingReply> | 28 | #include <QDBusPendingReply> |
806 | 29 | #pragma GCC diagnostic pop | ||
807 | 25 | #include <QString> | 30 | #include <QString> |
808 | 26 | 31 | ||
809 | 27 | #include <functional> | 32 | #include <functional> |
810 | 28 | 33 | ||
811 | === modified file 'include/unity/storage/provider/internal/DownloadJobImpl.h' | |||
812 | --- include/unity/storage/provider/internal/DownloadJobImpl.h 2016-07-12 02:22:05 +0000 | |||
813 | +++ include/unity/storage/provider/internal/DownloadJobImpl.h 2016-09-09 02:13:43 +0000 | |||
814 | @@ -48,9 +48,6 @@ | |||
815 | 48 | int write_socket() const; | 48 | int write_socket() const; |
816 | 49 | int take_read_socket(); | 49 | int take_read_socket(); |
817 | 50 | 50 | ||
818 | 51 | std::string const& sender_bus_name() const; | ||
819 | 52 | void set_sender_bus_name(std::string const& bus_name); | ||
820 | 53 | |||
821 | 54 | void report_complete(); | 51 | void report_complete(); |
822 | 55 | void report_error(std::exception_ptr p); | 52 | void report_error(std::exception_ptr p); |
823 | 56 | boost::future<void> finish(DownloadJob& job); | 53 | boost::future<void> finish(DownloadJob& job); |
824 | @@ -63,7 +60,6 @@ | |||
825 | 63 | std::string const download_id_; | 60 | std::string const download_id_; |
826 | 64 | int read_socket_ = -1; | 61 | int read_socket_ = -1; |
827 | 65 | int write_socket_ = -1; | 62 | int write_socket_ = -1; |
828 | 66 | std::string sender_bus_name_; | ||
829 | 67 | 63 | ||
830 | 68 | std::mutex completion_lock_; | 64 | std::mutex completion_lock_; |
831 | 69 | bool completed_ = false; | 65 | bool completed_ = false; |
832 | 70 | 66 | ||
833 | === modified file 'include/unity/storage/provider/internal/Handler.h' | |||
834 | --- include/unity/storage/provider/internal/Handler.h 2016-07-19 07:08:50 +0000 | |||
835 | +++ include/unity/storage/provider/internal/Handler.h 2016-09-09 02:13:43 +0000 | |||
836 | @@ -63,6 +63,8 @@ | |||
837 | 63 | void finished(); | 63 | void finished(); |
838 | 64 | 64 | ||
839 | 65 | private: | 65 | private: |
840 | 66 | void marshal_exception(std::exception_ptr ep); | ||
841 | 67 | |||
842 | 66 | std::shared_ptr<AccountData> const account_; | 68 | std::shared_ptr<AccountData> const account_; |
843 | 67 | Callback const callback_; | 69 | Callback const callback_; |
844 | 68 | QDBusConnection const bus_; | 70 | QDBusConnection const bus_; |
845 | 69 | 71 | ||
846 | === modified file 'include/unity/storage/provider/internal/MainLoopExecutor.h' | |||
847 | --- include/unity/storage/provider/internal/MainLoopExecutor.h 2016-07-19 03:26:36 +0000 | |||
848 | +++ include/unity/storage/provider/internal/MainLoopExecutor.h 2016-09-09 02:13:43 +0000 | |||
849 | @@ -19,13 +19,7 @@ | |||
850 | 19 | #pragma once | 19 | #pragma once |
851 | 20 | 20 | ||
852 | 21 | #include <boost/version.hpp> | 21 | #include <boost/version.hpp> |
860 | 22 | 22 | #include <boost/thread/executor.hpp> | |
854 | 23 | #if BOOST_VERSION >= 105600 | ||
855 | 24 | # define SF_SUPPORTS_EXECUTORS | ||
856 | 25 | #endif | ||
857 | 26 | #ifdef SF_SUPPORTS_EXECUTORS | ||
858 | 27 | # include <boost/thread/executor.hpp> | ||
859 | 28 | #endif | ||
861 | 29 | #include <QObject> | 23 | #include <QObject> |
862 | 30 | 24 | ||
863 | 31 | #include <functional> | 25 | #include <functional> |
864 | @@ -39,8 +33,6 @@ | |||
865 | 39 | namespace internal | 33 | namespace internal |
866 | 40 | { | 34 | { |
867 | 41 | 35 | ||
868 | 42 | #ifdef SF_SUPPORTS_EXECUTORS | ||
869 | 43 | |||
870 | 44 | /* Declare future continuations like so to execute within the event | 36 | /* Declare future continuations like so to execute within the event |
871 | 45 | * loop if possible: | 37 | * loop if possible: |
872 | 46 | * | 38 | * |
873 | @@ -72,12 +64,6 @@ | |||
874 | 72 | Q_DISABLE_COPY(MainLoopExecutor) | 64 | Q_DISABLE_COPY(MainLoopExecutor) |
875 | 73 | }; | 65 | }; |
876 | 74 | 66 | ||
877 | 75 | #else | ||
878 | 76 | |||
879 | 77 | #define EXEC_IN_MAIN /*nothing*/ | ||
880 | 78 | |||
881 | 79 | #endif | ||
882 | 80 | |||
883 | 81 | } | 67 | } |
884 | 82 | } | 68 | } |
885 | 83 | } | 69 | } |
886 | 84 | 70 | ||
887 | === modified file 'include/unity/storage/provider/internal/PendingJobs.h' | |||
888 | --- include/unity/storage/provider/internal/PendingJobs.h 2016-07-12 02:22:05 +0000 | |||
889 | +++ include/unity/storage/provider/internal/PendingJobs.h 2016-09-09 02:13:43 +0000 | |||
890 | @@ -18,14 +18,21 @@ | |||
891 | 18 | 18 | ||
892 | 19 | #pragma once | 19 | #pragma once |
893 | 20 | 20 | ||
894 | 21 | #pragma GCC diagnostic push | ||
895 | 22 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
896 | 23 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
897 | 24 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
898 | 21 | #include <QDBusConnection> | 25 | #include <QDBusConnection> |
899 | 22 | #include <QDBusServiceWatcher> | 26 | #include <QDBusServiceWatcher> |
900 | 23 | #include <QObject> | 27 | #include <QObject> |
901 | 28 | #include <QString> | ||
902 | 29 | #pragma GCC diagnostic pop | ||
903 | 24 | 30 | ||
904 | 25 | #include <map> | 31 | #include <map> |
905 | 26 | #include <memory> | 32 | #include <memory> |
906 | 27 | #include <mutex> | 33 | #include <mutex> |
907 | 28 | #include <string> | 34 | #include <string> |
908 | 35 | #include <utility> | ||
909 | 29 | 36 | ||
910 | 30 | namespace unity | 37 | namespace unity |
911 | 31 | { | 38 | { |
912 | @@ -49,27 +56,30 @@ | |||
913 | 49 | explicit PendingJobs(QDBusConnection const& bus, QObject *parent=nullptr); | 56 | explicit PendingJobs(QDBusConnection const& bus, QObject *parent=nullptr); |
914 | 50 | virtual ~PendingJobs(); | 57 | virtual ~PendingJobs(); |
915 | 51 | 58 | ||
919 | 52 | void add_download(std::unique_ptr<DownloadJob> &&job); | 59 | void add_download(QString const& client_bus_name, std::unique_ptr<DownloadJob> &&job); |
920 | 53 | std::shared_ptr<DownloadJob> get_download(std::string const& download_id); | 60 | std::shared_ptr<DownloadJob> remove_download(QString const& client_bus_name, std::string const& download_id); |
918 | 54 | std::shared_ptr<DownloadJob> remove_download(std::string const& download_id); | ||
921 | 55 | 61 | ||
925 | 56 | void add_upload(std::unique_ptr<UploadJob> &&job); | 62 | void add_upload(QString const& client_bus_name, std::unique_ptr<UploadJob> &&job); |
926 | 57 | std::shared_ptr<UploadJob> get_upload(std::string const& upload_id); | 63 | std::shared_ptr<UploadJob> remove_upload(QString const& client_bus_name, std::string const& upload_id); |
924 | 58 | std::shared_ptr<UploadJob> remove_upload(std::string const& upload_id); | ||
927 | 59 | 64 | ||
928 | 60 | private Q_SLOTS: | 65 | private Q_SLOTS: |
929 | 61 | void service_disconnected(QString const& service_name); | 66 | void service_disconnected(QString const& service_name); |
930 | 62 | 67 | ||
931 | 63 | private: | 68 | private: |
934 | 64 | void watch_peer(std::string const& bus_name); | 69 | void watch_peer(QString const& bus_name); |
935 | 65 | void unwatch_peer(std::string const& bus_name); | 70 | void unwatch_peer(QString const& bus_name); |
936 | 71 | |||
937 | 72 | template <typename Job> | ||
938 | 73 | void cancel_job(std::shared_ptr<Job> const& job, | ||
939 | 74 | std::string const& identifier); | ||
940 | 66 | 75 | ||
941 | 67 | std::mutex lock_; | 76 | std::mutex lock_; |
944 | 68 | std::map<std::string,std::shared_ptr<UploadJob>> uploads_; | 77 | // Key is client_bus_name and upload or download ID. |
945 | 69 | std::map<std::string,std::shared_ptr<DownloadJob>> downloads_; | 78 | std::map<std::pair<QString,std::string>,std::shared_ptr<UploadJob>> uploads_; |
946 | 79 | std::map<std::pair<QString,std::string>,std::shared_ptr<DownloadJob>> downloads_; | ||
947 | 70 | 80 | ||
948 | 71 | QDBusServiceWatcher watcher_; | 81 | QDBusServiceWatcher watcher_; |
950 | 72 | std::map<std::string,int> services_; | 82 | std::map<QString,int> services_; |
951 | 73 | 83 | ||
952 | 74 | Q_DISABLE_COPY(PendingJobs) | 84 | Q_DISABLE_COPY(PendingJobs) |
953 | 75 | }; | 85 | }; |
954 | 76 | 86 | ||
955 | === modified file 'include/unity/storage/provider/internal/ProviderInterface.h' | |||
956 | --- include/unity/storage/provider/internal/ProviderInterface.h 2016-07-14 00:17:14 +0000 | |||
957 | +++ include/unity/storage/provider/internal/ProviderInterface.h 2016-09-09 02:13:43 +0000 | |||
958 | @@ -21,11 +21,16 @@ | |||
959 | 21 | #include <unity/storage/internal/ItemMetadata.h> | 21 | #include <unity/storage/internal/ItemMetadata.h> |
960 | 22 | #include <unity/storage/provider/internal/Handler.h> | 22 | #include <unity/storage/provider/internal/Handler.h> |
961 | 23 | 23 | ||
962 | 24 | #pragma GCC diagnostic push | ||
963 | 25 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
964 | 26 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
965 | 27 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
966 | 24 | #include <QObject> | 28 | #include <QObject> |
967 | 25 | #include <QList> | 29 | #include <QList> |
968 | 26 | #include <QDBusConnection> | 30 | #include <QDBusConnection> |
969 | 27 | #include <QDBusContext> | 31 | #include <QDBusContext> |
970 | 28 | #include <QDBusUnixFileDescriptor> | 32 | #include <QDBusUnixFileDescriptor> |
971 | 33 | #pragma GCC diagnostic pop | ||
972 | 29 | 34 | ||
973 | 30 | #include <map> | 35 | #include <map> |
974 | 31 | #include <memory> | 36 | #include <memory> |
975 | 32 | 37 | ||
976 | === modified file 'include/unity/storage/provider/internal/ServerImpl.h' | |||
977 | --- include/unity/storage/provider/internal/ServerImpl.h 2016-07-12 02:22:05 +0000 | |||
978 | +++ include/unity/storage/provider/internal/ServerImpl.h 2016-09-09 02:13:43 +0000 | |||
979 | @@ -19,6 +19,7 @@ | |||
980 | 19 | #pragma once | 19 | #pragma once |
981 | 20 | 20 | ||
982 | 21 | #include <unity/storage/provider/Server.h> | 21 | #include <unity/storage/provider/Server.h> |
983 | 22 | #include <unity/storage/internal/TraceMessageHandler.h> | ||
984 | 22 | #include <unity/storage/provider/internal/DBusPeerCache.h> | 23 | #include <unity/storage/provider/internal/DBusPeerCache.h> |
985 | 23 | #include <unity/storage/provider/internal/ProviderInterface.h> | 24 | #include <unity/storage/provider/internal/ProviderInterface.h> |
986 | 24 | 25 | ||
987 | @@ -58,6 +59,7 @@ | |||
988 | 58 | ServerBase* const server_; | 59 | ServerBase* const server_; |
989 | 59 | std::string const bus_name_; | 60 | std::string const bus_name_; |
990 | 60 | std::string const service_id_; | 61 | std::string const service_id_; |
991 | 62 | unity::storage::internal::TraceMessageHandler trace_message_handler_; | ||
992 | 61 | 63 | ||
993 | 62 | std::unique_ptr<QCoreApplication> app_; | 64 | std::unique_ptr<QCoreApplication> app_; |
994 | 63 | std::unique_ptr<OnlineAccounts::Manager> manager_; | 65 | std::unique_ptr<OnlineAccounts::Manager> manager_; |
995 | 64 | 66 | ||
996 | === modified file 'include/unity/storage/provider/internal/TempfileUploadJobImpl.h' | |||
997 | --- include/unity/storage/provider/internal/TempfileUploadJobImpl.h 2016-07-12 02:22:05 +0000 | |||
998 | +++ include/unity/storage/provider/internal/TempfileUploadJobImpl.h 2016-09-09 02:13:43 +0000 | |||
999 | @@ -20,8 +20,12 @@ | |||
1000 | 20 | 20 | ||
1001 | 21 | #include <unity/storage/provider/internal/UploadJobImpl.h> | 21 | #include <unity/storage/provider/internal/UploadJobImpl.h> |
1002 | 22 | 22 | ||
1003 | 23 | #pragma GCC diagnostic push | ||
1004 | 24 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
1005 | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
1006 | 23 | #include <QLocalSocket> | 26 | #include <QLocalSocket> |
1007 | 24 | #include <QTemporaryFile> | 27 | #include <QTemporaryFile> |
1008 | 28 | #pragma GCC diagnostic pop | ||
1009 | 25 | 29 | ||
1010 | 26 | #include <memory> | 30 | #include <memory> |
1011 | 27 | #include <string> | 31 | #include <string> |
1012 | @@ -43,6 +47,7 @@ | |||
1013 | 43 | virtual ~TempfileUploadJobImpl(); | 47 | virtual ~TempfileUploadJobImpl(); |
1014 | 44 | 48 | ||
1015 | 45 | void complete_init() override; | 49 | void complete_init() override; |
1016 | 50 | void drain(); | ||
1017 | 46 | 51 | ||
1018 | 47 | std::string file_name() const; | 52 | std::string file_name() const; |
1019 | 48 | 53 | ||
1020 | @@ -51,8 +56,8 @@ | |||
1021 | 51 | void on_read_channel_finished(); | 56 | void on_read_channel_finished(); |
1022 | 52 | 57 | ||
1023 | 53 | private: | 58 | private: |
1024 | 59 | std::unique_ptr<QTemporaryFile> tmpfile_; | ||
1025 | 54 | std::unique_ptr<QLocalSocket> reader_; | 60 | std::unique_ptr<QLocalSocket> reader_; |
1026 | 55 | std::unique_ptr<QTemporaryFile> tmpfile_; | ||
1027 | 56 | 61 | ||
1028 | 57 | Q_DISABLE_COPY(TempfileUploadJobImpl) | 62 | Q_DISABLE_COPY(TempfileUploadJobImpl) |
1029 | 58 | }; | 63 | }; |
1030 | 59 | 64 | ||
1031 | === added file 'include/unity/storage/provider/internal/TestServerImpl.h' | |||
1032 | --- include/unity/storage/provider/internal/TestServerImpl.h 1970-01-01 00:00:00 +0000 | |||
1033 | +++ include/unity/storage/provider/internal/TestServerImpl.h 2016-09-09 02:13:43 +0000 | |||
1034 | @@ -0,0 +1,65 @@ | |||
1035 | 1 | /* | ||
1036 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
1037 | 3 | * | ||
1038 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1039 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
1040 | 6 | * published by the Free Software Foundation. | ||
1041 | 7 | * | ||
1042 | 8 | * This program is distributed in the hope that it will be useful, | ||
1043 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1044 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1045 | 11 | * GNU Lesser General Public License for more details. | ||
1046 | 12 | * | ||
1047 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1048 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1049 | 15 | * | ||
1050 | 16 | * Authors: James Henstridge <james.henstridge@canonical.com> | ||
1051 | 17 | */ | ||
1052 | 18 | |||
1053 | 19 | #pragma once | ||
1054 | 20 | |||
1055 | 21 | #include <unity/storage/provider/testing/TestServer.h> | ||
1056 | 22 | |||
1057 | 23 | #pragma GCC diagnostic push | ||
1058 | 24 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
1059 | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
1060 | 26 | #include <QDBusConnection> | ||
1061 | 27 | #pragma GCC diagnostic pop | ||
1062 | 28 | |||
1063 | 29 | #include <memory> | ||
1064 | 30 | #include <string> | ||
1065 | 31 | |||
1066 | 32 | namespace unity | ||
1067 | 33 | { | ||
1068 | 34 | namespace storage | ||
1069 | 35 | { | ||
1070 | 36 | namespace provider | ||
1071 | 37 | { | ||
1072 | 38 | namespace internal | ||
1073 | 39 | { | ||
1074 | 40 | |||
1075 | 41 | class ProviderInterface; | ||
1076 | 42 | |||
1077 | 43 | class TestServerImpl | ||
1078 | 44 | { | ||
1079 | 45 | public: | ||
1080 | 46 | TestServerImpl(std::unique_ptr<ProviderBase>&& provider, | ||
1081 | 47 | OnlineAccounts::Account* account, | ||
1082 | 48 | QDBusConnection const& connection, | ||
1083 | 49 | std::string const& object_path); | ||
1084 | 50 | ~TestServerImpl(); | ||
1085 | 51 | |||
1086 | 52 | QDBusConnection const& connection() const; | ||
1087 | 53 | std::string const& object_path() const; | ||
1088 | 54 | |||
1089 | 55 | private: | ||
1090 | 56 | QDBusConnection connection_; | ||
1091 | 57 | std::string const object_path_; | ||
1092 | 58 | |||
1093 | 59 | std::unique_ptr<ProviderInterface> interface_; | ||
1094 | 60 | }; | ||
1095 | 61 | |||
1096 | 62 | } | ||
1097 | 63 | } | ||
1098 | 64 | } | ||
1099 | 65 | } | ||
1100 | 0 | 66 | ||
1101 | === modified file 'include/unity/storage/provider/internal/UploadJobImpl.h' | |||
1102 | --- include/unity/storage/provider/internal/UploadJobImpl.h 2016-07-12 02:22:05 +0000 | |||
1103 | +++ include/unity/storage/provider/internal/UploadJobImpl.h 2016-09-09 02:13:43 +0000 | |||
1104 | @@ -21,7 +21,11 @@ | |||
1105 | 21 | #include <unity/storage/provider/ProviderBase.h> | 21 | #include <unity/storage/provider/ProviderBase.h> |
1106 | 22 | 22 | ||
1107 | 23 | #include <boost/thread/future.hpp> | 23 | #include <boost/thread/future.hpp> |
1108 | 24 | #pragma GCC diagnostic push | ||
1109 | 25 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
1110 | 26 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
1111 | 24 | #include <QObject> | 27 | #include <QObject> |
1112 | 28 | #pragma GCC diagnostic pop | ||
1113 | 25 | 29 | ||
1114 | 26 | #include <exception> | 30 | #include <exception> |
1115 | 27 | #include <mutex> | 31 | #include <mutex> |
1116 | @@ -49,9 +53,6 @@ | |||
1117 | 49 | int read_socket() const; | 53 | int read_socket() const; |
1118 | 50 | int take_write_socket(); | 54 | int take_write_socket(); |
1119 | 51 | 55 | ||
1120 | 52 | std::string const& sender_bus_name() const; | ||
1121 | 53 | void set_sender_bus_name(std::string const& bus_name); | ||
1122 | 54 | |||
1123 | 55 | void report_error(std::exception_ptr p); | 56 | void report_error(std::exception_ptr p); |
1124 | 56 | boost::future<Item> finish(UploadJob& job); | 57 | boost::future<Item> finish(UploadJob& job); |
1125 | 57 | boost::future<void> cancel(UploadJob& job); | 58 | boost::future<void> cancel(UploadJob& job); |
1126 | @@ -63,7 +64,6 @@ | |||
1127 | 63 | std::string const upload_id_; | 64 | std::string const upload_id_; |
1128 | 64 | int read_socket_ = -1; | 65 | int read_socket_ = -1; |
1129 | 65 | int write_socket_ = -1; | 66 | int write_socket_ = -1; |
1130 | 66 | std::string sender_bus_name_; | ||
1131 | 67 | 67 | ||
1132 | 68 | std::mutex completion_lock_; | 68 | std::mutex completion_lock_; |
1133 | 69 | bool completed_ = false; | 69 | bool completed_ = false; |
1134 | 70 | 70 | ||
1135 | === modified file 'include/unity/storage/provider/internal/dbusmarshal.h' | |||
1136 | --- include/unity/storage/provider/internal/dbusmarshal.h 2016-07-12 02:22:05 +0000 | |||
1137 | +++ include/unity/storage/provider/internal/dbusmarshal.h 2016-09-09 02:13:43 +0000 | |||
1138 | @@ -18,8 +18,15 @@ | |||
1139 | 18 | 18 | ||
1140 | 19 | #pragma once | 19 | #pragma once |
1141 | 20 | 20 | ||
1142 | 21 | #include <unity/storage/provider/ProviderBase.h> | ||
1143 | 22 | |||
1144 | 23 | #pragma GCC diagnostic push | ||
1145 | 24 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
1146 | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
1147 | 21 | #include <QDBusArgument> | 26 | #include <QDBusArgument> |
1148 | 22 | #include <QVariant> | 27 | #include <QVariant> |
1149 | 28 | #pragma GCC diagnostic pop | ||
1150 | 29 | |||
1151 | 23 | #include <vector> | 30 | #include <vector> |
1152 | 24 | 31 | ||
1153 | 25 | namespace unity | 32 | namespace unity |
1154 | 26 | 33 | ||
1155 | === renamed file 'include/unity/storage/internal/MetadataKeys.h' => 'include/unity/storage/provider/metadata_keys.h' | |||
1156 | --- include/unity/storage/internal/MetadataKeys.h 2016-07-14 00:25:40 +0000 | |||
1157 | +++ include/unity/storage/provider/metadata_keys.h 2016-09-09 02:13:43 +0000 | |||
1158 | @@ -18,15 +18,28 @@ | |||
1159 | 18 | 18 | ||
1160 | 19 | #pragma once | 19 | #pragma once |
1161 | 20 | 20 | ||
1162 | 21 | #include <unordered_map> | ||
1163 | 22 | |||
1164 | 21 | namespace unity | 23 | namespace unity |
1165 | 22 | { | 24 | { |
1166 | 23 | namespace storage | 25 | namespace storage |
1167 | 24 | { | 26 | { |
1174 | 25 | namespace internal | 27 | namespace provider |
1175 | 26 | { | 28 | { |
1176 | 27 | 29 | ||
1177 | 28 | static char constexpr CREATION_TIME[] = "creation_time"; | 30 | static char constexpr SIZE_IN_BYTES[] = "size_in_bytes"; // int64_t, >= 0 |
1178 | 29 | 31 | static char constexpr CREATION_TIME[] = "creation_time"; // String, ISO 8601 format | |
1179 | 30 | } // namespace internal | 32 | static char constexpr LAST_MODIFIED_TIME[] = "last_modified_time"; // String, ISO 8601 format |
1180 | 33 | |||
1181 | 34 | enum class MetadataType { int64, iso_8601_date_time }; | ||
1182 | 35 | |||
1183 | 36 | static std::unordered_map<std::string, MetadataType> known_metadata = | ||
1184 | 37 | { | ||
1185 | 38 | { SIZE_IN_BYTES, MetadataType::int64 }, | ||
1186 | 39 | { CREATION_TIME, MetadataType::iso_8601_date_time }, | ||
1187 | 40 | { LAST_MODIFIED_TIME, MetadataType::iso_8601_date_time } | ||
1188 | 41 | }; | ||
1189 | 42 | |||
1190 | 43 | } // namespace provider | ||
1191 | 31 | } // namespace storage | 44 | } // namespace storage |
1192 | 32 | } // namespace unity | 45 | } // namespace unity |
1193 | 33 | 46 | ||
1194 | === added directory 'include/unity/storage/provider/testing' | |||
1195 | === added file 'include/unity/storage/provider/testing/CMakeLists.txt' | |||
1196 | --- include/unity/storage/provider/testing/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1197 | +++ include/unity/storage/provider/testing/CMakeLists.txt 2016-09-09 02:13:43 +0000 | |||
1198 | @@ -0,0 +1,5 @@ | |||
1199 | 1 | set(includeprefix unity/storage/provider/testing) | ||
1200 | 2 | file(GLOB provider_headers *.h) | ||
1201 | 3 | |||
1202 | 4 | install(FILES ${provider_headers} | ||
1203 | 5 | DESTINATION ${provider_base_includedir}/${includeprefix}) | ||
1204 | 0 | 6 | ||
1205 | === added file 'include/unity/storage/provider/testing/TestServer.h' | |||
1206 | --- include/unity/storage/provider/testing/TestServer.h 1970-01-01 00:00:00 +0000 | |||
1207 | +++ include/unity/storage/provider/testing/TestServer.h 2016-09-09 02:13:43 +0000 | |||
1208 | @@ -0,0 +1,68 @@ | |||
1209 | 1 | /* | ||
1210 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
1211 | 3 | * | ||
1212 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1213 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
1214 | 6 | * published by the Free Software Foundation. | ||
1215 | 7 | * | ||
1216 | 8 | * This program is distributed in the hope that it will be useful, | ||
1217 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1218 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1219 | 11 | * GNU Lesser General Public License for more details. | ||
1220 | 12 | * | ||
1221 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1222 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1223 | 15 | * | ||
1224 | 16 | * Authors: James Henstridge <james.henstridge@canonical.com> | ||
1225 | 17 | */ | ||
1226 | 18 | |||
1227 | 19 | #pragma once | ||
1228 | 20 | |||
1229 | 21 | #include <unity/storage/visibility.h> | ||
1230 | 22 | |||
1231 | 23 | #include <memory> | ||
1232 | 24 | #include <string> | ||
1233 | 25 | |||
1234 | 26 | namespace OnlineAccounts | ||
1235 | 27 | { | ||
1236 | 28 | class Account; | ||
1237 | 29 | } | ||
1238 | 30 | class QDBusConnection; | ||
1239 | 31 | |||
1240 | 32 | namespace unity | ||
1241 | 33 | { | ||
1242 | 34 | namespace storage | ||
1243 | 35 | { | ||
1244 | 36 | namespace provider | ||
1245 | 37 | { | ||
1246 | 38 | |||
1247 | 39 | class ProviderBase; | ||
1248 | 40 | |||
1249 | 41 | namespace internal | ||
1250 | 42 | { | ||
1251 | 43 | class TestServerImpl; | ||
1252 | 44 | } | ||
1253 | 45 | |||
1254 | 46 | namespace testing | ||
1255 | 47 | { | ||
1256 | 48 | |||
1257 | 49 | class UNITY_STORAGE_EXPORT TestServer | ||
1258 | 50 | { | ||
1259 | 51 | public: | ||
1260 | 52 | TestServer(std::unique_ptr<ProviderBase>&& provider, | ||
1261 | 53 | OnlineAccounts::Account* account, | ||
1262 | 54 | QDBusConnection const& connection, | ||
1263 | 55 | std::string const& object_path); | ||
1264 | 56 | ~TestServer(); | ||
1265 | 57 | |||
1266 | 58 | QDBusConnection const& connection() const; | ||
1267 | 59 | std::string const& object_path() const; | ||
1268 | 60 | |||
1269 | 61 | private: | ||
1270 | 62 | std::unique_ptr<internal::TestServerImpl> p_; | ||
1271 | 63 | }; | ||
1272 | 64 | |||
1273 | 65 | } | ||
1274 | 66 | } | ||
1275 | 67 | } | ||
1276 | 68 | } | ||
1277 | 0 | 69 | ||
1278 | === modified file 'include/unity/storage/qt/client/Account.h' | |||
1279 | --- include/unity/storage/qt/client/Account.h 2016-07-22 02:35:12 +0000 | |||
1280 | +++ include/unity/storage/qt/client/Account.h 2016-09-09 02:13:43 +0000 | |||
1281 | @@ -77,7 +77,7 @@ | |||
1282 | 77 | 77 | ||
1283 | 78 | typedef std::shared_ptr<Account> SPtr; | 78 | typedef std::shared_ptr<Account> SPtr; |
1284 | 79 | 79 | ||
1286 | 80 | Runtime* runtime() const; | 80 | std::shared_ptr<Runtime> runtime() const; |
1287 | 81 | 81 | ||
1288 | 82 | QString owner() const; | 82 | QString owner() const; |
1289 | 83 | QString owner_id() const; | 83 | QString owner_id() const; |
1290 | 84 | 84 | ||
1291 | === modified file 'include/unity/storage/qt/client/Exceptions.h' | |||
1292 | --- include/unity/storage/qt/client/Exceptions.h 2016-07-22 02:35:12 +0000 | |||
1293 | +++ include/unity/storage/qt/client/Exceptions.h 2016-09-09 02:13:43 +0000 | |||
1294 | @@ -20,7 +20,10 @@ | |||
1295 | 20 | 20 | ||
1296 | 21 | #include <unity/storage/visibility.h> | 21 | #include <unity/storage/visibility.h> |
1297 | 22 | 22 | ||
1298 | 23 | #pragma GCC diagnostic push | ||
1299 | 24 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
1300 | 23 | #include <QException> | 25 | #include <QException> |
1301 | 26 | #pragma GCC diagnostic pop | ||
1302 | 24 | #include <QString> | 27 | #include <QString> |
1303 | 25 | 28 | ||
1304 | 26 | namespace unity | 29 | namespace unity |
1305 | @@ -46,6 +49,8 @@ | |||
1306 | 46 | 49 | ||
1307 | 47 | virtual char const* what() const noexcept override; | 50 | virtual char const* what() const noexcept override; |
1308 | 48 | 51 | ||
1309 | 52 | QString error_message() const; | ||
1310 | 53 | |||
1311 | 49 | private: | 54 | private: |
1312 | 50 | std::string what_string_; | 55 | std::string what_string_; |
1313 | 51 | QString error_message_; | 56 | QString error_message_; |
1314 | @@ -83,18 +88,16 @@ | |||
1315 | 83 | class UNITY_STORAGE_EXPORT DeletedException : public StorageException | 88 | class UNITY_STORAGE_EXPORT DeletedException : public StorageException |
1316 | 84 | { | 89 | { |
1317 | 85 | public: | 90 | public: |
1319 | 86 | DeletedException(QString const& error_message, QString const& identity_, QString const& name_); | 91 | DeletedException(QString const& error_message, QString const& identity_); |
1320 | 87 | ~DeletedException(); | 92 | ~DeletedException(); |
1321 | 88 | 93 | ||
1322 | 89 | virtual DeletedException* clone() const override; | 94 | virtual DeletedException* clone() const override; |
1323 | 90 | virtual void raise() const override; | 95 | virtual void raise() const override; |
1324 | 91 | 96 | ||
1325 | 92 | QString native_identity() const; | 97 | QString native_identity() const; |
1326 | 93 | QString name() const; | ||
1327 | 94 | 98 | ||
1328 | 95 | private: | 99 | private: |
1329 | 96 | QString identity_; | 100 | QString identity_; |
1330 | 97 | QString name_; | ||
1331 | 98 | }; | 101 | }; |
1332 | 99 | 102 | ||
1333 | 100 | /** | 103 | /** |
1334 | @@ -228,17 +231,22 @@ | |||
1335 | 228 | }; | 231 | }; |
1336 | 229 | 232 | ||
1337 | 230 | /** | 233 | /** |
1339 | 231 | \brief Indicates a system error, such as failure to to create a file or folder, | 234 | \brief Indicates a system error, such as failure to create a file or folder, |
1340 | 232 | or any other (usually non-recoverable) kind of error that should not arise during normal operation. | 235 | or any other (usually non-recoverable) kind of error that should not arise during normal operation. |
1341 | 233 | */ | 236 | */ |
1342 | 234 | class UNITY_STORAGE_EXPORT ResourceException : public StorageException | 237 | class UNITY_STORAGE_EXPORT ResourceException : public StorageException |
1343 | 235 | { | 238 | { |
1344 | 236 | public: | 239 | public: |
1346 | 237 | ResourceException(QString const& error_message); | 240 | ResourceException(QString const& error_message, int error_code); |
1347 | 238 | ~ResourceException(); | 241 | ~ResourceException(); |
1348 | 239 | 242 | ||
1349 | 240 | virtual ResourceException* clone() const override; | 243 | virtual ResourceException* clone() const override; |
1350 | 241 | virtual void raise() const override; | 244 | virtual void raise() const override; |
1351 | 245 | |||
1352 | 246 | int error_code() const noexcept; | ||
1353 | 247 | |||
1354 | 248 | private: | ||
1355 | 249 | int error_code_; | ||
1356 | 242 | }; | 250 | }; |
1357 | 243 | 251 | ||
1358 | 244 | } // namespace client | 252 | } // namespace client |
1359 | 245 | 253 | ||
1360 | === modified file 'include/unity/storage/qt/client/Item.h' | |||
1361 | --- include/unity/storage/qt/client/Item.h 2016-07-22 02:45:24 +0000 | |||
1362 | +++ include/unity/storage/qt/client/Item.h 2016-09-09 02:13:43 +0000 | |||
1363 | @@ -103,7 +103,7 @@ | |||
1364 | 103 | 103 | ||
1365 | 104 | If this item is a root, the returned pointer points at this item. | 104 | If this item is a root, the returned pointer points at this item. |
1366 | 105 | */ | 105 | */ |
1368 | 106 | Root* root() const; | 106 | std::shared_ptr<Root> root() const; |
1369 | 107 | 107 | ||
1370 | 108 | /** | 108 | /** |
1371 | 109 | \brief Returns the type of the item. | 109 | \brief Returns the type of the item. |
1372 | 110 | 110 | ||
1373 | === modified file 'include/unity/storage/qt/client/Root.h' | |||
1374 | --- include/unity/storage/qt/client/Root.h 2016-07-12 02:22:05 +0000 | |||
1375 | +++ include/unity/storage/qt/client/Root.h 2016-09-09 02:13:43 +0000 | |||
1376 | @@ -70,7 +70,7 @@ | |||
1377 | 70 | /** | 70 | /** |
1378 | 71 | \brief Returns the account for this root. | 71 | \brief Returns the account for this root. |
1379 | 72 | */ | 72 | */ |
1381 | 73 | Account* account() const; | 73 | std::shared_ptr<Account> account() const; |
1382 | 74 | 74 | ||
1383 | 75 | QFuture<int64_t> free_space_bytes() const; | 75 | QFuture<int64_t> free_space_bytes() const; |
1384 | 76 | QFuture<int64_t> used_space_bytes() const; | 76 | QFuture<int64_t> used_space_bytes() const; |
1385 | 77 | 77 | ||
1386 | === modified file 'include/unity/storage/qt/client/Runtime.h' | |||
1387 | --- include/unity/storage/qt/client/Runtime.h 2016-07-22 02:35:12 +0000 | |||
1388 | +++ include/unity/storage/qt/client/Runtime.h 2016-09-09 02:13:43 +0000 | |||
1389 | @@ -44,6 +44,7 @@ | |||
1390 | 44 | namespace internal | 44 | namespace internal |
1391 | 45 | { | 45 | { |
1392 | 46 | 46 | ||
1393 | 47 | class AccountBase; | ||
1394 | 47 | class RuntimeBase; | 48 | class RuntimeBase; |
1395 | 48 | 49 | ||
1396 | 49 | namespace remote_client | 50 | namespace remote_client |
1397 | @@ -95,11 +96,23 @@ | |||
1398 | 95 | 96 | ||
1399 | 96 | QFuture<QVector<std::shared_ptr<Account>>> accounts(); | 97 | QFuture<QVector<std::shared_ptr<Account>>> accounts(); |
1400 | 97 | 98 | ||
1401 | 99 | /// @cond | ||
1402 | 100 | /** | ||
1403 | 101 | \brief Creates an Account object pointing at (bus_name, object_path) | ||
1404 | 102 | |||
1405 | 103 | This method is intended for use in tests, where you want to talk | ||
1406 | 104 | to a provider that has already been set up on the bus. | ||
1407 | 105 | */ | ||
1408 | 106 | std::shared_ptr<Account> make_test_account(QString const& bus_name, | ||
1409 | 107 | QString const& object_path); | ||
1410 | 108 | /// @endcond | ||
1411 | 109 | |||
1412 | 98 | private: | 110 | private: |
1413 | 99 | Runtime(internal::RuntimeBase* p) UNITY_STORAGE_HIDDEN; | 111 | Runtime(internal::RuntimeBase* p) UNITY_STORAGE_HIDDEN; |
1414 | 100 | 112 | ||
1415 | 101 | std::shared_ptr<internal::RuntimeBase> p_; | 113 | std::shared_ptr<internal::RuntimeBase> p_; |
1416 | 102 | 114 | ||
1417 | 115 | friend class internal::AccountBase; | ||
1418 | 103 | friend class internal::remote_client::AccountImpl; | 116 | friend class internal::remote_client::AccountImpl; |
1419 | 104 | }; | 117 | }; |
1420 | 105 | 118 | ||
1421 | 106 | 119 | ||
1422 | === modified file 'include/unity/storage/qt/client/Uploader.h' | |||
1423 | --- include/unity/storage/qt/client/Uploader.h 2016-07-22 02:35:12 +0000 | |||
1424 | +++ include/unity/storage/qt/client/Uploader.h 2016-09-09 02:13:43 +0000 | |||
1425 | @@ -92,6 +92,14 @@ | |||
1426 | 92 | std::shared_ptr<QLocalSocket> socket() const; | 92 | std::shared_ptr<QLocalSocket> socket() const; |
1427 | 93 | 93 | ||
1428 | 94 | /** | 94 | /** |
1429 | 95 | \brief Returns the size that was passed to Folder::create_file() or File::create_uploader(). | ||
1430 | 96 | |||
1431 | 97 | \return The number of bytes that the uploader expects to be written to the `QLocalSocket` returned | ||
1432 | 98 | from socket(). | ||
1433 | 99 | */ | ||
1434 | 100 | int64_t size() const; | ||
1435 | 101 | |||
1436 | 102 | /** | ||
1437 | 95 | \brief Finalizes the upload. | 103 | \brief Finalizes the upload. |
1438 | 96 | 104 | ||
1439 | 97 | Once you have written the file contents to the socket returned by socket(), you must call finish_upload(), | 105 | Once you have written the file contents to the socket returned by socket(), you must call finish_upload(), |
1440 | 98 | 106 | ||
1441 | === modified file 'include/unity/storage/qt/client/internal/AccountBase.h' | |||
1442 | --- include/unity/storage/qt/client/internal/AccountBase.h 2016-07-22 02:35:12 +0000 | |||
1443 | +++ include/unity/storage/qt/client/internal/AccountBase.h 2016-09-09 02:13:43 +0000 | |||
1444 | @@ -52,7 +52,7 @@ | |||
1445 | 52 | AccountBase(AccountBase const&) = delete; | 52 | AccountBase(AccountBase const&) = delete; |
1446 | 53 | AccountBase& operator=(AccountBase const&) = delete; | 53 | AccountBase& operator=(AccountBase const&) = delete; |
1447 | 54 | 54 | ||
1449 | 55 | Runtime* runtime() const; | 55 | std::shared_ptr<Runtime> runtime() const; |
1450 | 56 | virtual QString owner() const = 0; | 56 | virtual QString owner() const = 0; |
1451 | 57 | virtual QString owner_id() const = 0; | 57 | virtual QString owner_id() const = 0; |
1452 | 58 | virtual QString description() const = 0; | 58 | virtual QString description() const = 0; |
1453 | 59 | 59 | ||
1454 | === modified file 'include/unity/storage/qt/client/internal/ItemBase.h' | |||
1455 | --- include/unity/storage/qt/client/internal/ItemBase.h 2016-07-27 02:19:17 +0000 | |||
1456 | +++ include/unity/storage/qt/client/internal/ItemBase.h 2016-09-09 02:13:43 +0000 | |||
1457 | @@ -20,10 +20,10 @@ | |||
1458 | 20 | 20 | ||
1459 | 21 | #include <unity/storage/common.h> | 21 | #include <unity/storage/common.h> |
1460 | 22 | 22 | ||
1461 | 23 | #include <QDateTime> | ||
1462 | 24 | #pragma GCC diagnostic push | 23 | #pragma GCC diagnostic push |
1463 | 25 | #pragma GCC diagnostic ignored "-Wcast-align" | 24 | #pragma GCC diagnostic ignored "-Wcast-align" |
1464 | 26 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" |
1465 | 26 | #include <QDateTime> | ||
1466 | 27 | #include <QFuture> | 27 | #include <QFuture> |
1467 | 28 | #pragma GCC diagnostic pop | 28 | #pragma GCC diagnostic pop |
1468 | 29 | #include <QVariantMap> | 29 | #include <QVariantMap> |
1469 | @@ -60,7 +60,7 @@ | |||
1470 | 60 | 60 | ||
1471 | 61 | QString native_identity() const; | 61 | QString native_identity() const; |
1472 | 62 | ItemType type() const; | 62 | ItemType type() const; |
1474 | 63 | Root* root() const; | 63 | std::shared_ptr<Root> root() const; |
1475 | 64 | 64 | ||
1476 | 65 | virtual QString name() const = 0; | 65 | virtual QString name() const = 0; |
1477 | 66 | virtual QString etag() const = 0; | 66 | virtual QString etag() const = 0; |
1478 | @@ -82,10 +82,14 @@ | |||
1479 | 82 | void set_public_instance(std::weak_ptr<Item> p); | 82 | void set_public_instance(std::weak_ptr<Item> p); |
1480 | 83 | 83 | ||
1481 | 84 | protected: | 84 | protected: |
1482 | 85 | std::shared_ptr<Root> get_root() const noexcept; | ||
1483 | 86 | void throw_if_destroyed(QString const& method) const; | ||
1484 | 87 | |||
1485 | 85 | const QString identity_; | 88 | const QString identity_; |
1486 | 86 | const ItemType type_; | 89 | const ItemType type_; |
1487 | 87 | std::weak_ptr<Root> root_; | 90 | std::weak_ptr<Root> root_; |
1488 | 88 | std::weak_ptr<Item> public_instance_; | 91 | std::weak_ptr<Item> public_instance_; |
1489 | 92 | bool deleted_ = false; | ||
1490 | 89 | 93 | ||
1491 | 90 | friend class ItemImpl; | 94 | friend class ItemImpl; |
1492 | 91 | }; | 95 | }; |
1493 | 92 | 96 | ||
1494 | === modified file 'include/unity/storage/qt/client/internal/RootBase.h' | |||
1495 | --- include/unity/storage/qt/client/internal/RootBase.h 2016-07-12 02:22:05 +0000 | |||
1496 | +++ include/unity/storage/qt/client/internal/RootBase.h 2016-09-09 02:13:43 +0000 | |||
1497 | @@ -46,7 +46,7 @@ | |||
1498 | 46 | public: | 46 | public: |
1499 | 47 | RootBase(QString const& identity, std::weak_ptr<Account> const& account); | 47 | RootBase(QString const& identity, std::weak_ptr<Account> const& account); |
1500 | 48 | 48 | ||
1502 | 49 | Account* account() const; | 49 | std::shared_ptr<Account> account() const; |
1503 | 50 | virtual QFuture<int64_t> free_space_bytes() const = 0; | 50 | virtual QFuture<int64_t> free_space_bytes() const = 0; |
1504 | 51 | virtual QFuture<int64_t> used_space_bytes() const = 0; | 51 | virtual QFuture<int64_t> used_space_bytes() const = 0; |
1505 | 52 | virtual QFuture<Item::SPtr> get(QString native_identity) const = 0; | 52 | virtual QFuture<Item::SPtr> get(QString native_identity) const = 0; |
1506 | 53 | 53 | ||
1507 | === modified file 'include/unity/storage/qt/client/internal/RuntimeBase.h' | |||
1508 | --- include/unity/storage/qt/client/internal/RuntimeBase.h 2016-07-22 02:35:12 +0000 | |||
1509 | +++ include/unity/storage/qt/client/internal/RuntimeBase.h 2016-09-09 02:13:43 +0000 | |||
1510 | @@ -25,7 +25,6 @@ | |||
1511 | 25 | #pragma GCC diagnostic pop | 25 | #pragma GCC diagnostic pop |
1512 | 26 | #include <QVector> | 26 | #include <QVector> |
1513 | 27 | 27 | ||
1514 | 28 | #include <atomic> | ||
1515 | 29 | #include <memory> | 28 | #include <memory> |
1516 | 30 | 29 | ||
1517 | 31 | namespace unity | 30 | namespace unity |
1518 | @@ -43,23 +42,29 @@ | |||
1519 | 43 | namespace internal | 42 | namespace internal |
1520 | 44 | { | 43 | { |
1521 | 45 | 44 | ||
1522 | 45 | class AccountBase; | ||
1523 | 46 | |||
1524 | 46 | class RuntimeBase : public QObject | 47 | class RuntimeBase : public QObject |
1525 | 47 | { | 48 | { |
1526 | 48 | public: | 49 | public: |
1528 | 49 | RuntimeBase(); | 50 | RuntimeBase() = default; |
1529 | 50 | virtual ~RuntimeBase() = default; | 51 | virtual ~RuntimeBase() = default; |
1530 | 51 | RuntimeBase(RuntimeBase const&) = delete; | 52 | RuntimeBase(RuntimeBase const&) = delete; |
1531 | 52 | RuntimeBase& operator=(RuntimeBase const&) = delete; | 53 | RuntimeBase& operator=(RuntimeBase const&) = delete; |
1532 | 53 | 54 | ||
1533 | 54 | virtual void shutdown() = 0; | 55 | virtual void shutdown() = 0; |
1534 | 55 | virtual QFuture<QVector<std::shared_ptr<Account>>> accounts() = 0; | 56 | virtual QFuture<QVector<std::shared_ptr<Account>>> accounts() = 0; |
1535 | 57 | virtual std::shared_ptr<Account> make_test_account(QString const& bus_name, | ||
1536 | 58 | QString const& object_path) = 0; | ||
1537 | 56 | 59 | ||
1538 | 57 | void set_public_instance(std::weak_ptr<Runtime> p); | 60 | void set_public_instance(std::weak_ptr<Runtime> p); |
1539 | 58 | 61 | ||
1540 | 59 | protected: | 62 | protected: |
1543 | 60 | std::atomic_bool destroyed_; | 63 | bool destroyed_ = false; |
1544 | 61 | QVector<std::shared_ptr<Account>> accounts_; // Immutable once set | 64 | QVector<std::shared_ptr<Account>> accounts_; |
1545 | 62 | std::weak_ptr<Runtime> public_instance_; // Immutable once set | 65 | std::weak_ptr<Runtime> public_instance_; // Immutable once set |
1546 | 66 | |||
1547 | 67 | friend class unity::storage::qt::client::internal::AccountBase; | ||
1548 | 63 | }; | 68 | }; |
1549 | 64 | 69 | ||
1550 | 65 | } // namespace internal | 70 | } // namespace internal |
1551 | 66 | 71 | ||
1552 | === modified file 'include/unity/storage/qt/client/internal/UploaderBase.h' | |||
1553 | --- include/unity/storage/qt/client/internal/UploaderBase.h 2016-07-22 02:35:12 +0000 | |||
1554 | +++ include/unity/storage/qt/client/internal/UploaderBase.h 2016-09-09 02:13:43 +0000 | |||
1555 | @@ -47,7 +47,7 @@ | |||
1556 | 47 | class UploaderBase : public QObject | 47 | class UploaderBase : public QObject |
1557 | 48 | { | 48 | { |
1558 | 49 | public: | 49 | public: |
1560 | 50 | UploaderBase(ConflictPolicy policy); | 50 | UploaderBase(ConflictPolicy policy, int64_t size); |
1561 | 51 | UploaderBase(UploaderBase&) = delete; | 51 | UploaderBase(UploaderBase&) = delete; |
1562 | 52 | UploaderBase& operator=(UploaderBase const&) = delete; | 52 | UploaderBase& operator=(UploaderBase const&) = delete; |
1563 | 53 | 53 | ||
1564 | @@ -55,8 +55,11 @@ | |||
1565 | 55 | virtual QFuture<std::shared_ptr<File>> finish_upload() = 0; | 55 | virtual QFuture<std::shared_ptr<File>> finish_upload() = 0; |
1566 | 56 | virtual QFuture<void> cancel() noexcept = 0; | 56 | virtual QFuture<void> cancel() noexcept = 0; |
1567 | 57 | 57 | ||
1568 | 58 | int64_t size() const; | ||
1569 | 59 | |||
1570 | 58 | protected: | 60 | protected: |
1571 | 59 | ConflictPolicy policy_; | 61 | ConflictPolicy policy_; |
1572 | 62 | int64_t size_; | ||
1573 | 60 | }; | 63 | }; |
1574 | 61 | 64 | ||
1575 | 62 | } // namespace internal | 65 | } // namespace internal |
1576 | 63 | 66 | ||
1577 | === modified file 'include/unity/storage/qt/client/internal/local_client/DownloaderImpl.h' | |||
1578 | --- include/unity/storage/qt/client/internal/local_client/DownloaderImpl.h 2016-07-14 04:50:36 +0000 | |||
1579 | +++ include/unity/storage/qt/client/internal/local_client/DownloaderImpl.h 2016-09-09 02:13:43 +0000 | |||
1580 | @@ -60,7 +60,7 @@ | |||
1581 | 60 | 60 | ||
1582 | 61 | private: | 61 | private: |
1583 | 62 | void read_and_write_chunk(); | 62 | void read_and_write_chunk(); |
1585 | 63 | void handle_error(QString const& msg); | 63 | void handle_error(QString const& msg, int error_code); |
1586 | 64 | 64 | ||
1587 | 65 | enum State { in_progress, finalized, cancelled, error }; | 65 | enum State { in_progress, finalized, cancelled, error }; |
1588 | 66 | 66 | ||
1589 | @@ -73,6 +73,7 @@ | |||
1590 | 73 | QFutureInterface<void>& worker_initialized_; | 73 | QFutureInterface<void>& worker_initialized_; |
1591 | 74 | qint64 bytes_to_write_; | 74 | qint64 bytes_to_write_; |
1592 | 75 | QString error_msg_; | 75 | QString error_msg_; |
1593 | 76 | int error_code_ = 0; | ||
1594 | 76 | }; | 77 | }; |
1595 | 77 | 78 | ||
1596 | 78 | class DownloadThread : public QThread | 79 | class DownloadThread : public QThread |
1597 | 79 | 80 | ||
1598 | === modified file 'include/unity/storage/qt/client/internal/local_client/FolderImpl.h' | |||
1599 | --- include/unity/storage/qt/client/internal/local_client/FolderImpl.h 2016-07-14 00:17:14 +0000 | |||
1600 | +++ include/unity/storage/qt/client/internal/local_client/FolderImpl.h 2016-09-09 02:13:43 +0000 | |||
1601 | @@ -40,6 +40,7 @@ | |||
1602 | 40 | FolderImpl(QString const& identity); | 40 | FolderImpl(QString const& identity); |
1603 | 41 | FolderImpl(QString const& identity, ItemType type); | 41 | FolderImpl(QString const& identity, ItemType type); |
1604 | 42 | 42 | ||
1605 | 43 | virtual QString name() const override; | ||
1606 | 43 | QFuture<QVector<std::shared_ptr<Item>>> list() const override; | 44 | QFuture<QVector<std::shared_ptr<Item>>> list() const override; |
1607 | 44 | QFuture<QVector<std::shared_ptr<Item>>> lookup(QString const& name) const override; | 45 | QFuture<QVector<std::shared_ptr<Item>>> lookup(QString const& name) const override; |
1608 | 45 | QFuture<std::shared_ptr<Folder>> create_folder(QString const& name) override; | 46 | QFuture<std::shared_ptr<Folder>> create_folder(QString const& name) override; |
1609 | 46 | 47 | ||
1610 | === modified file 'include/unity/storage/qt/client/internal/local_client/ItemImpl.h' | |||
1611 | --- include/unity/storage/qt/client/internal/local_client/ItemImpl.h 2016-07-27 02:19:17 +0000 | |||
1612 | +++ include/unity/storage/qt/client/internal/local_client/ItemImpl.h 2016-09-09 02:13:43 +0000 | |||
1613 | @@ -47,7 +47,6 @@ | |||
1614 | 47 | ItemImpl(QString const& identity, ItemType type); | 47 | ItemImpl(QString const& identity, ItemType type); |
1615 | 48 | virtual ~ItemImpl(); | 48 | virtual ~ItemImpl(); |
1616 | 49 | 49 | ||
1617 | 50 | virtual QString name() const override; | ||
1618 | 51 | virtual QString etag() const override; | 50 | virtual QString etag() const override; |
1619 | 52 | virtual QVariantMap metadata() const override; | 51 | virtual QVariantMap metadata() const override; |
1620 | 53 | virtual QDateTime last_modified_time() const override; | 52 | virtual QDateTime last_modified_time() const override; |
1621 | @@ -65,20 +64,18 @@ | |||
1622 | 65 | void set_timestamps() noexcept; | 64 | void set_timestamps() noexcept; |
1623 | 66 | bool has_conflict() const noexcept; | 65 | bool has_conflict() const noexcept; |
1624 | 67 | 66 | ||
1625 | 68 | std::unique_lock<std::mutex> get_lock(); | ||
1626 | 69 | |||
1627 | 70 | protected: | 67 | protected: |
1628 | 71 | static boost::filesystem::path sanitize(QString const& name, QString const& method); | 68 | static boost::filesystem::path sanitize(QString const& name, QString const& method); |
1629 | 72 | static bool is_reserved_path(boost::filesystem::path const& path) noexcept; | 69 | static bool is_reserved_path(boost::filesystem::path const& path) noexcept; |
1630 | 73 | 70 | ||
1631 | 74 | DeletedException deleted_ex(QString const& method) const noexcept; | ||
1632 | 75 | |||
1633 | 76 | bool deleted_; | ||
1634 | 77 | QString name_; | 71 | QString name_; |
1635 | 78 | QString etag_; | 72 | QString etag_; |
1636 | 79 | QDateTime modified_time_; | 73 | QDateTime modified_time_; |
1637 | 80 | QVariantMap metadata_; | 74 | QVariantMap metadata_; |
1639 | 81 | std::mutex mutable mutex_; | 75 | std::recursive_mutex mutable mutex_; |
1640 | 76 | |||
1641 | 77 | private: | ||
1642 | 78 | static void copy_recursively(boost::filesystem::path const& source, boost::filesystem::path const& target); | ||
1643 | 82 | }; | 79 | }; |
1644 | 83 | 80 | ||
1645 | 84 | } // namespace local_client | 81 | } // namespace local_client |
1646 | 85 | 82 | ||
1647 | === modified file 'include/unity/storage/qt/client/internal/local_client/RuntimeImpl.h' | |||
1648 | --- include/unity/storage/qt/client/internal/local_client/RuntimeImpl.h 2016-07-12 02:22:05 +0000 | |||
1649 | +++ include/unity/storage/qt/client/internal/local_client/RuntimeImpl.h 2016-09-09 02:13:43 +0000 | |||
1650 | @@ -41,6 +41,8 @@ | |||
1651 | 41 | 41 | ||
1652 | 42 | virtual void shutdown() override; | 42 | virtual void shutdown() override; |
1653 | 43 | virtual QFuture<QVector<std::shared_ptr<Account>>> accounts() override; | 43 | virtual QFuture<QVector<std::shared_ptr<Account>>> accounts() override; |
1654 | 44 | virtual std::shared_ptr<Account> make_test_account(QString const& bus_name, | ||
1655 | 45 | QString const& object_path) override; | ||
1656 | 44 | }; | 46 | }; |
1657 | 45 | 47 | ||
1658 | 46 | } // namespace local_client | 48 | } // namespace local_client |
1659 | 47 | 49 | ||
1660 | === modified file 'include/unity/storage/qt/client/internal/local_client/UploaderImpl.h' | |||
1661 | --- include/unity/storage/qt/client/internal/local_client/UploaderImpl.h 2016-07-26 01:51:26 +0000 | |||
1662 | +++ include/unity/storage/qt/client/internal/local_client/UploaderImpl.h 2016-09-09 02:13:43 +0000 | |||
1663 | @@ -68,12 +68,11 @@ | |||
1664 | 68 | private Q_SLOTS: | 68 | private Q_SLOTS: |
1665 | 69 | void on_bytes_ready(); | 69 | void on_bytes_ready(); |
1666 | 70 | void on_read_channel_finished(); | 70 | void on_read_channel_finished(); |
1667 | 71 | void on_error(); | ||
1668 | 72 | 71 | ||
1669 | 73 | private: | 72 | private: |
1670 | 74 | void read_and_write_chunk(); | 73 | void read_and_write_chunk(); |
1671 | 75 | void finalize(); | 74 | void finalize(); |
1673 | 76 | void handle_error(QString const& msg); | 75 | void handle_error(QString const& msg, int error_code); |
1674 | 77 | 76 | ||
1675 | 78 | enum State { in_progress, finalized, cancelled, error }; | 77 | enum State { in_progress, finalized, cancelled, error }; |
1676 | 79 | 78 | ||
1677 | @@ -91,6 +90,7 @@ | |||
1678 | 91 | QFutureInterface<std::shared_ptr<File>>& qf_; | 90 | QFutureInterface<std::shared_ptr<File>>& qf_; |
1679 | 92 | QFutureInterface<void>& worker_initialized_; | 91 | QFutureInterface<void>& worker_initialized_; |
1680 | 93 | QString error_msg_; | 92 | QString error_msg_; |
1681 | 93 | int error_code_ = 0; | ||
1682 | 94 | bool use_linkat_ = true; | 94 | bool use_linkat_ = true; |
1683 | 95 | }; | 95 | }; |
1684 | 96 | 96 | ||
1685 | 97 | 97 | ||
1686 | === added file 'include/unity/storage/qt/client/internal/local_client/storage_exception.h' | |||
1687 | --- include/unity/storage/qt/client/internal/local_client/storage_exception.h 1970-01-01 00:00:00 +0000 | |||
1688 | +++ include/unity/storage/qt/client/internal/local_client/storage_exception.h 2016-09-09 02:13:43 +0000 | |||
1689 | @@ -0,0 +1,94 @@ | |||
1690 | 1 | /* | ||
1691 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
1692 | 3 | * | ||
1693 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1694 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
1695 | 6 | * published by the Free Software Foundation. | ||
1696 | 7 | * | ||
1697 | 8 | * This program is distributed in the hope that it will be useful, | ||
1698 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1699 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1700 | 11 | * GNU Lesser General Public License for more details. | ||
1701 | 12 | * | ||
1702 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1703 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1704 | 15 | * | ||
1705 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
1706 | 17 | */ | ||
1707 | 18 | |||
1708 | 19 | #pragma once | ||
1709 | 20 | |||
1710 | 21 | #include <unity/storage/qt/client/Exceptions.h> | ||
1711 | 22 | #include <unity/storage/qt/client/internal/local_client/boost_filesystem.h> | ||
1712 | 23 | |||
1713 | 24 | #pragma GCC diagnostic push | ||
1714 | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
1715 | 26 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
1716 | 27 | #include <QFuture> | ||
1717 | 28 | #pragma GCC diagnostic pop | ||
1718 | 29 | #include <QFutureInterface> | ||
1719 | 30 | |||
1720 | 31 | class QString; | ||
1721 | 32 | |||
1722 | 33 | namespace unity | ||
1723 | 34 | { | ||
1724 | 35 | namespace storage | ||
1725 | 36 | { | ||
1726 | 37 | namespace qt | ||
1727 | 38 | { | ||
1728 | 39 | namespace client | ||
1729 | 40 | { | ||
1730 | 41 | namespace internal | ||
1731 | 42 | { | ||
1732 | 43 | namespace local_client | ||
1733 | 44 | { | ||
1734 | 45 | |||
1735 | 46 | void throw_storage_exception(QString const& method, | ||
1736 | 47 | std::exception_ptr ep) __attribute__ ((noreturn)); | ||
1737 | 48 | |||
1738 | 49 | void throw_storage_exception(QString const& method, | ||
1739 | 50 | std::exception_ptr ep, | ||
1740 | 51 | QString const& key) __attribute__ ((noreturn)); | ||
1741 | 52 | |||
1742 | 53 | template<typename T> | ||
1743 | 54 | QFuture<T> make_exceptional_future(QString const& method, std::exception_ptr ep) | ||
1744 | 55 | { | ||
1745 | 56 | try | ||
1746 | 57 | { | ||
1747 | 58 | throw_storage_exception(method, ep); | ||
1748 | 59 | } | ||
1749 | 60 | catch (StorageException const& e) | ||
1750 | 61 | { | ||
1751 | 62 | QFutureInterface<T> qf; | ||
1752 | 63 | qf.reportException(e); | ||
1753 | 64 | qf.reportFinished(); | ||
1754 | 65 | return qf.future(); | ||
1755 | 66 | } | ||
1756 | 67 | abort(); // Impossible. // LCOV_EXCL_LINE | ||
1757 | 68 | } | ||
1758 | 69 | |||
1759 | 70 | template<typename T> | ||
1760 | 71 | QFuture<T> make_exceptional_future(QString const& method, | ||
1761 | 72 | std::exception_ptr ep, | ||
1762 | 73 | QString const& key) | ||
1763 | 74 | { | ||
1764 | 75 | try | ||
1765 | 76 | { | ||
1766 | 77 | throw_storage_exception(method, ep, key); | ||
1767 | 78 | } | ||
1768 | 79 | catch (StorageException const& e) | ||
1769 | 80 | { | ||
1770 | 81 | QFutureInterface<T> qf; | ||
1771 | 82 | qf.reportException(e); | ||
1772 | 83 | qf.reportFinished(); | ||
1773 | 84 | return qf.future(); | ||
1774 | 85 | } | ||
1775 | 86 | abort(); // Impossible. // LCOV_EXCL_LINE | ||
1776 | 87 | } | ||
1777 | 88 | |||
1778 | 89 | } // namespace local_client | ||
1779 | 90 | } // namespace internal | ||
1780 | 91 | } // namespace client | ||
1781 | 92 | } // namespace qt | ||
1782 | 93 | } // namespace storage | ||
1783 | 94 | } // namespace unity | ||
1784 | 0 | 95 | ||
1785 | === renamed file 'include/unity/storage/qt/client/internal/local_client/tmpfile-prefix.h' => 'include/unity/storage/qt/client/internal/local_client/tmpfile_prefix.h' | |||
1786 | === modified file 'include/unity/storage/qt/client/internal/make_future.h' | |||
1787 | --- include/unity/storage/qt/client/internal/make_future.h 2016-07-22 02:35:12 +0000 | |||
1788 | +++ include/unity/storage/qt/client/internal/make_future.h 2016-09-09 02:13:43 +0000 | |||
1789 | @@ -36,40 +36,30 @@ | |||
1790 | 36 | namespace internal | 36 | namespace internal |
1791 | 37 | { | 37 | { |
1792 | 38 | 38 | ||
1793 | 39 | template<typename T> | ||
1794 | 40 | QFuture<T> | ||
1795 | 41 | __attribute__ ((warn_unused_result)) | ||
1796 | 42 | make_ready_future(T const& val) | ||
1797 | 43 | { | ||
1798 | 44 | QFutureInterface<T> qf; | ||
1799 | 45 | qf.reportResult(val); | ||
1800 | 46 | qf.reportFinished(); | ||
1801 | 47 | return qf.future(); | ||
1802 | 48 | } | ||
1803 | 49 | |||
1804 | 39 | template<typename T = void> | 50 | template<typename T = void> |
1806 | 40 | QFuture<T> make_ready_future() | 51 | QFuture<T> |
1807 | 52 | __attribute__ ((warn_unused_result)) | ||
1808 | 53 | make_ready_future() | ||
1809 | 41 | { | 54 | { |
1810 | 42 | QFutureInterface<void> qf; | 55 | QFutureInterface<void> qf; |
1837 | 43 | qf.reportFinished(); | 56 | return make_ready_future(qf); |
1812 | 44 | return qf.future(); | ||
1813 | 45 | } | ||
1814 | 46 | |||
1815 | 47 | template<typename T = void> | ||
1816 | 48 | QFuture<T> make_ready_future(QFutureInterface<T> qf) | ||
1817 | 49 | { | ||
1818 | 50 | qf.reportFinished(); | ||
1819 | 51 | return qf.future(); | ||
1820 | 52 | } | ||
1821 | 53 | |||
1822 | 54 | template<typename T> | ||
1823 | 55 | QFuture<T> make_ready_future(T const& val) | ||
1824 | 56 | { | ||
1825 | 57 | QFutureInterface<T> qf; | ||
1826 | 58 | qf.reportResult(val); | ||
1827 | 59 | qf.reportFinished(); | ||
1828 | 60 | return qf.future(); | ||
1829 | 61 | } | ||
1830 | 62 | |||
1831 | 63 | template<typename T> | ||
1832 | 64 | QFuture<T> make_ready_future(QFutureInterface<T> qf, T const& val) | ||
1833 | 65 | { | ||
1834 | 66 | qf.reportResult(val); | ||
1835 | 67 | qf.reportFinished(); | ||
1836 | 68 | return qf.future(); | ||
1838 | 69 | } | 57 | } |
1839 | 70 | 58 | ||
1840 | 71 | template<typename E> | 59 | template<typename E> |
1842 | 72 | QFuture<void> make_exceptional_future(E const& ex) | 60 | QFuture<void> |
1843 | 61 | __attribute__ | ||
1844 | 62 | ((warn_unused_result)) make_exceptional_future(E const& ex) | ||
1845 | 73 | { | 63 | { |
1846 | 74 | QFutureInterface<void> qf; | 64 | QFutureInterface<void> qf; |
1847 | 75 | qf.reportException(ex); | 65 | qf.reportException(ex); |
1848 | @@ -78,7 +68,9 @@ | |||
1849 | 78 | } | 68 | } |
1850 | 79 | 69 | ||
1851 | 80 | template<typename T, typename E> | 70 | template<typename T, typename E> |
1853 | 81 | QFuture<T> make_exceptional_future(E const& ex) | 71 | QFuture<T> |
1854 | 72 | __attribute__ ((warn_unused_result)) | ||
1855 | 73 | make_exceptional_future(E const& ex) | ||
1856 | 82 | { | 74 | { |
1857 | 83 | QFutureInterface<T> qf; | 75 | QFutureInterface<T> qf; |
1858 | 84 | qf.reportException(ex); | 76 | qf.reportException(ex); |
1859 | @@ -86,14 +78,6 @@ | |||
1860 | 86 | return qf.future(); | 78 | return qf.future(); |
1861 | 87 | } | 79 | } |
1862 | 88 | 80 | ||
1863 | 89 | template<typename T, typename E> | ||
1864 | 90 | QFuture<T> make_exceptional_future(QFutureInterface<T> qf, E const& ex) | ||
1865 | 91 | { | ||
1866 | 92 | qf.reportException(ex); | ||
1867 | 93 | qf.reportFinished(); | ||
1868 | 94 | return qf.future(); | ||
1869 | 95 | } | ||
1870 | 96 | |||
1871 | 97 | } // namespace internal | 81 | } // namespace internal |
1872 | 98 | } // namespace client | 82 | } // namespace client |
1873 | 99 | } // namespace qt | 83 | } // namespace qt |
1874 | 100 | 84 | ||
1875 | === modified file 'include/unity/storage/qt/client/internal/remote_client/AccountImpl.h' | |||
1876 | --- include/unity/storage/qt/client/internal/remote_client/AccountImpl.h 2016-07-15 03:56:14 +0000 | |||
1877 | +++ include/unity/storage/qt/client/internal/remote_client/AccountImpl.h 2016-09-09 02:13:43 +0000 | |||
1878 | @@ -39,7 +39,8 @@ | |||
1879 | 39 | { | 39 | { |
1880 | 40 | public: | 40 | public: |
1881 | 41 | AccountImpl(std::weak_ptr<Runtime> const& runtime, | 41 | AccountImpl(std::weak_ptr<Runtime> const& runtime, |
1883 | 42 | int account_id, | 42 | QString const& bus_name, |
1884 | 43 | QString const& object_path, | ||
1885 | 43 | QString const& owner, | 44 | QString const& owner, |
1886 | 44 | QString const& owner_id, | 45 | QString const& owner_id, |
1887 | 45 | QString const& description); | 46 | QString const& description); |
1888 | 46 | 47 | ||
1889 | === modified file 'include/unity/storage/qt/client/internal/remote_client/Handler.h' | |||
1890 | --- include/unity/storage/qt/client/internal/remote_client/Handler.h 2016-07-15 03:58:35 +0000 | |||
1891 | +++ include/unity/storage/qt/client/internal/remote_client/Handler.h 2016-09-09 02:13:43 +0000 | |||
1892 | @@ -20,10 +20,13 @@ | |||
1893 | 20 | 20 | ||
1894 | 21 | #include <unity/storage/qt/client/Exceptions.h> | 21 | #include <unity/storage/qt/client/Exceptions.h> |
1895 | 22 | #include <unity/storage/qt/client/internal/make_future.h> | 22 | #include <unity/storage/qt/client/internal/make_future.h> |
1896 | 23 | #include <unity/storage/qt/client/internal/remote_client/dbusmarshal.h> | ||
1897 | 23 | #include <unity/storage/qt/client/internal/remote_client/HandlerBase.h> | 24 | #include <unity/storage/qt/client/internal/remote_client/HandlerBase.h> |
1898 | 24 | 25 | ||
1899 | 25 | #include <QDBusPendingReply> | 26 | #include <QDBusPendingReply> |
1900 | 26 | 27 | ||
1901 | 28 | #include <cassert> | ||
1902 | 29 | |||
1903 | 27 | namespace unity | 30 | namespace unity |
1904 | 28 | { | 31 | { |
1905 | 29 | namespace storage | 32 | namespace storage |
1906 | @@ -72,8 +75,41 @@ | |||
1907 | 72 | { | 75 | { |
1908 | 73 | if (call.isError()) | 76 | if (call.isError()) |
1909 | 74 | { | 77 | { |
1912 | 75 | qDebug() << call.error().message(); // TODO, remove this | 78 | try |
1913 | 76 | make_exceptional_future<T>(ResourceException("DBus error return")); | 79 | { |
1914 | 80 | auto ep = unmarshal_exception(call); | ||
1915 | 81 | std::rethrow_exception(ep); | ||
1916 | 82 | } | ||
1917 | 83 | // We catch some exceptions that are "surprising" so we can log those. | ||
1918 | 84 | catch (LocalCommsException const& e) | ||
1919 | 85 | { | ||
1920 | 86 | qCritical() << "provider exception:" << e.what(); | ||
1921 | 87 | qf_.reportException(e); | ||
1922 | 88 | qf_.reportFinished(); | ||
1923 | 89 | } | ||
1924 | 90 | catch (RemoteCommsException const& e) | ||
1925 | 91 | { | ||
1926 | 92 | qCritical() << "provider exception:" << e.what(); | ||
1927 | 93 | qf_.reportException(e); | ||
1928 | 94 | qf_.reportFinished(); | ||
1929 | 95 | } | ||
1930 | 96 | catch (ResourceException const& e) | ||
1931 | 97 | { | ||
1932 | 98 | qCritical() << "provider exception:" << e.what(); | ||
1933 | 99 | qf_.reportException(e); | ||
1934 | 100 | qf_.reportFinished(); | ||
1935 | 101 | } | ||
1936 | 102 | catch (StorageException const& e) | ||
1937 | 103 | { | ||
1938 | 104 | qf_.reportException(e); | ||
1939 | 105 | qf_.reportFinished(); | ||
1940 | 106 | } | ||
1941 | 107 | // LCOV_EXCL_START | ||
1942 | 108 | catch (...) | ||
1943 | 109 | { | ||
1944 | 110 | abort(); // Impossible. | ||
1945 | 111 | } | ||
1946 | 112 | // LCOV_EXCL_STOP | ||
1947 | 77 | return; | 113 | return; |
1948 | 78 | } | 114 | } |
1949 | 79 | // TODO: See HACK above. Should just be closure(call, qf_); | 115 | // TODO: See HACK above. Should just be closure(call, qf_); |
1950 | 80 | 116 | ||
1951 | === modified file 'include/unity/storage/qt/client/internal/remote_client/ItemImpl.h' | |||
1952 | --- include/unity/storage/qt/client/internal/remote_client/ItemImpl.h 2016-07-22 00:17:24 +0000 | |||
1953 | +++ include/unity/storage/qt/client/internal/remote_client/ItemImpl.h 2016-09-09 02:13:43 +0000 | |||
1954 | @@ -66,9 +66,6 @@ | |||
1955 | 66 | static std::shared_ptr<Item> make_item(storage::internal::ItemMetadata const& md, std::weak_ptr<Root> root); | 66 | static std::shared_ptr<Item> make_item(storage::internal::ItemMetadata const& md, std::weak_ptr<Root> root); |
1956 | 67 | 67 | ||
1957 | 68 | protected: | 68 | protected: |
1958 | 69 | DeletedException deleted_ex(QString const& method) const noexcept; | ||
1959 | 70 | |||
1960 | 71 | bool deleted_ = false; | ||
1961 | 72 | storage::internal::ItemMetadata md_; | 69 | storage::internal::ItemMetadata md_; |
1962 | 73 | 70 | ||
1963 | 74 | friend class DeleteHandler; | 71 | friend class DeleteHandler; |
1964 | 75 | 72 | ||
1965 | === modified file 'include/unity/storage/qt/client/internal/remote_client/RuntimeImpl.h' | |||
1966 | --- include/unity/storage/qt/client/internal/remote_client/RuntimeImpl.h 2016-07-22 00:17:24 +0000 | |||
1967 | +++ include/unity/storage/qt/client/internal/remote_client/RuntimeImpl.h 2016-09-09 02:13:43 +0000 | |||
1968 | @@ -50,6 +50,8 @@ | |||
1969 | 50 | 50 | ||
1970 | 51 | virtual void shutdown() override; | 51 | virtual void shutdown() override; |
1971 | 52 | virtual QFuture<QVector<std::shared_ptr<Account>>> accounts() override; | 52 | virtual QFuture<QVector<std::shared_ptr<Account>>> accounts() override; |
1972 | 53 | virtual std::shared_ptr<Account> make_test_account(QString const& bus_name, | ||
1973 | 54 | QString const& object_path) override; | ||
1974 | 53 | 55 | ||
1975 | 54 | QDBusConnection& connection(); | 56 | QDBusConnection& connection(); |
1976 | 55 | 57 | ||
1977 | @@ -58,6 +60,12 @@ | |||
1978 | 58 | virtual void timeout(); | 60 | virtual void timeout(); |
1979 | 59 | 61 | ||
1980 | 60 | private: | 62 | private: |
1981 | 63 | std::shared_ptr<Account> make_account(QString const& bus_name, | ||
1982 | 64 | QString const& object_path, | ||
1983 | 65 | QString const& owner, | ||
1984 | 66 | QString const& owner_id, | ||
1985 | 67 | QString const& description); | ||
1986 | 68 | |||
1987 | 61 | QDBusConnection conn_; | 69 | QDBusConnection conn_; |
1988 | 62 | std::unique_ptr<OnlineAccounts::Manager> manager_; // TODO: Hack until we can use the registry | 70 | std::unique_ptr<OnlineAccounts::Manager> manager_; // TODO: Hack until we can use the registry |
1989 | 63 | QTimer timer_; | 71 | QTimer timer_; |
1990 | 64 | 72 | ||
1991 | === modified file 'include/unity/storage/qt/client/internal/remote_client/UploaderImpl.h' | |||
1992 | --- include/unity/storage/qt/client/internal/remote_client/UploaderImpl.h 2016-07-22 00:17:24 +0000 | |||
1993 | +++ include/unity/storage/qt/client/internal/remote_client/UploaderImpl.h 2016-09-09 02:13:43 +0000 | |||
1994 | @@ -65,13 +65,15 @@ | |||
1995 | 65 | std::shared_ptr<ProviderInterface> const& provider); | 65 | std::shared_ptr<ProviderInterface> const& provider); |
1996 | 66 | 66 | ||
1997 | 67 | private: | 67 | private: |
1998 | 68 | enum State { uploading, finalized }; | ||
1999 | 69 | |||
2000 | 68 | QString upload_id_; | 70 | QString upload_id_; |
2001 | 69 | QDBusUnixFileDescriptor fd_; | 71 | QDBusUnixFileDescriptor fd_; |
2002 | 70 | int64_t size_; | ||
2003 | 71 | QString old_etag_; | 72 | QString old_etag_; |
2005 | 72 | std::weak_ptr<Root> root_; | 73 | std::shared_ptr<Root> root_; |
2006 | 73 | std::shared_ptr<ProviderInterface> provider_; | 74 | std::shared_ptr<ProviderInterface> provider_; |
2007 | 74 | std::shared_ptr<QLocalSocket> write_socket_; | 75 | std::shared_ptr<QLocalSocket> write_socket_; |
2008 | 76 | State state_; | ||
2009 | 75 | }; | 77 | }; |
2010 | 76 | 78 | ||
2011 | 77 | } // namespace remote_client | 79 | } // namespace remote_client |
2012 | 78 | 80 | ||
2013 | === modified file 'include/unity/storage/qt/client/internal/remote_client/dbusmarshal.h' | |||
2014 | --- include/unity/storage/qt/client/internal/remote_client/dbusmarshal.h 2016-07-12 02:22:05 +0000 | |||
2015 | +++ include/unity/storage/qt/client/internal/remote_client/dbusmarshal.h 2016-09-09 02:13:43 +0000 | |||
2016 | @@ -18,29 +18,28 @@ | |||
2017 | 18 | 18 | ||
2018 | 19 | #pragma once | 19 | #pragma once |
2019 | 20 | 20 | ||
2021 | 21 | #include <unity/storage/internal/ItemMetadata.h> | 21 | #include <exception> |
2022 | 22 | 22 | ||
2026 | 23 | #include <QDBusArgument> | 23 | class QDBusPendingCallWatcher; |
2024 | 24 | #include <QMetaType> | ||
2025 | 25 | #include <QVariant> | ||
2027 | 26 | 24 | ||
2028 | 27 | namespace unity | 25 | namespace unity |
2029 | 28 | { | 26 | { |
2030 | 29 | namespace storage | 27 | namespace storage |
2031 | 30 | { | 28 | { |
2032 | 29 | namespace qt | ||
2033 | 30 | { | ||
2034 | 31 | namespace client | ||
2035 | 32 | { | ||
2036 | 31 | namespace internal | 33 | namespace internal |
2037 | 32 | { | 34 | { |
2046 | 33 | 35 | namespace remote_client | |
2047 | 34 | struct ItemMetadata; | 36 | { |
2048 | 35 | QDBusArgument& operator<<(QDBusArgument& argument, storage::internal::ItemMetadata const& metadata); | 37 | |
2049 | 36 | QDBusArgument const& operator>>(QDBusArgument const& argument, storage::internal::ItemMetadata& metadata); | 38 | std::exception_ptr unmarshal_exception(QDBusPendingCallWatcher const& call); |
2050 | 37 | 39 | ||
2051 | 38 | QDBusArgument& operator<<(QDBusArgument& argument, QList<storage::internal::ItemMetadata> const& md_list); | 40 | } // namespace remote_client |
2044 | 39 | QDBusArgument const& operator>>(QDBusArgument const& argument, QList<storage::internal::ItemMetadata>& md_list); | ||
2045 | 40 | |||
2052 | 41 | } // namespace internal | 41 | } // namespace internal |
2058 | 42 | } // namespace storage | 42 | } // client |
2059 | 43 | } // namespace unity | 43 | } // qt |
2060 | 44 | 44 | } // storage | |
2061 | 45 | Q_DECLARE_METATYPE(unity::storage::internal::ItemMetadata) | 45 | } // unity |
2057 | 46 | Q_DECLARE_METATYPE(QList<unity::storage::internal::ItemMetadata>) | ||
2062 | 47 | 46 | ||
2063 | === added file 'include/unity/storage/qt/client/internal/remote_client/validate.h' | |||
2064 | --- include/unity/storage/qt/client/internal/remote_client/validate.h 1970-01-01 00:00:00 +0000 | |||
2065 | +++ include/unity/storage/qt/client/internal/remote_client/validate.h 2016-09-09 02:13:43 +0000 | |||
2066 | @@ -0,0 +1,51 @@ | |||
2067 | 1 | /* | ||
2068 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
2069 | 3 | * | ||
2070 | 4 | * This program is free software: you can redistribute it and/or modify | ||
2071 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
2072 | 6 | * published by the Free Software Foundation. | ||
2073 | 7 | * | ||
2074 | 8 | * This program is distributed in the hope that it will be useful, | ||
2075 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2076 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2077 | 11 | * GNU Lesser General Public License for more details. | ||
2078 | 12 | * | ||
2079 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2080 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2081 | 15 | * | ||
2082 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
2083 | 17 | */ | ||
2084 | 18 | |||
2085 | 19 | #pragma once | ||
2086 | 20 | |||
2087 | 21 | #include <QString> | ||
2088 | 22 | |||
2089 | 23 | namespace unity | ||
2090 | 24 | { | ||
2091 | 25 | namespace storage | ||
2092 | 26 | { | ||
2093 | 27 | |||
2094 | 28 | namespace internal | ||
2095 | 29 | { | ||
2096 | 30 | |||
2097 | 31 | class ItemMetadata; | ||
2098 | 32 | |||
2099 | 33 | } // namespace internal | ||
2100 | 34 | |||
2101 | 35 | namespace qt | ||
2102 | 36 | { | ||
2103 | 37 | namespace client | ||
2104 | 38 | { | ||
2105 | 39 | namespace internal | ||
2106 | 40 | { | ||
2107 | 41 | namespace remote_client | ||
2108 | 42 | { | ||
2109 | 43 | |||
2110 | 44 | void validate(QString const& method, unity::storage::internal::ItemMetadata const& md); | ||
2111 | 45 | |||
2112 | 46 | } // namespace remote_client | ||
2113 | 47 | } // namespace internal | ||
2114 | 48 | } // namespace client | ||
2115 | 49 | } // namespace qt | ||
2116 | 50 | } // namespace storage | ||
2117 | 51 | } // namespace unity | ||
2118 | 0 | 52 | ||
2119 | === modified file 'src/internal/CMakeLists.txt' | |||
2120 | --- src/internal/CMakeLists.txt 2016-07-06 00:59:42 +0000 | |||
2121 | +++ src/internal/CMakeLists.txt 2016-09-09 02:13:43 +0000 | |||
2122 | @@ -1,5 +1,10 @@ | |||
2123 | 1 | set(src | 1 | set(src |
2124 | 2 | dbusmarshal.cpp | ||
2125 | 2 | safe_strerror.cpp | 3 | safe_strerror.cpp |
2126 | 4 | TraceMessageHandler.cpp | ||
2127 | 3 | ) | 5 | ) |
2128 | 4 | 6 | ||
2129 | 5 | add_library(storage-framework-common-internal STATIC ${src}) | 7 | add_library(storage-framework-common-internal STATIC ${src}) |
2130 | 8 | target_link_libraries(storage-framework-common-internal | ||
2131 | 9 | Qt5::DBus | ||
2132 | 10 | ) | ||
2133 | 6 | 11 | ||
2134 | === added file 'src/internal/TraceMessageHandler.cpp' | |||
2135 | --- src/internal/TraceMessageHandler.cpp 1970-01-01 00:00:00 +0000 | |||
2136 | +++ src/internal/TraceMessageHandler.cpp 2016-09-09 02:13:43 +0000 | |||
2137 | @@ -0,0 +1,96 @@ | |||
2138 | 1 | /* | ||
2139 | 2 | * Copyright (C) 2015 Canonical Ltd | ||
2140 | 3 | * | ||
2141 | 4 | * This program is free software: you can redistribute it and/or modify | ||
2142 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
2143 | 6 | * published by the Free Software Foundation. | ||
2144 | 7 | * | ||
2145 | 8 | * This program is distributed in the hope that it will be useful, | ||
2146 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2147 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2148 | 11 | * GNU Lesser General Public License for more details. | ||
2149 | 12 | * | ||
2150 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2151 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2152 | 15 | * | ||
2153 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
2154 | 17 | */ | ||
2155 | 18 | |||
2156 | 19 | #include <unity/storage/internal/TraceMessageHandler.h> | ||
2157 | 20 | |||
2158 | 21 | #include <chrono> | ||
2159 | 22 | #include <mutex> | ||
2160 | 23 | |||
2161 | 24 | using namespace std; | ||
2162 | 25 | |||
2163 | 26 | namespace unity | ||
2164 | 27 | { | ||
2165 | 28 | namespace storage | ||
2166 | 29 | { | ||
2167 | 30 | namespace internal | ||
2168 | 31 | { | ||
2169 | 32 | namespace | ||
2170 | 33 | { | ||
2171 | 34 | |||
2172 | 35 | string prefix; | ||
2173 | 36 | |||
2174 | 37 | void trace_message_handler(QtMsgType type, const QMessageLogContext& /*context*/, const QString& msg) | ||
2175 | 38 | { | ||
2176 | 39 | using namespace std; | ||
2177 | 40 | using namespace std::chrono; | ||
2178 | 41 | |||
2179 | 42 | static recursive_mutex mutex; | ||
2180 | 43 | lock_guard<decltype(mutex)> lock(mutex); | ||
2181 | 44 | |||
2182 | 45 | auto now = system_clock::now(); | ||
2183 | 46 | auto sys_time = system_clock::to_time_t(now); | ||
2184 | 47 | struct tm local_time; | ||
2185 | 48 | localtime_r(&sys_time, &local_time); | ||
2186 | 49 | int msecs = duration_cast<milliseconds>(now.time_since_epoch()).count() % 1000; | ||
2187 | 50 | |||
2188 | 51 | if (!prefix.empty()) | ||
2189 | 52 | { | ||
2190 | 53 | fprintf(stderr, "%s: ", prefix.c_str()); | ||
2191 | 54 | } | ||
2192 | 55 | char buf[100]; | ||
2193 | 56 | strftime(buf, sizeof(buf), "%T", &local_time); | ||
2194 | 57 | fprintf(stderr, "[%s.%03d]", buf, msecs); | ||
2195 | 58 | switch (type) | ||
2196 | 59 | { | ||
2197 | 60 | case QtWarningMsg: | ||
2198 | 61 | fputs(" Warning:", stderr); | ||
2199 | 62 | break; | ||
2200 | 63 | case QtCriticalMsg: | ||
2201 | 64 | fputs(" Critical:", stderr); | ||
2202 | 65 | break; | ||
2203 | 66 | // LCOV_EXCL_START | ||
2204 | 67 | case QtFatalMsg: | ||
2205 | 68 | fputs(" Fatal:", stderr); | ||
2206 | 69 | break; | ||
2207 | 70 | // LCOV_EXCL_STOP | ||
2208 | 71 | default: | ||
2209 | 72 | break; // No label for debug messages. | ||
2210 | 73 | } | ||
2211 | 74 | fprintf(stderr, " %s\n", msg.toLocal8Bit().constData()); | ||
2212 | 75 | if (type == QtFatalMsg) | ||
2213 | 76 | { | ||
2214 | 77 | abort(); // LCOV_EXCL_LINE | ||
2215 | 78 | } | ||
2216 | 79 | } | ||
2217 | 80 | |||
2218 | 81 | } // namespace | ||
2219 | 82 | |||
2220 | 83 | TraceMessageHandler::TraceMessageHandler(string const& prog_name) | ||
2221 | 84 | { | ||
2222 | 85 | prefix = prog_name; | ||
2223 | 86 | old_message_handler_ = qInstallMessageHandler(trace_message_handler); | ||
2224 | 87 | } | ||
2225 | 88 | |||
2226 | 89 | TraceMessageHandler::~TraceMessageHandler() | ||
2227 | 90 | { | ||
2228 | 91 | qInstallMessageHandler(old_message_handler_); | ||
2229 | 92 | } | ||
2230 | 93 | |||
2231 | 94 | } // namespace internal | ||
2232 | 95 | } // namespace storage | ||
2233 | 96 | } // namespace unity | ||
2234 | 0 | 97 | ||
2235 | === added file 'src/internal/dbusmarshal.cpp' | |||
2236 | --- src/internal/dbusmarshal.cpp 1970-01-01 00:00:00 +0000 | |||
2237 | +++ src/internal/dbusmarshal.cpp 2016-09-09 02:13:43 +0000 | |||
2238 | @@ -0,0 +1,113 @@ | |||
2239 | 1 | /* | ||
2240 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
2241 | 3 | * | ||
2242 | 4 | * This program is free software: you can redistribute it and/or modify | ||
2243 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
2244 | 6 | * published by the Free Software Foundation. | ||
2245 | 7 | * | ||
2246 | 8 | * This program is distributed in the hope that it will be useful, | ||
2247 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2248 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2249 | 11 | * GNU Lesser General Public License for more details. | ||
2250 | 12 | * | ||
2251 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2252 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2253 | 15 | * | ||
2254 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
2255 | 17 | */ | ||
2256 | 18 | |||
2257 | 19 | #include <unity/storage/internal/dbusmarshal.h> | ||
2258 | 20 | |||
2259 | 21 | #include <QDebug> | ||
2260 | 22 | |||
2261 | 23 | using namespace unity::storage::internal; | ||
2262 | 24 | using namespace std; | ||
2263 | 25 | |||
2264 | 26 | namespace unity | ||
2265 | 27 | { | ||
2266 | 28 | namespace storage | ||
2267 | 29 | { | ||
2268 | 30 | namespace internal | ||
2269 | 31 | { | ||
2270 | 32 | |||
2271 | 33 | QDBusArgument& operator<<(QDBusArgument& argument, storage::internal::ItemMetadata const& metadata) | ||
2272 | 34 | { | ||
2273 | 35 | argument.beginStructure(); | ||
2274 | 36 | argument << metadata.item_id; | ||
2275 | 37 | argument << metadata.parent_ids; | ||
2276 | 38 | argument << metadata.name; | ||
2277 | 39 | argument << metadata.etag; | ||
2278 | 40 | argument << static_cast<int32_t>(metadata.type); | ||
2279 | 41 | argument.beginMap(QVariant::String, qMetaTypeId<QDBusVariant>()); | ||
2280 | 42 | decltype(ItemMetadata::metadata)::const_iterator i = metadata.metadata.constBegin(); | ||
2281 | 43 | while (i != metadata.metadata.constEnd()) | ||
2282 | 44 | { | ||
2283 | 45 | argument.beginMapEntry(); | ||
2284 | 46 | argument << i.key() << QDBusVariant(i.value()); | ||
2285 | 47 | argument.endMapEntry(); | ||
2286 | 48 | ++i; | ||
2287 | 49 | } | ||
2288 | 50 | argument.endMap(); | ||
2289 | 51 | argument.endStructure(); | ||
2290 | 52 | return argument; | ||
2291 | 53 | } | ||
2292 | 54 | |||
2293 | 55 | QDBusArgument const& operator>>(QDBusArgument const& argument, storage::internal::ItemMetadata& metadata) | ||
2294 | 56 | { | ||
2295 | 57 | argument.beginStructure(); | ||
2296 | 58 | argument >> metadata.item_id; | ||
2297 | 59 | argument >> metadata.parent_ids; | ||
2298 | 60 | argument >> metadata.name; | ||
2299 | 61 | argument >> metadata.etag; | ||
2300 | 62 | int32_t enum_val; | ||
2301 | 63 | argument >> enum_val; | ||
2302 | 64 | if (enum_val < 0 || enum_val >= int(ItemType::LAST_ENTRY__)) | ||
2303 | 65 | { | ||
2304 | 66 | qCritical() << "unmarshaling error: impossible ItemType value: " + QString::number(enum_val); | ||
2305 | 67 | return argument; // Forces error | ||
2306 | 68 | } | ||
2307 | 69 | metadata.type = static_cast<ItemType>(enum_val); | ||
2308 | 70 | metadata.metadata.clear(); | ||
2309 | 71 | argument.beginMap(); | ||
2310 | 72 | while (!argument.atEnd()) | ||
2311 | 73 | { | ||
2312 | 74 | QString key; | ||
2313 | 75 | QVariant value; | ||
2314 | 76 | argument.beginMapEntry(); | ||
2315 | 77 | argument >> key >> value; | ||
2316 | 78 | argument.endMapEntry(); | ||
2317 | 79 | metadata.metadata.insert(key, value); | ||
2318 | 80 | } | ||
2319 | 81 | argument.endMap(); | ||
2320 | 82 | argument.endStructure(); | ||
2321 | 83 | return argument; | ||
2322 | 84 | } | ||
2323 | 85 | |||
2324 | 86 | QDBusArgument& operator<<(QDBusArgument& argument, QList<storage::internal::ItemMetadata> const& md_list) | ||
2325 | 87 | { | ||
2326 | 88 | argument.beginArray(qMetaTypeId<storage::internal::ItemMetadata>()); | ||
2327 | 89 | for (auto const& md : md_list) | ||
2328 | 90 | { | ||
2329 | 91 | argument << md; | ||
2330 | 92 | } | ||
2331 | 93 | argument.endArray(); | ||
2332 | 94 | return argument; | ||
2333 | 95 | } | ||
2334 | 96 | |||
2335 | 97 | QDBusArgument const& operator>>(QDBusArgument const& argument, QList<storage::internal::ItemMetadata>& md_list) | ||
2336 | 98 | { | ||
2337 | 99 | md_list.clear(); | ||
2338 | 100 | argument.beginArray(); | ||
2339 | 101 | while (!argument.atEnd()) | ||
2340 | 102 | { | ||
2341 | 103 | ItemMetadata imd; | ||
2342 | 104 | argument >> imd; | ||
2343 | 105 | md_list.append(imd); | ||
2344 | 106 | } | ||
2345 | 107 | argument.endArray(); | ||
2346 | 108 | return argument; | ||
2347 | 109 | } | ||
2348 | 110 | |||
2349 | 111 | } // namespace internal | ||
2350 | 112 | } // namespace storage | ||
2351 | 113 | } // namespace unity | ||
2352 | 0 | 114 | ||
2353 | === modified file 'src/provider/CMakeLists.txt' | |||
2354 | --- src/provider/CMakeLists.txt 2016-07-22 03:29:45 +0000 | |||
2355 | +++ src/provider/CMakeLists.txt 2016-09-09 02:13:43 +0000 | |||
2356 | @@ -1,9 +1,3 @@ | |||
2357 | 1 | |||
2358 | 2 | add_definitions( | ||
2359 | 3 | -DBOOST_THREAD_VERSION=4 | ||
2360 | 4 | -DBOOST_THREAD_PROVIDES_EXECUTORS | ||
2361 | 5 | ${APPARMOR_DEPS_CFLAGS} | ||
2362 | 6 | ${ONLINEACCOUNTS_DEPS_CFLAGS}) | ||
2363 | 7 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | 1 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
2364 | 8 | 2 | ||
2365 | 9 | qt5_add_dbus_adaptor(generated_files ${CMAKE_SOURCE_DIR}/data/provider.xml unity/storage/provider/internal/ProviderInterface.h unity::storage::provider::internal::ProviderInterface) | 3 | qt5_add_dbus_adaptor(generated_files ${CMAKE_SOURCE_DIR}/data/provider.xml unity/storage/provider/internal/ProviderInterface.h unity::storage::provider::internal::ProviderInterface) |
2366 | @@ -12,16 +6,20 @@ | |||
2367 | 12 | qt5_add_dbus_interface(generated_files bus.xml businterface) | 6 | qt5_add_dbus_interface(generated_files bus.xml businterface) |
2368 | 13 | 7 | ||
2369 | 14 | set_source_files_properties(${generated_files} PROPERTIES | 8 | set_source_files_properties(${generated_files} PROPERTIES |
2372 | 15 | COMPILE_FLAGS "-Wno-ctor-dtor-privacy -Wmissing-field-initializers" | 9 | COMPILE_FLAGS "-Wno-ctor-dtor-privacy -Wmissing-field-initializers" |
2373 | 16 | GENERATED TRUE | 10 | GENERATED TRUE |
2374 | 17 | ) | 11 | ) |
2375 | 18 | 12 | ||
2377 | 19 | add_library(storage-framework-provider SHARED | 13 | add_custom_target(sf-provider-generated-files DEPENDS ${generated_files}) |
2378 | 14 | |||
2379 | 15 | add_library(sf-provider-objects OBJECT | ||
2380 | 20 | DownloadJob.cpp | 16 | DownloadJob.cpp |
2381 | 17 | Exceptions.cpp | ||
2382 | 21 | ProviderBase.cpp | 18 | ProviderBase.cpp |
2383 | 22 | Server.cpp | 19 | Server.cpp |
2384 | 23 | TempfileUploadJob.cpp | 20 | TempfileUploadJob.cpp |
2385 | 24 | UploadJob.cpp | 21 | UploadJob.cpp |
2386 | 22 | testing/TestServer.cpp | ||
2387 | 25 | internal/AccountData.cpp | 23 | internal/AccountData.cpp |
2388 | 26 | internal/DBusPeerCache.cpp | 24 | internal/DBusPeerCache.cpp |
2389 | 27 | internal/DownloadJobImpl.cpp | 25 | internal/DownloadJobImpl.cpp |
2390 | @@ -31,6 +29,7 @@ | |||
2391 | 31 | internal/ProviderInterface.cpp | 29 | internal/ProviderInterface.cpp |
2392 | 32 | internal/ServerImpl.cpp | 30 | internal/ServerImpl.cpp |
2393 | 33 | internal/TempfileUploadJobImpl.cpp | 31 | internal/TempfileUploadJobImpl.cpp |
2394 | 32 | internal/TestServerImpl.cpp | ||
2395 | 34 | internal/UploadJobImpl.cpp | 33 | internal/UploadJobImpl.cpp |
2396 | 35 | internal/dbusmarshal.cpp | 34 | internal/dbusmarshal.cpp |
2397 | 36 | ${CMAKE_SOURCE_DIR}/include/unity/storage/provider/internal/AccountData.h | 35 | ${CMAKE_SOURCE_DIR}/include/unity/storage/provider/internal/AccountData.h |
2398 | @@ -42,6 +41,23 @@ | |||
2399 | 42 | ${CMAKE_SOURCE_DIR}/include/unity/storage/provider/internal/ServerImpl.h | 41 | ${CMAKE_SOURCE_DIR}/include/unity/storage/provider/internal/ServerImpl.h |
2400 | 43 | ${CMAKE_SOURCE_DIR}/include/unity/storage/provider/internal/TempfileUploadJobImpl.h | 42 | ${CMAKE_SOURCE_DIR}/include/unity/storage/provider/internal/TempfileUploadJobImpl.h |
2401 | 44 | ${CMAKE_SOURCE_DIR}/include/unity/storage/provider/internal/UploadJobImpl.h | 43 | ${CMAKE_SOURCE_DIR}/include/unity/storage/provider/internal/UploadJobImpl.h |
2402 | 44 | ) | ||
2403 | 45 | add_dependencies(sf-provider-objects sf-provider-generated-files) | ||
2404 | 46 | set_target_properties(sf-provider-objects PROPERTIES | ||
2405 | 47 | AUTOMOC TRUE | ||
2406 | 48 | ) | ||
2407 | 49 | target_compile_options(sf-provider-objects PUBLIC | ||
2408 | 50 | -DBOOST_THREAD_VERSION=4 | ||
2409 | 51 | -DBOOST_THREAD_PROVIDES_EXECUTORS | ||
2410 | 52 | ${APPARMOR_DEPS_CFLAGS} | ||
2411 | 53 | ${ONLINEACCOUNTS_DEPS_CFLAGS}) | ||
2412 | 54 | target_include_directories(sf-provider-objects PRIVATE | ||
2413 | 55 | ${Qt5DBus_INCLUDE_DIRS} | ||
2414 | 56 | ${Qt5Network_INCLUDE_DIRS} | ||
2415 | 57 | ) | ||
2416 | 58 | |||
2417 | 59 | add_library(storage-framework-provider SHARED | ||
2418 | 60 | $<TARGET_OBJECTS:sf-provider-objects> | ||
2419 | 45 | ${generated_files}) | 61 | ${generated_files}) |
2420 | 46 | 62 | ||
2421 | 47 | set_target_properties(storage-framework-provider PROPERTIES | 63 | set_target_properties(storage-framework-provider PROPERTIES |
2422 | @@ -51,7 +67,10 @@ | |||
2423 | 51 | SOVERSION ${SF_PROVIDER_SOVERSION} | 67 | SOVERSION ${SF_PROVIDER_SOVERSION} |
2424 | 52 | VERSION ${SF_PROVIDER_LIBVERSION} | 68 | VERSION ${SF_PROVIDER_LIBVERSION} |
2425 | 53 | ) | 69 | ) |
2426 | 70 | target_compile_options(storage-framework-provider PUBLIC | ||
2427 | 71 | $<TARGET_PROPERTY:sf-provider-objects,COMPILE_OPTIONS>) | ||
2428 | 54 | target_link_libraries(storage-framework-provider | 72 | target_link_libraries(storage-framework-provider |
2429 | 73 | storage-framework-common-internal | ||
2430 | 55 | Qt5::Core | 74 | Qt5::Core |
2431 | 56 | Qt5::DBus | 75 | Qt5::DBus |
2432 | 57 | Qt5::Network | 76 | Qt5::Network |
2433 | @@ -60,19 +79,31 @@ | |||
2434 | 60 | ${ONLINEACCOUNTS_DEPS_LDFLAGS} | 79 | ${ONLINEACCOUNTS_DEPS_LDFLAGS} |
2435 | 61 | ) | 80 | ) |
2436 | 62 | 81 | ||
2437 | 63 | # moc does not know how to interpret the preprocessor logic in | ||
2438 | 64 | # MainLoopExecutor.h, so we reproduce it here. | ||
2439 | 65 | if(Boost_VERSION GREATER "105599") | ||
2440 | 66 | set_target_properties(storage-framework-provider PROPERTIES | ||
2441 | 67 | AUTOMOC_MOC_OPTIONS "-DSF_SUPPORTS_EXECUTORS" | ||
2442 | 68 | ) | ||
2443 | 69 | endif() | ||
2444 | 70 | |||
2445 | 71 | install( | 82 | install( |
2446 | 72 | TARGETS storage-framework-provider | 83 | TARGETS storage-framework-provider |
2447 | 73 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | 84 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
2448 | 74 | ) | 85 | ) |
2449 | 75 | 86 | ||
2450 | 87 | # Build a static version of the library so that tests have access to | ||
2451 | 88 | # hidden visibility symbols. | ||
2452 | 89 | add_library(storage-framework-provider-static STATIC | ||
2453 | 90 | $<TARGET_OBJECTS:sf-provider-objects> | ||
2454 | 91 | ${generated_files}) | ||
2455 | 92 | set_target_properties(storage-framework-provider-static PROPERTIES | ||
2456 | 93 | AUTOMOC TRUE | ||
2457 | 94 | ) | ||
2458 | 95 | target_compile_options(storage-framework-provider-static PUBLIC | ||
2459 | 96 | $<TARGET_PROPERTY:sf-provider-objects,COMPILE_OPTIONS>) | ||
2460 | 97 | target_link_libraries(storage-framework-provider-static | ||
2461 | 98 | storage-framework-common-internal | ||
2462 | 99 | Qt5::Core | ||
2463 | 100 | Qt5::DBus | ||
2464 | 101 | Qt5::Network | ||
2465 | 102 | ${Boost_LIBRARIES} | ||
2466 | 103 | ${APPARMOR_DEPS_LDFLAGS} | ||
2467 | 104 | ${ONLINEACCOUNTS_DEPS_LDFLAGS} | ||
2468 | 105 | ) | ||
2469 | 106 | |||
2470 | 76 | configure_file( | 107 | configure_file( |
2471 | 77 | storage-framework-provider.pc.in | 108 | storage-framework-provider.pc.in |
2472 | 78 | storage-framework-provider-${SF_PROVIDER_API_VERSION}.pc | 109 | storage-framework-provider-${SF_PROVIDER_API_VERSION}.pc |
2473 | 79 | 110 | ||
2474 | === added file 'src/provider/Exceptions.cpp' | |||
2475 | --- src/provider/Exceptions.cpp 1970-01-01 00:00:00 +0000 | |||
2476 | +++ src/provider/Exceptions.cpp 2016-09-09 02:13:43 +0000 | |||
2477 | @@ -0,0 +1,157 @@ | |||
2478 | 1 | /* | ||
2479 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
2480 | 3 | * | ||
2481 | 4 | * This program is free software: you can redistribute it and/or modify | ||
2482 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
2483 | 6 | * published by the Free Software Foundation. | ||
2484 | 7 | * | ||
2485 | 8 | * This program is distributed in the hope that it will be useful, | ||
2486 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2487 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2488 | 11 | * GNU Lesser General Public License for more details. | ||
2489 | 12 | * | ||
2490 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2491 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2492 | 15 | * | ||
2493 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
2494 | 17 | */ | ||
2495 | 18 | |||
2496 | 19 | #include <unity/storage/provider/Exceptions.h> | ||
2497 | 20 | |||
2498 | 21 | using namespace std; | ||
2499 | 22 | |||
2500 | 23 | namespace unity | ||
2501 | 24 | { | ||
2502 | 25 | namespace storage | ||
2503 | 26 | { | ||
2504 | 27 | namespace provider | ||
2505 | 28 | { | ||
2506 | 29 | |||
2507 | 30 | StorageException::StorageException(std::string const& exception_type, string const& error_message) | ||
2508 | 31 | : what_string_(string(exception_type) + ": " + error_message) | ||
2509 | 32 | , type_(exception_type) | ||
2510 | 33 | , error_message_(error_message) | ||
2511 | 34 | { | ||
2512 | 35 | } | ||
2513 | 36 | |||
2514 | 37 | StorageException::~StorageException() = default; | ||
2515 | 38 | |||
2516 | 39 | char const* StorageException::what() const noexcept | ||
2517 | 40 | { | ||
2518 | 41 | return what_string_.c_str(); | ||
2519 | 42 | } | ||
2520 | 43 | |||
2521 | 44 | string StorageException::type() const | ||
2522 | 45 | { | ||
2523 | 46 | return type_; | ||
2524 | 47 | } | ||
2525 | 48 | |||
2526 | 49 | string StorageException::error_message() const | ||
2527 | 50 | { | ||
2528 | 51 | return error_message_; | ||
2529 | 52 | } | ||
2530 | 53 | |||
2531 | 54 | RemoteCommsException::RemoteCommsException(string const& error_message) | ||
2532 | 55 | : StorageException("RemoteCommsException", error_message) | ||
2533 | 56 | { | ||
2534 | 57 | } | ||
2535 | 58 | |||
2536 | 59 | RemoteCommsException::~RemoteCommsException() = default; | ||
2537 | 60 | |||
2538 | 61 | NotExistsException::NotExistsException(string const& error_message, string const& key) | ||
2539 | 62 | : StorageException("NotExistsException", error_message) | ||
2540 | 63 | , key_(key) | ||
2541 | 64 | { | ||
2542 | 65 | } | ||
2543 | 66 | |||
2544 | 67 | NotExistsException::~NotExistsException() = default; | ||
2545 | 68 | |||
2546 | 69 | string NotExistsException::key() const | ||
2547 | 70 | { | ||
2548 | 71 | return key_; | ||
2549 | 72 | } | ||
2550 | 73 | |||
2551 | 74 | ExistsException::ExistsException(string const& error_message, string const& identity, string const& name) | ||
2552 | 75 | : StorageException("ExistsException", error_message) | ||
2553 | 76 | , identity_(identity) | ||
2554 | 77 | , name_(name) | ||
2555 | 78 | { | ||
2556 | 79 | } | ||
2557 | 80 | |||
2558 | 81 | ExistsException::~ExistsException() = default; | ||
2559 | 82 | |||
2560 | 83 | string ExistsException::native_identity() const | ||
2561 | 84 | { | ||
2562 | 85 | return identity_; | ||
2563 | 86 | } | ||
2564 | 87 | |||
2565 | 88 | string ExistsException::name() const | ||
2566 | 89 | { | ||
2567 | 90 | return name_; | ||
2568 | 91 | } | ||
2569 | 92 | |||
2570 | 93 | ConflictException::ConflictException(string const& error_message) | ||
2571 | 94 | : StorageException("ConflictException", error_message) | ||
2572 | 95 | { | ||
2573 | 96 | } | ||
2574 | 97 | |||
2575 | 98 | ConflictException::~ConflictException() = default; | ||
2576 | 99 | |||
2577 | 100 | PermissionException::PermissionException(string const& error_message) | ||
2578 | 101 | : StorageException("PermissionException", error_message) | ||
2579 | 102 | { | ||
2580 | 103 | } | ||
2581 | 104 | |||
2582 | 105 | PermissionException::~PermissionException() = default; | ||
2583 | 106 | |||
2584 | 107 | QuotaException::QuotaException(string const& error_message) | ||
2585 | 108 | : StorageException("QuotaException", error_message) | ||
2586 | 109 | { | ||
2587 | 110 | } | ||
2588 | 111 | |||
2589 | 112 | QuotaException::~QuotaException() = default; | ||
2590 | 113 | |||
2591 | 114 | CancelledException::CancelledException(string const& error_message) | ||
2592 | 115 | : StorageException("CancelledException", error_message) | ||
2593 | 116 | { | ||
2594 | 117 | } | ||
2595 | 118 | |||
2596 | 119 | CancelledException::~CancelledException() = default; | ||
2597 | 120 | |||
2598 | 121 | LogicException::LogicException(string const& error_message) | ||
2599 | 122 | : StorageException("LogicException", error_message) | ||
2600 | 123 | { | ||
2601 | 124 | } | ||
2602 | 125 | |||
2603 | 126 | LogicException::~LogicException() = default; | ||
2604 | 127 | |||
2605 | 128 | InvalidArgumentException::InvalidArgumentException(string const& error_message) | ||
2606 | 129 | : StorageException("InvalidArgumentException", error_message) | ||
2607 | 130 | { | ||
2608 | 131 | } | ||
2609 | 132 | |||
2610 | 133 | InvalidArgumentException::~InvalidArgumentException() = default; | ||
2611 | 134 | |||
2612 | 135 | ResourceException::ResourceException(string const& error_message, int error_code) | ||
2613 | 136 | : StorageException("ResourceException", error_message) | ||
2614 | 137 | , error_code_(error_code) | ||
2615 | 138 | { | ||
2616 | 139 | } | ||
2617 | 140 | |||
2618 | 141 | ResourceException::~ResourceException() = default; | ||
2619 | 142 | |||
2620 | 143 | int ResourceException::error_code() const noexcept | ||
2621 | 144 | { | ||
2622 | 145 | return error_code_; | ||
2623 | 146 | } | ||
2624 | 147 | |||
2625 | 148 | UnknownException::UnknownException(string const& error_message) | ||
2626 | 149 | : StorageException("UnknownException", error_message) | ||
2627 | 150 | { | ||
2628 | 151 | } | ||
2629 | 152 | |||
2630 | 153 | UnknownException::~UnknownException() = default; | ||
2631 | 154 | |||
2632 | 155 | } // namespace provider | ||
2633 | 156 | } // namespace storage | ||
2634 | 157 | } // namespace unity | ||
2635 | 0 | 158 | ||
2636 | === modified file 'src/provider/TempfileUploadJob.cpp' | |||
2637 | --- src/provider/TempfileUploadJob.cpp 2016-07-12 02:22:05 +0000 | |||
2638 | +++ src/provider/TempfileUploadJob.cpp 2016-09-09 02:13:43 +0000 | |||
2639 | @@ -40,6 +40,11 @@ | |||
2640 | 40 | 40 | ||
2641 | 41 | TempfileUploadJob::~TempfileUploadJob() = default; | 41 | TempfileUploadJob::~TempfileUploadJob() = default; |
2642 | 42 | 42 | ||
2643 | 43 | void TempfileUploadJob::drain() | ||
2644 | 44 | { | ||
2645 | 45 | static_cast<internal::TempfileUploadJobImpl*>(p_)->drain(); | ||
2646 | 46 | } | ||
2647 | 47 | |||
2648 | 43 | string TempfileUploadJob::file_name() const | 48 | string TempfileUploadJob::file_name() const |
2649 | 44 | { | 49 | { |
2650 | 45 | return static_cast<internal::TempfileUploadJobImpl*>(p_)->file_name(); | 50 | return static_cast<internal::TempfileUploadJobImpl*>(p_)->file_name(); |
2651 | 46 | 51 | ||
2652 | === modified file 'src/provider/internal/DownloadJobImpl.cpp' | |||
2653 | --- src/provider/internal/DownloadJobImpl.cpp 2016-07-12 02:22:05 +0000 | |||
2654 | +++ src/provider/internal/DownloadJobImpl.cpp 2016-09-09 02:13:43 +0000 | |||
2655 | @@ -17,7 +17,9 @@ | |||
2656 | 17 | */ | 17 | */ |
2657 | 18 | 18 | ||
2658 | 19 | #include <unity/storage/provider/internal/DownloadJobImpl.h> | 19 | #include <unity/storage/provider/internal/DownloadJobImpl.h> |
2659 | 20 | #include <unity/storage/internal/safe_strerror.h> | ||
2660 | 20 | #include <unity/storage/provider/DownloadJob.h> | 21 | #include <unity/storage/provider/DownloadJob.h> |
2661 | 22 | #include <unity/storage/provider/Exceptions.h> | ||
2662 | 21 | 23 | ||
2663 | 22 | #include <sys/socket.h> | 24 | #include <sys/socket.h> |
2664 | 23 | #include <sys/types.h> | 25 | #include <sys/types.h> |
2665 | @@ -26,6 +28,7 @@ | |||
2666 | 26 | #include <stdexcept> | 28 | #include <stdexcept> |
2667 | 27 | 29 | ||
2668 | 28 | using namespace std; | 30 | using namespace std; |
2669 | 31 | using namespace unity::storage::internal; | ||
2670 | 29 | 32 | ||
2671 | 30 | namespace unity | 33 | namespace unity |
2672 | 31 | { | 34 | { |
2673 | @@ -42,18 +45,30 @@ | |||
2674 | 42 | int socks[2]; | 45 | int socks[2]; |
2675 | 43 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, socks) < 0) | 46 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, socks) < 0) |
2676 | 44 | { | 47 | { |
2678 | 45 | throw runtime_error("could not create socketpair"); | 48 | int error_code = errno; |
2679 | 49 | string msg = "could not create socketpair: " + safe_strerror(error_code); | ||
2680 | 50 | throw ResourceException(msg, error_code); | ||
2681 | 46 | } | 51 | } |
2682 | 47 | read_socket_ = socks[0]; | 52 | read_socket_ = socks[0]; |
2683 | 48 | write_socket_ = socks[1]; | 53 | write_socket_ = socks[1]; |
2684 | 54 | |||
2685 | 55 | #if 0 | ||
2686 | 56 | // TODO: We should be able to half-close the write channel of the read socket and the read channel of | ||
2687 | 57 | // the write socket. But, if we do, QLocalSocket indicates that everything was closed, which causes | ||
2688 | 58 | // failures on the client side. We suspect a QLocalSocket bug -- need to investigate. | ||
2689 | 49 | if (shutdown(read_socket_, SHUT_WR) < 0) | 59 | if (shutdown(read_socket_, SHUT_WR) < 0) |
2690 | 50 | { | 60 | { |
2692 | 51 | throw runtime_error("Could not shut down write channel on read socket"); | 61 | int error_code = errno; |
2693 | 62 | string msg = "Could not shut down write channel on read socket" + safe_strerror(error_code); | ||
2694 | 63 | throw ResourceException(msg, error_code); | ||
2695 | 52 | } | 64 | } |
2696 | 53 | if (shutdown(write_socket_, SHUT_RD) < 0) | 65 | if (shutdown(write_socket_, SHUT_RD) < 0) |
2697 | 54 | { | 66 | { |
2699 | 55 | throw runtime_error("Could not shut down read channel on write socket"); | 67 | int error_code = errno; |
2700 | 68 | string msg = "Could not shut down read channel on write socket: " + safe_strerror(error_code); | ||
2701 | 69 | throw ResourceException(msg, error_code); | ||
2702 | 56 | } | 70 | } |
2703 | 71 | #endif | ||
2704 | 57 | } | 72 | } |
2705 | 58 | 73 | ||
2706 | 59 | DownloadJobImpl::~DownloadJobImpl() | 74 | DownloadJobImpl::~DownloadJobImpl() |
2707 | @@ -90,17 +105,6 @@ | |||
2708 | 90 | return sock; | 105 | return sock; |
2709 | 91 | } | 106 | } |
2710 | 92 | 107 | ||
2711 | 93 | string const& DownloadJobImpl::sender_bus_name() const | ||
2712 | 94 | { | ||
2713 | 95 | return sender_bus_name_; | ||
2714 | 96 | } | ||
2715 | 97 | |||
2716 | 98 | void DownloadJobImpl::set_sender_bus_name(string const& bus_name) | ||
2717 | 99 | { | ||
2718 | 100 | assert(bus_name[0] == ':'); | ||
2719 | 101 | sender_bus_name_ = bus_name; | ||
2720 | 102 | } | ||
2721 | 103 | |||
2722 | 104 | void DownloadJobImpl::report_complete() | 108 | void DownloadJobImpl::report_complete() |
2723 | 105 | { | 109 | { |
2724 | 106 | if (write_socket_ >= 0) | 110 | if (write_socket_ >= 0) |
2725 | @@ -124,7 +128,19 @@ | |||
2726 | 124 | 128 | ||
2727 | 125 | lock_guard<mutex> guard(completion_lock_); | 129 | lock_guard<mutex> guard(completion_lock_); |
2728 | 126 | completed_ = true; | 130 | completed_ = true; |
2730 | 127 | completion_promise_.set_exception(p); | 131 | // Convert std::exception_ptr to boost::exception_ptr |
2731 | 132 | try | ||
2732 | 133 | { | ||
2733 | 134 | std::rethrow_exception(p); | ||
2734 | 135 | } | ||
2735 | 136 | catch (StorageException const& e) | ||
2736 | 137 | { | ||
2737 | 138 | completion_promise_.set_exception(e); | ||
2738 | 139 | } | ||
2739 | 140 | catch (...) | ||
2740 | 141 | { | ||
2741 | 142 | completion_promise_.set_exception(boost::current_exception()); | ||
2742 | 143 | } | ||
2743 | 128 | } | 144 | } |
2744 | 129 | 145 | ||
2745 | 130 | boost::future<void> DownloadJobImpl::finish(DownloadJob& job) | 146 | boost::future<void> DownloadJobImpl::finish(DownloadJob& job) |
2746 | 131 | 147 | ||
2747 | === modified file 'src/provider/internal/Handler.cpp' | |||
2748 | --- src/provider/internal/Handler.cpp 2016-07-20 02:20:53 +0000 | |||
2749 | +++ src/provider/internal/Handler.cpp 2016-09-09 02:13:43 +0000 | |||
2750 | @@ -17,20 +17,26 @@ | |||
2751 | 17 | */ | 17 | */ |
2752 | 18 | 18 | ||
2753 | 19 | #include <unity/storage/provider/internal/Handler.h> | 19 | #include <unity/storage/provider/internal/Handler.h> |
2754 | 20 | |||
2755 | 21 | #include <unity/storage/internal/dbus_error.h> | ||
2756 | 20 | #include <unity/storage/provider/internal/AccountData.h> | 22 | #include <unity/storage/provider/internal/AccountData.h> |
2757 | 23 | #include <unity/storage/provider/internal/dbusmarshal.h> | ||
2758 | 21 | #include <unity/storage/provider/internal/DBusPeerCache.h> | 24 | #include <unity/storage/provider/internal/DBusPeerCache.h> |
2759 | 22 | #include <unity/storage/provider/internal/MainLoopExecutor.h> | 25 | #include <unity/storage/provider/internal/MainLoopExecutor.h> |
2760 | 23 | #include <unity/storage/provider/ProviderBase.h> | 26 | #include <unity/storage/provider/ProviderBase.h> |
2761 | 27 | #include <unity/storage/provider/Exceptions.h> | ||
2762 | 28 | |||
2763 | 29 | #pragma GCC diagnostic push | ||
2764 | 30 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | ||
2765 | 31 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
2766 | 32 | #include <QDebug> | ||
2767 | 33 | #pragma GCC diagnostic pop | ||
2768 | 24 | 34 | ||
2769 | 25 | #include <stdexcept> | 35 | #include <stdexcept> |
2770 | 26 | 36 | ||
2771 | 37 | using namespace unity::storage::internal; | ||
2772 | 27 | using namespace std; | 38 | using namespace std; |
2773 | 28 | 39 | ||
2774 | 29 | namespace | ||
2775 | 30 | { | ||
2776 | 31 | char const ERROR[] = "com.canonical.StorageFramework.Provider.Error"; | ||
2777 | 32 | } | ||
2778 | 33 | |||
2779 | 34 | namespace unity | 40 | namespace unity |
2780 | 35 | { | 41 | { |
2781 | 36 | namespace storage | 42 | namespace storage |
2782 | @@ -53,7 +59,8 @@ | |||
2783 | 53 | auto peer_future = account_->dbus_peer().get(message_.service()); | 59 | auto peer_future = account_->dbus_peer().get(message_.service()); |
2784 | 54 | creds_future_ = peer_future.then( | 60 | creds_future_ = peer_future.then( |
2785 | 55 | EXEC_IN_MAIN | 61 | EXEC_IN_MAIN |
2787 | 56 | [this](decltype(peer_future) f) { | 62 | [this](decltype(peer_future) f) |
2788 | 63 | { | ||
2789 | 57 | auto info = f.get(); | 64 | auto info = f.get(); |
2790 | 58 | if (info.valid) | 65 | if (info.valid) |
2791 | 59 | { | 66 | { |
2792 | @@ -64,8 +71,10 @@ | |||
2793 | 64 | } | 71 | } |
2794 | 65 | else | 72 | else |
2795 | 66 | { | 73 | { |
2798 | 67 | reply_ = message_.createErrorReply( | 74 | string msg = "Handler::begin(): could not retrieve credentials"; |
2799 | 68 | ERROR, "Handler::begin(): could not retrieve credentials"); | 75 | qDebug() << QString::fromStdString(msg); |
2800 | 76 | auto ep = make_exception_ptr(PermissionException(msg)); | ||
2801 | 77 | marshal_exception(ep); | ||
2802 | 69 | QMetaObject::invokeMethod(this, "send_reply", | 78 | QMetaObject::invokeMethod(this, "send_reply", |
2803 | 70 | Qt::QueuedConnection); | 79 | Qt::QueuedConnection); |
2804 | 71 | } | 80 | } |
2805 | @@ -75,23 +84,29 @@ | |||
2806 | 75 | void Handler::credentials_received() | 84 | void Handler::credentials_received() |
2807 | 76 | { | 85 | { |
2808 | 77 | boost::future<QDBusMessage> msg_future; | 86 | boost::future<QDBusMessage> msg_future; |
2810 | 78 | try { | 87 | try |
2811 | 88 | { | ||
2812 | 79 | msg_future = callback_(account_, context_, message_); | 89 | msg_future = callback_(account_, context_, message_); |
2815 | 80 | } catch (std::exception const& e) { | 90 | } |
2816 | 81 | reply_ = message_.createErrorReply(ERROR, e.what()); | 91 | catch (std::exception const& e) |
2817 | 92 | { | ||
2818 | 93 | qDebug() << "provider method threw an exception:" << e.what(); | ||
2819 | 94 | marshal_exception(current_exception()); | ||
2820 | 82 | QMetaObject::invokeMethod(this, "send_reply", Qt::QueuedConnection); | 95 | QMetaObject::invokeMethod(this, "send_reply", Qt::QueuedConnection); |
2821 | 83 | return; | 96 | return; |
2822 | 84 | } | 97 | } |
2823 | 85 | reply_future_ = msg_future.then( | 98 | reply_future_ = msg_future.then( |
2824 | 86 | EXEC_IN_MAIN | 99 | EXEC_IN_MAIN |
2826 | 87 | [this](decltype(msg_future) f) { | 100 | [this](decltype(msg_future) f) |
2827 | 101 | { | ||
2828 | 88 | try | 102 | try |
2829 | 89 | { | 103 | { |
2830 | 90 | reply_ = f.get(); | 104 | reply_ = f.get(); |
2831 | 91 | } | 105 | } |
2832 | 92 | catch (std::exception const& e) | 106 | catch (std::exception const& e) |
2833 | 93 | { | 107 | { |
2835 | 94 | reply_ = message_.createErrorReply(ERROR, e.what()); | 108 | qDebug() << e.what(); |
2836 | 109 | marshal_exception(current_exception()); | ||
2837 | 95 | } | 110 | } |
2838 | 96 | QMetaObject::invokeMethod(this, "send_reply", Qt::QueuedConnection); | 111 | QMetaObject::invokeMethod(this, "send_reply", Qt::QueuedConnection); |
2839 | 97 | }); | 112 | }); |
2840 | @@ -103,6 +118,62 @@ | |||
2841 | 103 | Q_EMIT finished(); | 118 | Q_EMIT finished(); |
2842 | 104 | } | 119 | } |
2843 | 105 | 120 | ||
2844 | 121 | void Handler::marshal_exception(exception_ptr ep) | ||
2845 | 122 | { | ||
2846 | 123 | try | ||
2847 | 124 | { | ||
2848 | 125 | rethrow_exception(ep); | ||
2849 | 126 | } | ||
2850 | 127 | catch (StorageException const& e) | ||
2851 | 128 | { | ||
2852 | 129 | reply_ = message_.createErrorReply(QString(DBUS_ERROR_PREFIX) + QString::fromStdString(e.type()), | ||
2853 | 130 | QString::fromStdString(e.error_message())); | ||
2854 | 131 | try | ||
2855 | 132 | { | ||
2856 | 133 | throw; | ||
2857 | 134 | } | ||
2858 | 135 | catch (NotExistsException const& e) | ||
2859 | 136 | { | ||
2860 | 137 | reply_ << QVariant(QString::fromStdString(e.key())); | ||
2861 | 138 | } | ||
2862 | 139 | catch (ExistsException const& e) | ||
2863 | 140 | { | ||
2864 | 141 | reply_ << QVariant(QString::fromStdString(e.native_identity())); | ||
2865 | 142 | reply_ << QVariant(QString::fromStdString(e.name())); | ||
2866 | 143 | } | ||
2867 | 144 | catch (ResourceException const& e) | ||
2868 | 145 | { | ||
2869 | 146 | qDebug() << e.what(); | ||
2870 | 147 | reply_ << QVariant(e.error_code()); | ||
2871 | 148 | } | ||
2872 | 149 | catch (RemoteCommsException const& e) | ||
2873 | 150 | { | ||
2874 | 151 | qDebug() << e.what(); | ||
2875 | 152 | } | ||
2876 | 153 | catch (UnknownException const& e) | ||
2877 | 154 | { | ||
2878 | 155 | qDebug() << e.what(); | ||
2879 | 156 | } | ||
2880 | 157 | catch (StorageException const&) | ||
2881 | 158 | { | ||
2882 | 159 | // Some other sub-type of StorageException without additional data members, | ||
2883 | 160 | // and we don't want to log this (not surprising) exception. | ||
2884 | 161 | } | ||
2885 | 162 | } | ||
2886 | 163 | catch (std::exception const& e) | ||
2887 | 164 | { | ||
2888 | 165 | QString msg = QString("unknown exception thrown by provider: ") + e.what(); | ||
2889 | 166 | qDebug() << msg; | ||
2890 | 167 | reply_ = message_.createErrorReply(QString(DBUS_ERROR_PREFIX) + "UnknownException", msg); | ||
2891 | 168 | } | ||
2892 | 169 | catch (...) | ||
2893 | 170 | { | ||
2894 | 171 | QString msg = "unknown exception thrown by provider"; | ||
2895 | 172 | qDebug() << msg; | ||
2896 | 173 | reply_ = message_.createErrorReply(QString(DBUS_ERROR_PREFIX) + "UnknownException", msg); | ||
2897 | 174 | } | ||
2898 | 175 | } | ||
2899 | 176 | |||
2900 | 106 | } | 177 | } |
2901 | 107 | } | 178 | } |
2902 | 108 | } | 179 | } |
2903 | 109 | 180 | ||
2904 | === modified file 'src/provider/internal/MainLoopExecutor.cpp' | |||
2905 | --- src/provider/internal/MainLoopExecutor.cpp 2016-07-19 03:29:15 +0000 | |||
2906 | +++ src/provider/internal/MainLoopExecutor.cpp 2016-09-09 02:13:43 +0000 | |||
2907 | @@ -23,8 +23,6 @@ | |||
2908 | 23 | 23 | ||
2909 | 24 | #include <stdexcept> | 24 | #include <stdexcept> |
2910 | 25 | 25 | ||
2911 | 26 | #ifdef SF_SUPPORTS_EXECUTORS | ||
2912 | 27 | |||
2913 | 28 | namespace { | 26 | namespace { |
2914 | 29 | 27 | ||
2915 | 30 | class WorkEvent : public QEvent { | 28 | class WorkEvent : public QEvent { |
2916 | @@ -107,5 +105,3 @@ | |||
2917 | 107 | } | 105 | } |
2918 | 108 | } | 106 | } |
2919 | 109 | } | 107 | } |
2920 | 110 | |||
2921 | 111 | #endif /* SF_SUPPORTS_EXECUTORS */ | ||
2922 | 112 | 108 | ||
2923 | === modified file 'src/provider/internal/PendingJobs.cpp' | |||
2924 | --- src/provider/internal/PendingJobs.cpp 2016-07-19 03:26:36 +0000 | |||
2925 | +++ src/provider/internal/PendingJobs.cpp 2016-09-09 02:13:43 +0000 | |||
2926 | @@ -18,6 +18,7 @@ | |||
2927 | 18 | 18 | ||
2928 | 19 | #include <unity/storage/provider/internal/PendingJobs.h> | 19 | #include <unity/storage/provider/internal/PendingJobs.h> |
2929 | 20 | #include <unity/storage/provider/DownloadJob.h> | 20 | #include <unity/storage/provider/DownloadJob.h> |
2930 | 21 | #include <unity/storage/provider/Exceptions.h> | ||
2931 | 21 | #include <unity/storage/provider/UploadJob.h> | 22 | #include <unity/storage/provider/UploadJob.h> |
2932 | 22 | #include <unity/storage/provider/internal/DownloadJobImpl.h> | 23 | #include <unity/storage/provider/internal/DownloadJobImpl.h> |
2933 | 23 | #include <unity/storage/provider/internal/MainLoopExecutor.h> | 24 | #include <unity/storage/provider/internal/MainLoopExecutor.h> |
2934 | @@ -47,67 +48,79 @@ | |||
2935 | 47 | this, &PendingJobs::service_disconnected); | 48 | this, &PendingJobs::service_disconnected); |
2936 | 48 | } | 49 | } |
2937 | 49 | 50 | ||
2939 | 50 | PendingJobs::~PendingJobs() = default; | 51 | PendingJobs::~PendingJobs() |
2940 | 52 | { | ||
2941 | 53 | for (const auto& pair : downloads_) | ||
2942 | 54 | { | ||
2943 | 55 | cancel_job(pair.second, "download " + pair.second->download_id()); | ||
2944 | 56 | } | ||
2945 | 57 | for (const auto& pair : uploads_) | ||
2946 | 58 | { | ||
2947 | 59 | cancel_job(pair.second, "upload " + pair.second->upload_id()); | ||
2948 | 60 | } | ||
2949 | 61 | } | ||
2950 | 51 | 62 | ||
2952 | 52 | void PendingJobs::add_download(unique_ptr<DownloadJob> &&job) | 63 | void PendingJobs::add_download(QString const& client_bus_name, |
2953 | 64 | unique_ptr<DownloadJob> &&job) | ||
2954 | 53 | { | 65 | { |
2955 | 54 | lock_guard<mutex> guard(lock_); | 66 | lock_guard<mutex> guard(lock_); |
2956 | 55 | 67 | ||
2959 | 56 | assert(!job->p_->sender_bus_name().empty()); | 68 | assert(!client_bus_name.isEmpty() && client_bus_name[0] == ':'); |
2960 | 57 | assert(downloads_.find(job->download_id()) == downloads_.end()); | 69 | const auto job_id = make_pair(client_bus_name, job->download_id()); |
2961 | 70 | assert(downloads_.find(job_id) == downloads_.end()); | ||
2962 | 58 | 71 | ||
2963 | 59 | shared_ptr<DownloadJob> j(std::move(job)); | 72 | shared_ptr<DownloadJob> j(std::move(job)); |
2982 | 60 | downloads_.emplace(j->download_id(), j); | 73 | downloads_.emplace(job_id, j); |
2983 | 61 | watch_peer(j->p_->sender_bus_name()); | 74 | watch_peer(client_bus_name); |
2984 | 62 | } | 75 | } |
2985 | 63 | 76 | ||
2986 | 64 | std::shared_ptr<DownloadJob> PendingJobs::get_download(std::string const& download_id) | 77 | shared_ptr<DownloadJob> PendingJobs::remove_download(QString const& client_bus_name, |
2987 | 65 | { | 78 | string const& download_id) |
2988 | 66 | lock_guard<mutex> guard(lock_); | 79 | { |
2989 | 67 | 80 | lock_guard<mutex> guard(lock_); | |
2990 | 68 | return downloads_.at(download_id); | 81 | |
2991 | 69 | } | 82 | auto it = downloads_.find({client_bus_name, download_id}); |
2992 | 70 | 83 | if (it == downloads_.cend()) | |
2993 | 71 | std::shared_ptr<DownloadJob> PendingJobs::remove_download(std::string const& download_id) | 84 | { |
2994 | 72 | { | 85 | throw LogicException("No such download: " + download_id); |
2995 | 73 | lock_guard<mutex> guard(lock_); | 86 | } |
2996 | 74 | 87 | auto job = it->second; | |
2997 | 75 | auto job = downloads_.at(download_id); | 88 | downloads_.erase(it); |
2998 | 76 | downloads_.erase(download_id); | 89 | unwatch_peer(client_bus_name); |
2981 | 77 | unwatch_peer(job->p_->sender_bus_name()); | ||
2999 | 78 | return job; | 90 | return job; |
3000 | 79 | } | 91 | } |
3001 | 80 | 92 | ||
3003 | 81 | void PendingJobs::add_upload(unique_ptr<UploadJob> &&job) | 93 | void PendingJobs::add_upload(QString const& client_bus_name, |
3004 | 94 | unique_ptr<UploadJob> &&job) | ||
3005 | 82 | { | 95 | { |
3006 | 83 | lock_guard<mutex> guard(lock_); | 96 | lock_guard<mutex> guard(lock_); |
3007 | 84 | 97 | ||
3010 | 85 | assert(!job->p_->sender_bus_name().empty()); | 98 | assert(!client_bus_name.isEmpty() && client_bus_name[0] == ':'); |
3011 | 86 | assert(uploads_.find(job->upload_id()) == uploads_.end()); | 99 | const auto job_id = make_pair(client_bus_name, job->upload_id()); |
3012 | 100 | assert(uploads_.find(job_id) == uploads_.end()); | ||
3013 | 87 | 101 | ||
3014 | 88 | shared_ptr<UploadJob> j(std::move(job)); | 102 | shared_ptr<UploadJob> j(std::move(job)); |
3033 | 89 | uploads_.emplace(j->upload_id(), j); | 103 | uploads_.emplace(job_id, j); |
3034 | 90 | watch_peer(j->p_->sender_bus_name()); | 104 | watch_peer(client_bus_name); |
3035 | 91 | } | 105 | } |
3036 | 92 | 106 | ||
3037 | 93 | std::shared_ptr<UploadJob> PendingJobs::get_upload(std::string const& upload_id) | 107 | shared_ptr<UploadJob> PendingJobs::remove_upload(QString const& client_bus_name, |
3038 | 94 | { | 108 | string const& upload_id) |
3039 | 95 | lock_guard<mutex> guard(lock_); | 109 | { |
3040 | 96 | 110 | lock_guard<mutex> guard(lock_); | |
3041 | 97 | return uploads_.at(upload_id); | 111 | |
3042 | 98 | } | 112 | auto it = uploads_.find({client_bus_name, upload_id}); |
3043 | 99 | 113 | if (it == uploads_.cend()) | |
3044 | 100 | std::shared_ptr<UploadJob> PendingJobs::remove_upload(std::string const& upload_id) | 114 | { |
3045 | 101 | { | 115 | throw LogicException("No such upload: " + upload_id); |
3046 | 102 | lock_guard<mutex> guard(lock_); | 116 | } |
3047 | 103 | 117 | auto job = it->second; | |
3048 | 104 | auto job = uploads_.at(upload_id); | 118 | uploads_.erase(it); |
3049 | 105 | uploads_.erase(upload_id); | 119 | unwatch_peer(client_bus_name); |
3032 | 106 | unwatch_peer(job->p_->sender_bus_name()); | ||
3050 | 107 | return job; | 120 | return job; |
3051 | 108 | } | 121 | } |
3052 | 109 | 122 | ||
3054 | 110 | void PendingJobs::watch_peer(string const& bus_name) | 123 | void PendingJobs::watch_peer(QString const& bus_name) |
3055 | 111 | { | 124 | { |
3056 | 112 | auto it = services_.find(bus_name); | 125 | auto it = services_.find(bus_name); |
3057 | 113 | if (it != services_.end()) | 126 | if (it != services_.end()) |
3058 | @@ -116,12 +129,12 @@ | |||
3059 | 116 | } | 129 | } |
3060 | 117 | else | 130 | else |
3061 | 118 | { | 131 | { |
3063 | 119 | watcher_.addWatchedService(QString::fromStdString(bus_name)); | 132 | watcher_.addWatchedService(bus_name); |
3064 | 120 | services_[bus_name] = 1; | 133 | services_[bus_name] = 1; |
3065 | 121 | } | 134 | } |
3066 | 122 | } | 135 | } |
3067 | 123 | 136 | ||
3069 | 124 | void PendingJobs::unwatch_peer(string const& bus_name) | 137 | void PendingJobs::unwatch_peer(QString const& bus_name) |
3070 | 125 | { | 138 | { |
3071 | 126 | auto it = services_.find(bus_name); | 139 | auto it = services_.find(bus_name); |
3072 | 127 | if (it == services_.end()) | 140 | if (it == services_.end()) |
3073 | @@ -132,72 +145,62 @@ | |||
3074 | 132 | if (it->second == 0) | 145 | if (it->second == 0) |
3075 | 133 | { | 146 | { |
3076 | 134 | services_.erase(it); | 147 | services_.erase(it); |
3078 | 135 | watcher_.removeWatchedService(QString::fromStdString(bus_name)); | 148 | watcher_.removeWatchedService(bus_name); |
3079 | 136 | } | 149 | } |
3080 | 137 | } | 150 | } |
3081 | 138 | 151 | ||
3082 | 139 | void PendingJobs::service_disconnected(QString const& service_name) | 152 | void PendingJobs::service_disconnected(QString const& service_name) |
3083 | 140 | { | 153 | { |
3084 | 141 | lock_guard<mutex> guard(lock_); | 154 | lock_guard<mutex> guard(lock_); |
3144 | 142 | string const bus_name = service_name.toStdString(); | 155 | |
3145 | 143 | 156 | services_.erase(service_name); | |
3146 | 144 | for (auto it = downloads_.cbegin(); it != downloads_.cend(); ) | 157 | watcher_.removeWatchedService(service_name); |
3147 | 145 | { | 158 | |
3148 | 146 | if (it->second->p_->sender_bus_name() == bus_name) | 159 | const auto lower = make_pair(service_name, string()); |
3149 | 147 | { | 160 | |
3150 | 148 | auto job = it->second; | 161 | for (auto it = downloads_.lower_bound(lower); |
3151 | 149 | it = downloads_.erase(it); | 162 | it != downloads_.cend() && it->first.first == service_name; ) |
3152 | 150 | auto f = job->p_->cancel(*job); | 163 | { |
3153 | 151 | // This continuation also ensures that the job remains | 164 | auto job = it->second; |
3154 | 152 | // alive until the cancel method has completed. | 165 | it = downloads_.erase(it); |
3155 | 153 | f.then( | 166 | cancel_job(job, "download " + job->download_id()); |
3156 | 154 | EXEC_IN_MAIN | 167 | } |
3157 | 155 | [job](decltype(f) f) { | 168 | |
3158 | 156 | try | 169 | for (auto it = uploads_.lower_bound(lower); |
3159 | 157 | { | 170 | it != uploads_.cend() && it->first.first == service_name; ) |
3160 | 158 | f.get(); | 171 | { |
3161 | 159 | } | 172 | auto job = it->second; |
3162 | 160 | catch (std::exception const& e) | 173 | it = uploads_.erase(it); |
3163 | 161 | { | 174 | cancel_job(job, "upload " + job->upload_id()); |
3164 | 162 | fprintf(stderr, "Error cancelling download job '%s': %s\n", | 175 | } |
3165 | 163 | job->download_id().c_str(), e.what()); | 176 | } |
3166 | 164 | } | 177 | |
3167 | 165 | }); | 178 | template<typename Job> |
3168 | 166 | } | 179 | void PendingJobs::cancel_job(shared_ptr<Job> const& job, string const& identifier) |
3169 | 167 | else | 180 | { |
3170 | 168 | { | 181 | auto f = job->p_->cancel(*job); |
3171 | 169 | ++it; | 182 | // This continuation also ensures that the job remains |
3172 | 170 | } | 183 | // alive until the cancel method has completed. |
3173 | 171 | } | 184 | auto cancel_future = std::make_shared<boost::future<void>>(); |
3174 | 172 | 185 | *cancel_future = f.then( | |
3175 | 173 | for (auto it = uploads_.cbegin(); it != uploads_.cend(); ) | 186 | EXEC_IN_MAIN |
3176 | 174 | { | 187 | [job, identifier, cancel_future](decltype(f) f) { |
3177 | 175 | if (it->second->p_->sender_bus_name() == bus_name) | 188 | try |
3178 | 176 | { | 189 | { |
3179 | 177 | auto job = it->second; | 190 | f.get(); |
3180 | 178 | it = uploads_.erase(it); | 191 | } |
3181 | 179 | auto f = job->p_->cancel(*job); | 192 | catch (std::exception const& e) |
3182 | 180 | // This continuation also ensures that the job remains | 193 | { |
3183 | 181 | // alive until the cancel method has completed. | 194 | fprintf(stderr, "Error cancelling job '%s': %s\n", |
3184 | 182 | f.then( | 195 | identifier.c_str(), e.what()); |
3185 | 183 | EXEC_IN_MAIN | 196 | } |
3186 | 184 | [job](decltype(f) f) { | 197 | |
3187 | 185 | try | 198 | // Break the reference cycle between the continuation |
3188 | 186 | { | 199 | // future and closure, while making sure the future |
3189 | 187 | f.get(); | 200 | // survives long enough to be marked ready. |
3190 | 188 | } | 201 | auto fut = std::make_shared<boost::future<void>>(std::move(*cancel_future)); |
3191 | 189 | catch (std::exception const& e) | 202 | MainLoopExecutor::instance().submit([fut]{}); |
3192 | 190 | { | 203 | }); |
3134 | 191 | fprintf(stderr, "Error cancelling upload job '%s': %s\n", | ||
3135 | 192 | job->upload_id().c_str(), e.what()); | ||
3136 | 193 | } | ||
3137 | 194 | }); | ||
3138 | 195 | } | ||
3139 | 196 | else | ||
3140 | 197 | { | ||
3141 | 198 | ++it; | ||
3142 | 199 | } | ||
3143 | 200 | } | ||
3193 | 201 | } | 204 | } |
3194 | 202 | 205 | ||
3195 | 203 | } | 206 | } |
3196 | 204 | 207 | ||
3197 | === modified file 'src/provider/internal/ProviderInterface.cpp' | |||
3198 | --- src/provider/internal/ProviderInterface.cpp 2016-07-21 12:48:40 +0000 | |||
3199 | +++ src/provider/internal/ProviderInterface.cpp 2016-09-09 02:13:43 +0000 | |||
3200 | @@ -18,6 +18,7 @@ | |||
3201 | 18 | 18 | ||
3202 | 19 | #include <unity/storage/provider/internal/ProviderInterface.h> | 19 | #include <unity/storage/provider/internal/ProviderInterface.h> |
3203 | 20 | #include <unity/storage/provider/DownloadJob.h> | 20 | #include <unity/storage/provider/DownloadJob.h> |
3204 | 21 | #include <unity/storage/provider/Exceptions.h> | ||
3205 | 21 | #include <unity/storage/provider/ProviderBase.h> | 22 | #include <unity/storage/provider/ProviderBase.h> |
3206 | 22 | #include <unity/storage/provider/UploadJob.h> | 23 | #include <unity/storage/provider/UploadJob.h> |
3207 | 23 | #include <unity/storage/provider/internal/AccountData.h> | 24 | #include <unity/storage/provider/internal/AccountData.h> |
3208 | @@ -171,15 +172,13 @@ | |||
3209 | 171 | EXEC_IN_MAIN | 172 | EXEC_IN_MAIN |
3210 | 172 | [account, message](decltype(f) f) -> QDBusMessage { | 173 | [account, message](decltype(f) f) -> QDBusMessage { |
3211 | 173 | auto job = f.get(); | 174 | auto job = f.get(); |
3212 | 174 | job->p_->set_sender_bus_name(message.service().toStdString()); | ||
3213 | 175 | |||
3214 | 176 | auto upload_id = QString::fromStdString(job->upload_id()); | 175 | auto upload_id = QString::fromStdString(job->upload_id()); |
3215 | 177 | QDBusUnixFileDescriptor file_desc; | 176 | QDBusUnixFileDescriptor file_desc; |
3216 | 178 | int fd = job->p_->take_write_socket(); | 177 | int fd = job->p_->take_write_socket(); |
3217 | 179 | file_desc.setFileDescriptor(fd); | 178 | file_desc.setFileDescriptor(fd); |
3218 | 180 | close(fd); | 179 | close(fd); |
3219 | 181 | 180 | ||
3221 | 182 | account->jobs().add_upload(std::move(job)); | 181 | account->jobs().add_upload(message.service(), std::move(job)); |
3222 | 183 | return message.createReply({ | 182 | return message.createReply({ |
3223 | 184 | QVariant(upload_id), | 183 | QVariant(upload_id), |
3224 | 185 | QVariant::fromValue(file_desc), | 184 | QVariant::fromValue(file_desc), |
3225 | @@ -198,15 +197,13 @@ | |||
3226 | 198 | EXEC_IN_MAIN | 197 | EXEC_IN_MAIN |
3227 | 199 | [account, message](decltype(f) f) -> QDBusMessage { | 198 | [account, message](decltype(f) f) -> QDBusMessage { |
3228 | 200 | auto job = f.get(); | 199 | auto job = f.get(); |
3229 | 201 | job->p_->set_sender_bus_name(message.service().toStdString()); | ||
3230 | 202 | |||
3231 | 203 | auto upload_id = QString::fromStdString(job->upload_id()); | 200 | auto upload_id = QString::fromStdString(job->upload_id()); |
3232 | 204 | QDBusUnixFileDescriptor file_desc; | 201 | QDBusUnixFileDescriptor file_desc; |
3233 | 205 | int fd = job->p_->take_write_socket(); | 202 | int fd = job->p_->take_write_socket(); |
3234 | 206 | file_desc.setFileDescriptor(fd); | 203 | file_desc.setFileDescriptor(fd); |
3235 | 207 | close(fd); | 204 | close(fd); |
3236 | 208 | 205 | ||
3238 | 209 | account->jobs().add_upload(std::move(job)); | 206 | account->jobs().add_upload(message.service(), std::move(job)); |
3239 | 210 | return message.createReply({ | 207 | return message.createReply({ |
3240 | 211 | QVariant(upload_id), | 208 | QVariant(upload_id), |
3241 | 212 | QVariant::fromValue(file_desc), | 209 | QVariant::fromValue(file_desc), |
3242 | @@ -219,15 +216,10 @@ | |||
3243 | 219 | ProviderInterface::IMD ProviderInterface::FinishUpload(QString const& upload_id) | 216 | ProviderInterface::IMD ProviderInterface::FinishUpload(QString const& upload_id) |
3244 | 220 | { | 217 | { |
3245 | 221 | queue_request([upload_id](shared_ptr<AccountData> const& account, Context const& /*ctx*/, QDBusMessage const& message) { | 218 | queue_request([upload_id](shared_ptr<AccountData> const& account, Context const& /*ctx*/, QDBusMessage const& message) { |
3246 | 222 | // Throws if job is not available | ||
3247 | 223 | auto job = account->jobs().get_upload(upload_id.toStdString()); | ||
3248 | 224 | if (job->p_->sender_bus_name() != message.service().toStdString()) | ||
3249 | 225 | { | ||
3250 | 226 | throw runtime_error("Upload job belongs to a different client"); | ||
3251 | 227 | } | ||
3252 | 228 | // FIXME: removing the job at this point means we can't | 219 | // FIXME: removing the job at this point means we can't |
3253 | 229 | // cancel during finish(). | 220 | // cancel during finish(). |
3255 | 230 | account->jobs().remove_upload(upload_id.toStdString()); | 221 | // Throws if job is not available |
3256 | 222 | auto job = account->jobs().remove_upload(message.service(), upload_id.toStdString()); | ||
3257 | 231 | auto f = job->p_->finish(*job); | 223 | auto f = job->p_->finish(*job); |
3258 | 232 | return f.then( | 224 | return f.then( |
3259 | 233 | EXEC_IN_MAIN | 225 | EXEC_IN_MAIN |
3260 | @@ -243,12 +235,7 @@ | |||
3261 | 243 | { | 235 | { |
3262 | 244 | queue_request([upload_id](shared_ptr<AccountData> const& account, Context const& /*ctx*/, QDBusMessage const& message) { | 236 | queue_request([upload_id](shared_ptr<AccountData> const& account, Context const& /*ctx*/, QDBusMessage const& message) { |
3263 | 245 | // Throws if job is not available | 237 | // Throws if job is not available |
3270 | 246 | auto job = account->jobs().get_upload(upload_id.toStdString()); | 238 | auto job = account->jobs().remove_upload(message.service(), upload_id.toStdString()); |
3265 | 247 | if (job->p_->sender_bus_name() != message.service().toStdString()) | ||
3266 | 248 | { | ||
3267 | 249 | throw runtime_error("Upload job belongs to a different client"); | ||
3268 | 250 | } | ||
3269 | 251 | account->jobs().remove_upload(upload_id.toStdString()); | ||
3271 | 252 | auto f = job->p_->cancel(*job); | 239 | auto f = job->p_->cancel(*job); |
3272 | 253 | return f.then( | 240 | return f.then( |
3273 | 254 | EXEC_IN_MAIN | 241 | EXEC_IN_MAIN |
3274 | @@ -268,15 +255,13 @@ | |||
3275 | 268 | EXEC_IN_MAIN | 255 | EXEC_IN_MAIN |
3276 | 269 | [account, message](decltype(f) f) -> QDBusMessage { | 256 | [account, message](decltype(f) f) -> QDBusMessage { |
3277 | 270 | auto job = f.get(); | 257 | auto job = f.get(); |
3278 | 271 | job->p_->set_sender_bus_name(message.service().toStdString()); | ||
3279 | 272 | |||
3280 | 273 | auto download_id = QString::fromStdString(job->download_id()); | 258 | auto download_id = QString::fromStdString(job->download_id()); |
3281 | 274 | QDBusUnixFileDescriptor file_desc; | 259 | QDBusUnixFileDescriptor file_desc; |
3282 | 275 | int fd = job->p_->take_read_socket(); | 260 | int fd = job->p_->take_read_socket(); |
3283 | 276 | file_desc.setFileDescriptor(fd); | 261 | file_desc.setFileDescriptor(fd); |
3284 | 277 | close(fd); | 262 | close(fd); |
3285 | 278 | 263 | ||
3287 | 279 | account->jobs().add_download(std::move(job)); | 264 | account->jobs().add_download(message.service(), std::move(job)); |
3288 | 280 | return message.createReply({ | 265 | return message.createReply({ |
3289 | 281 | QVariant(download_id), | 266 | QVariant(download_id), |
3290 | 282 | QVariant::fromValue(file_desc), | 267 | QVariant::fromValue(file_desc), |
3291 | @@ -289,15 +274,10 @@ | |||
3292 | 289 | void ProviderInterface::FinishDownload(QString const& download_id) | 274 | void ProviderInterface::FinishDownload(QString const& download_id) |
3293 | 290 | { | 275 | { |
3294 | 291 | queue_request([download_id](shared_ptr<AccountData> const& account, Context const& /*ctx*/, QDBusMessage const& message) { | 276 | queue_request([download_id](shared_ptr<AccountData> const& account, Context const& /*ctx*/, QDBusMessage const& message) { |
3295 | 292 | // Throws if job is not available | ||
3296 | 293 | auto job = account->jobs().get_download(download_id.toStdString()); | ||
3297 | 294 | if (job->p_->sender_bus_name() != message.service().toStdString()) | ||
3298 | 295 | { | ||
3299 | 296 | throw runtime_error("Download job belongs to a different client"); | ||
3300 | 297 | } | ||
3301 | 298 | // FIXME: removing the job at this point means we can't | 277 | // FIXME: removing the job at this point means we can't |
3302 | 299 | // cancel during finish(). | 278 | // cancel during finish(). |
3304 | 300 | account->jobs().remove_download(download_id.toStdString()); | 279 | // Throws if job is not available |
3305 | 280 | auto job = account->jobs().remove_download(message.service(), download_id.toStdString()); | ||
3306 | 301 | auto f = job->p_->finish(*job); | 281 | auto f = job->p_->finish(*job); |
3307 | 302 | return f.then( | 282 | return f.then( |
3308 | 303 | EXEC_IN_MAIN | 283 | EXEC_IN_MAIN |
3309 | 304 | 284 | ||
3310 | === modified file 'src/provider/internal/ServerImpl.cpp' | |||
3311 | --- src/provider/internal/ServerImpl.cpp 2016-07-21 04:00:29 +0000 | |||
3312 | +++ src/provider/internal/ServerImpl.cpp 2016-09-09 02:13:43 +0000 | |||
3313 | @@ -17,6 +17,7 @@ | |||
3314 | 17 | */ | 17 | */ |
3315 | 18 | 18 | ||
3316 | 19 | #include <unity/storage/provider/internal/ServerImpl.h> | 19 | #include <unity/storage/provider/internal/ServerImpl.h> |
3317 | 20 | #include <unity/storage/provider/Exceptions.h> | ||
3318 | 20 | #include <unity/storage/provider/ProviderBase.h> | 21 | #include <unity/storage/provider/ProviderBase.h> |
3319 | 21 | #include <unity/storage/provider/internal/AccountData.h> | 22 | #include <unity/storage/provider/internal/AccountData.h> |
3320 | 22 | #include <unity/storage/provider/internal/MainLoopExecutor.h> | 23 | #include <unity/storage/provider/internal/MainLoopExecutor.h> |
3321 | @@ -37,7 +38,10 @@ | |||
3322 | 37 | { | 38 | { |
3323 | 38 | 39 | ||
3324 | 39 | ServerImpl::ServerImpl(ServerBase* server, string const& bus_name, string const& account_service_id) | 40 | ServerImpl::ServerImpl(ServerBase* server, string const& bus_name, string const& account_service_id) |
3326 | 40 | : server_(server), bus_name_(bus_name), service_id_(account_service_id) | 41 | : server_(server) |
3327 | 42 | , bus_name_(bus_name) | ||
3328 | 43 | , service_id_(account_service_id) | ||
3329 | 44 | , trace_message_handler_("storage_provider") | ||
3330 | 41 | { | 45 | { |
3331 | 42 | qDBusRegisterMetaType<Item>(); | 46 | qDBusRegisterMetaType<Item>(); |
3332 | 43 | qDBusRegisterMetaType<std::vector<Item>>(); | 47 | qDBusRegisterMetaType<std::vector<Item>>(); |
3333 | @@ -85,7 +89,8 @@ | |||
3334 | 85 | 89 | ||
3335 | 86 | if (!bus.registerService(QString::fromStdString(bus_name_))) | 90 | if (!bus.registerService(QString::fromStdString(bus_name_))) |
3336 | 87 | { | 91 | { |
3338 | 88 | throw runtime_error("Could not acquire bus name: " + bus_name_); | 92 | string msg = string("Could not acquire bus name: ") + bus_name_ + ": " + bus.lastError().message().toStdString(); |
3339 | 93 | throw ResourceException(msg, int(bus.lastError().type())); | ||
3340 | 89 | } | 94 | } |
3341 | 90 | // TODO: claim bus name | 95 | // TODO: claim bus name |
3342 | 91 | qDebug() << "Bus unique name:" << bus.baseService(); | 96 | qDebug() << "Bus unique name:" << bus.baseService(); |
3343 | 92 | 97 | ||
3344 | === modified file 'src/provider/internal/TempfileUploadJobImpl.cpp' | |||
3345 | --- src/provider/internal/TempfileUploadJobImpl.cpp 2016-07-12 02:22:05 +0000 | |||
3346 | +++ src/provider/internal/TempfileUploadJobImpl.cpp 2016-09-09 02:13:43 +0000 | |||
3347 | @@ -17,9 +17,10 @@ | |||
3348 | 17 | */ | 17 | */ |
3349 | 18 | 18 | ||
3350 | 19 | #include <unity/storage/provider/internal/TempfileUploadJobImpl.h> | 19 | #include <unity/storage/provider/internal/TempfileUploadJobImpl.h> |
3351 | 20 | #include <unity/storage/provider/Exceptions.h> | ||
3352 | 20 | 21 | ||
3353 | 21 | #include <cassert> | 22 | #include <cassert> |
3355 | 22 | #include <stdexcept> | 23 | #include <exception> |
3356 | 23 | 24 | ||
3357 | 24 | using namespace std; | 25 | using namespace std; |
3358 | 25 | 26 | ||
3359 | @@ -64,6 +65,25 @@ | |||
3360 | 64 | return tmpfile_->fileName().toStdString(); | 65 | return tmpfile_->fileName().toStdString(); |
3361 | 65 | } | 66 | } |
3362 | 66 | 67 | ||
3363 | 68 | void TempfileUploadJobImpl::drain() | ||
3364 | 69 | { | ||
3365 | 70 | while (true) | ||
3366 | 71 | { | ||
3367 | 72 | if (!tmpfile_->isOpen()) | ||
3368 | 73 | { | ||
3369 | 74 | break; | ||
3370 | 75 | } | ||
3371 | 76 | if (!reader_->waitForReadyRead(0)) | ||
3372 | 77 | { | ||
3373 | 78 | // Nothing was available to read: is the read channel still open? | ||
3374 | 79 | if (tmpfile_->isOpen()) | ||
3375 | 80 | { | ||
3376 | 81 | throw LogicException("Socket not closed"); | ||
3377 | 82 | } | ||
3378 | 83 | } | ||
3379 | 84 | } | ||
3380 | 85 | } | ||
3381 | 86 | |||
3382 | 67 | void TempfileUploadJobImpl::on_ready_read() | 87 | void TempfileUploadJobImpl::on_ready_read() |
3383 | 68 | { | 88 | { |
3384 | 69 | char buffer[4096]; | 89 | char buffer[4096]; |
3385 | 70 | 90 | ||
3386 | === added file 'src/provider/internal/TestServerImpl.cpp' | |||
3387 | --- src/provider/internal/TestServerImpl.cpp 1970-01-01 00:00:00 +0000 | |||
3388 | +++ src/provider/internal/TestServerImpl.cpp 2016-09-09 02:13:43 +0000 | |||
3389 | @@ -0,0 +1,84 @@ | |||
3390 | 1 | /* | ||
3391 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
3392 | 3 | * | ||
3393 | 4 | * This program is free software: you can redistribute it and/or modify | ||
3394 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
3395 | 6 | * published by the Free Software Foundation. | ||
3396 | 7 | * | ||
3397 | 8 | * This program is distributed in the hope that it will be useful, | ||
3398 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3399 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3400 | 11 | * GNU Lesser General Public License for more details. | ||
3401 | 12 | * | ||
3402 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3403 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3404 | 15 | * | ||
3405 | 16 | * Authors: James Henstridge <james.henstridge@canonical.com> | ||
3406 | 17 | */ | ||
3407 | 18 | |||
3408 | 19 | #include <unity/storage/provider/internal/TestServerImpl.h> | ||
3409 | 20 | #include <unity/storage/provider/Exceptions.h> | ||
3410 | 21 | #include <unity/storage/provider/ProviderBase.h> | ||
3411 | 22 | #include <unity/storage/provider/internal/AccountData.h> | ||
3412 | 23 | #include <unity/storage/provider/internal/DBusPeerCache.h> | ||
3413 | 24 | #include <unity/storage/provider/internal/ProviderInterface.h> | ||
3414 | 25 | #include <unity/storage/provider/internal/dbusmarshal.h> | ||
3415 | 26 | #include "provideradaptor.h" | ||
3416 | 27 | |||
3417 | 28 | #include <OnlineAccounts/Account> | ||
3418 | 29 | |||
3419 | 30 | #include <stdexcept> | ||
3420 | 31 | |||
3421 | 32 | using namespace std; | ||
3422 | 33 | |||
3423 | 34 | namespace unity | ||
3424 | 35 | { | ||
3425 | 36 | namespace storage | ||
3426 | 37 | { | ||
3427 | 38 | namespace provider | ||
3428 | 39 | { | ||
3429 | 40 | namespace internal | ||
3430 | 41 | { | ||
3431 | 42 | |||
3432 | 43 | TestServerImpl::TestServerImpl(unique_ptr<ProviderBase>&& provider, | ||
3433 | 44 | OnlineAccounts::Account* account, | ||
3434 | 45 | QDBusConnection const& connection, | ||
3435 | 46 | string const& object_path) | ||
3436 | 47 | : connection_(connection), object_path_(object_path) | ||
3437 | 48 | { | ||
3438 | 49 | qDBusRegisterMetaType<Item>(); | ||
3439 | 50 | qDBusRegisterMetaType<std::vector<Item>>(); | ||
3440 | 51 | |||
3441 | 52 | auto peer_cache = make_shared<DBusPeerCache>(connection_); | ||
3442 | 53 | auto account_data = make_shared<AccountData>( | ||
3443 | 54 | move(provider), peer_cache, connection_, account); | ||
3444 | 55 | interface_.reset(new ProviderInterface(account_data)); | ||
3445 | 56 | new ProviderAdaptor(interface_.get()); | ||
3446 | 57 | |||
3447 | 58 | if (!connection_.registerObject(QString::fromStdString(object_path_), | ||
3448 | 59 | interface_.get())) | ||
3449 | 60 | { | ||
3450 | 61 | string msg = "Could not register provider on connection: " + connection_.lastError().message().toStdString(); | ||
3451 | 62 | throw ResourceException(msg, int(connection_.lastError().type())); | ||
3452 | 63 | } | ||
3453 | 64 | } | ||
3454 | 65 | |||
3455 | 66 | TestServerImpl::~TestServerImpl() | ||
3456 | 67 | { | ||
3457 | 68 | connection_.unregisterObject(QString::fromStdString(object_path_)); | ||
3458 | 69 | } | ||
3459 | 70 | |||
3460 | 71 | QDBusConnection const& TestServerImpl::connection() const | ||
3461 | 72 | { | ||
3462 | 73 | return connection_; | ||
3463 | 74 | } | ||
3464 | 75 | |||
3465 | 76 | string const& TestServerImpl::object_path() const | ||
3466 | 77 | { | ||
3467 | 78 | return object_path_; | ||
3468 | 79 | } | ||
3469 | 80 | |||
3470 | 81 | } | ||
3471 | 82 | } | ||
3472 | 83 | } | ||
3473 | 84 | } | ||
3474 | 0 | 85 | ||
3475 | === modified file 'src/provider/internal/UploadJobImpl.cpp' | |||
3476 | --- src/provider/internal/UploadJobImpl.cpp 2016-07-12 02:22:05 +0000 | |||
3477 | +++ src/provider/internal/UploadJobImpl.cpp 2016-09-09 02:13:43 +0000 | |||
3478 | @@ -17,7 +17,10 @@ | |||
3479 | 17 | */ | 17 | */ |
3480 | 18 | 18 | ||
3481 | 19 | #include <unity/storage/provider/internal/UploadJobImpl.h> | 19 | #include <unity/storage/provider/internal/UploadJobImpl.h> |
3482 | 20 | #include <unity/storage/internal/safe_strerror.h> | ||
3483 | 21 | #include <unity/storage/provider/Exceptions.h> | ||
3484 | 20 | #include <unity/storage/provider/UploadJob.h> | 22 | #include <unity/storage/provider/UploadJob.h> |
3485 | 23 | #include <unity/storage/provider/internal/MainLoopExecutor.h> | ||
3486 | 21 | 24 | ||
3487 | 22 | #include <sys/socket.h> | 25 | #include <sys/socket.h> |
3488 | 23 | #include <sys/types.h> | 26 | #include <sys/types.h> |
3489 | @@ -26,6 +29,7 @@ | |||
3490 | 26 | #include <stdexcept> | 29 | #include <stdexcept> |
3491 | 27 | 30 | ||
3492 | 28 | using namespace std; | 31 | using namespace std; |
3493 | 32 | using namespace unity::storage::internal; | ||
3494 | 29 | 33 | ||
3495 | 30 | namespace unity | 34 | namespace unity |
3496 | 31 | { | 35 | { |
3497 | @@ -42,18 +46,30 @@ | |||
3498 | 42 | int socks[2]; | 46 | int socks[2]; |
3499 | 43 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, socks) < 0) | 47 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, socks) < 0) |
3500 | 44 | { | 48 | { |
3502 | 45 | throw runtime_error("could not create socketpair"); | 49 | int error_code = errno; |
3503 | 50 | string msg = "could not create socketpair: " + safe_strerror(error_code); | ||
3504 | 51 | throw ResourceException(msg, error_code); | ||
3505 | 46 | } | 52 | } |
3506 | 47 | read_socket_ = socks[0]; | 53 | read_socket_ = socks[0]; |
3507 | 48 | write_socket_ = socks[1]; | 54 | write_socket_ = socks[1]; |
3508 | 55 | |||
3509 | 56 | #if 0 | ||
3510 | 57 | // TODO: We should be able to half-close the write channel of the read socket, and the read channel of | ||
3511 | 58 | // the write socket. But, if we do, QLocalSocket indicates that everything was closed, which causes | ||
3512 | 59 | // failures on the client side. We suspect a QLocalSocket bug -- need to investigate. | ||
3513 | 49 | if (shutdown(read_socket_, SHUT_WR) < 0) | 60 | if (shutdown(read_socket_, SHUT_WR) < 0) |
3514 | 50 | { | 61 | { |
3516 | 51 | throw runtime_error("Could not shut down write channel on read socket"); | 62 | int error_code = errno; |
3517 | 63 | string msg = "could not shut down write channel on read socket: " + safe_strerror(error_code); | ||
3518 | 64 | throw ResourceException(msg, error_code); | ||
3519 | 52 | } | 65 | } |
3520 | 53 | if (shutdown(write_socket_, SHUT_RD) < 0) | 66 | if (shutdown(write_socket_, SHUT_RD) < 0) |
3521 | 54 | { | 67 | { |
3523 | 55 | throw runtime_error("Could not shut down read channel on write socket"); | 68 | int error_code = errno; |
3524 | 69 | string msg = "Could not shut down read channel on write socket" + safe_strerror(error_code); | ||
3525 | 70 | throw ResourceException(msg, error_code); | ||
3526 | 56 | } | 71 | } |
3527 | 72 | #endif | ||
3528 | 57 | } | 73 | } |
3529 | 58 | 74 | ||
3530 | 59 | UploadJobImpl::~UploadJobImpl() | 75 | UploadJobImpl::~UploadJobImpl() |
3531 | @@ -72,7 +88,7 @@ | |||
3532 | 72 | { | 88 | { |
3533 | 73 | } | 89 | } |
3534 | 74 | 90 | ||
3536 | 75 | std::string const& UploadJobImpl::upload_id() const | 91 | string const& UploadJobImpl::upload_id() const |
3537 | 76 | { | 92 | { |
3538 | 77 | return upload_id_; | 93 | return upload_id_; |
3539 | 78 | } | 94 | } |
3540 | @@ -90,28 +106,29 @@ | |||
3541 | 90 | return sock; | 106 | return sock; |
3542 | 91 | } | 107 | } |
3543 | 92 | 108 | ||
3556 | 93 | string const& UploadJobImpl::sender_bus_name() const | 109 | void UploadJobImpl::report_error(exception_ptr p) |
3545 | 94 | { | ||
3546 | 95 | return sender_bus_name_; | ||
3547 | 96 | } | ||
3548 | 97 | |||
3549 | 98 | void UploadJobImpl::set_sender_bus_name(string const& bus_name) | ||
3550 | 99 | { | ||
3551 | 100 | assert(bus_name[0] == ':'); | ||
3552 | 101 | sender_bus_name_ = bus_name; | ||
3553 | 102 | } | ||
3554 | 103 | |||
3555 | 104 | void UploadJobImpl::report_error(std::exception_ptr p) | ||
3557 | 105 | { | 110 | { |
3558 | 106 | if (read_socket_ >= 0) | 111 | if (read_socket_ >= 0) |
3559 | 107 | { | 112 | { |
3561 | 108 | close(write_socket_); | 113 | close(read_socket_); |
3562 | 109 | read_socket_ = -1; | 114 | read_socket_ = -1; |
3563 | 110 | } | 115 | } |
3564 | 111 | 116 | ||
3565 | 112 | lock_guard<mutex> guard(completion_lock_); | 117 | lock_guard<mutex> guard(completion_lock_); |
3566 | 113 | completed_ = true; | 118 | completed_ = true; |
3568 | 114 | completion_promise_.set_exception(p); | 119 | // Convert std::exception_ptr to boost::exception_ptr |
3569 | 120 | try | ||
3570 | 121 | { | ||
3571 | 122 | rethrow_exception(p); | ||
3572 | 123 | } | ||
3573 | 124 | catch (StorageException const& e) | ||
3574 | 125 | { | ||
3575 | 126 | completion_promise_.set_exception(e); | ||
3576 | 127 | } | ||
3577 | 128 | catch (...) | ||
3578 | 129 | { | ||
3579 | 130 | completion_promise_.set_exception(boost::current_exception()); | ||
3580 | 131 | } | ||
3581 | 115 | } | 132 | } |
3582 | 116 | 133 | ||
3583 | 117 | boost::future<Item> UploadJobImpl::finish(UploadJob& job) | 134 | boost::future<Item> UploadJobImpl::finish(UploadJob& job) |
3584 | 118 | 135 | ||
3585 | === modified file 'src/provider/internal/dbusmarshal.cpp' | |||
3586 | --- src/provider/internal/dbusmarshal.cpp 2016-07-21 12:48:40 +0000 | |||
3587 | +++ src/provider/internal/dbusmarshal.cpp 2016-09-09 02:13:43 +0000 | |||
3588 | @@ -31,29 +31,57 @@ | |||
3589 | 31 | namespace provider | 31 | namespace provider |
3590 | 32 | { | 32 | { |
3591 | 33 | 33 | ||
3592 | 34 | namespace | ||
3593 | 35 | { | ||
3594 | 36 | |||
3595 | 37 | QDBusVariant to_qdbus_variant(MetadataValue const& v) | ||
3596 | 38 | { | ||
3597 | 39 | switch (v.which()) | ||
3598 | 40 | { | ||
3599 | 41 | case 0: | ||
3600 | 42 | return QDBusVariant(QString::fromStdString(boost::get<string>(v))); | ||
3601 | 43 | case 1: | ||
3602 | 44 | return QDBusVariant(qlonglong(boost::get<int64_t>(v))); | ||
3603 | 45 | default: | ||
3604 | 46 | abort(); // Impossible. // LCOV_EXCL_LINE | ||
3605 | 47 | } | ||
3606 | 48 | } | ||
3607 | 49 | |||
3608 | 50 | } // namespace | ||
3609 | 51 | |||
3610 | 34 | QDBusArgument& operator<<(QDBusArgument& argument, Item const& item) | 52 | QDBusArgument& operator<<(QDBusArgument& argument, Item const& item) |
3611 | 35 | { | 53 | { |
3612 | 36 | argument.beginStructure(); | 54 | argument.beginStructure(); |
3613 | 37 | argument << QString::fromStdString(item.item_id); | 55 | argument << QString::fromStdString(item.item_id); |
3615 | 38 | argument << QString::fromStdString(item.parent_id); | 56 | { |
3616 | 57 | argument.beginArray(qMetaTypeId<QString>()); | ||
3617 | 58 | for (auto const& id : item.parent_ids) | ||
3618 | 59 | { | ||
3619 | 60 | argument << QString::fromStdString(id); | ||
3620 | 61 | } | ||
3621 | 62 | argument.endArray(); | ||
3622 | 63 | } | ||
3623 | 39 | argument << QString::fromStdString(item.name); | 64 | argument << QString::fromStdString(item.name); |
3624 | 40 | argument << QString::fromStdString(item.etag); | 65 | argument << QString::fromStdString(item.etag); |
3625 | 41 | argument << static_cast<int32_t>(item.type); | 66 | argument << static_cast<int32_t>(item.type); |
3626 | 42 | argument.beginMap(QVariant::String, qMetaTypeId<QDBusVariant>()); | ||
3627 | 43 | for (auto const& pair : item.metadata) | ||
3628 | 44 | { | 67 | { |
3632 | 45 | argument.beginMapEntry(); | 68 | argument.beginMap(QVariant::String, qMetaTypeId<QDBusVariant>()); |
3633 | 46 | argument << QString::fromStdString(pair.first) << QDBusVariant(QString::fromStdString(pair.second)); | 69 | for (auto const& pair : item.metadata) |
3634 | 47 | argument.endMapEntry(); | 70 | { |
3635 | 71 | argument.beginMapEntry(); | ||
3636 | 72 | argument << QString::fromStdString(pair.first) << to_qdbus_variant(pair.second); | ||
3637 | 73 | argument.endMapEntry(); | ||
3638 | 74 | } | ||
3639 | 75 | argument.endMap(); | ||
3640 | 48 | } | 76 | } |
3641 | 49 | argument.endMap(); | ||
3642 | 50 | argument.endStructure(); | 77 | argument.endStructure(); |
3643 | 51 | return argument; | 78 | return argument; |
3644 | 52 | } | 79 | } |
3645 | 53 | 80 | ||
3646 | 54 | QDBusArgument const& operator>>(QDBusArgument const&, Item&) | 81 | QDBusArgument const& operator>>(QDBusArgument const&, Item&) |
3647 | 55 | { | 82 | { |
3649 | 56 | throw std::runtime_error("Item decode not implemented"); | 83 | // We don't expect to ever have to unmarshal anything, only marshal it. |
3650 | 84 | qFatal("unexpected call to operator>>(QDBusArgument const&, Item&)"); // LCOV_EXCL_LINE | ||
3651 | 57 | } | 85 | } |
3652 | 58 | 86 | ||
3653 | 59 | QDBusArgument& operator<<(QDBusArgument& argument, ItemList const& items) | 87 | QDBusArgument& operator<<(QDBusArgument& argument, ItemList const& items) |
3654 | @@ -69,7 +97,8 @@ | |||
3655 | 69 | 97 | ||
3656 | 70 | QDBusArgument const& operator>>(QDBusArgument const&, ItemList&) | 98 | QDBusArgument const& operator>>(QDBusArgument const&, ItemList&) |
3657 | 71 | { | 99 | { |
3659 | 72 | throw std::runtime_error("std::vector<Item> decode not implemented"); | 100 | // We don't expect to ever have to unmarshal anything, only marshal it. |
3660 | 101 | qFatal("unexpected call to operator>>(QDBusArgument const&, ItemList&)"); // LCOV_EXCL_LINE | ||
3661 | 73 | } | 102 | } |
3662 | 74 | 103 | ||
3663 | 75 | } | 104 | } |
3664 | 76 | 105 | ||
3665 | === added directory 'src/provider/testing' | |||
3666 | === added file 'src/provider/testing/TestServer.cpp' | |||
3667 | --- src/provider/testing/TestServer.cpp 1970-01-01 00:00:00 +0000 | |||
3668 | +++ src/provider/testing/TestServer.cpp 2016-09-09 02:13:43 +0000 | |||
3669 | @@ -0,0 +1,60 @@ | |||
3670 | 1 | /* | ||
3671 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
3672 | 3 | * | ||
3673 | 4 | * This program is free software: you can redistribute it and/or modify | ||
3674 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
3675 | 6 | * published by the Free Software Foundation. | ||
3676 | 7 | * | ||
3677 | 8 | * This program is distributed in the hope that it will be useful, | ||
3678 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3679 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3680 | 11 | * GNU Lesser General Public License for more details. | ||
3681 | 12 | * | ||
3682 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3683 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3684 | 15 | * | ||
3685 | 16 | * Authors: James Henstridge <james.henstridge@canonical.com> | ||
3686 | 17 | */ | ||
3687 | 18 | |||
3688 | 19 | #include <unity/storage/provider/testing/TestServer.h> | ||
3689 | 20 | #include <unity/storage/provider/internal/TestServerImpl.h> | ||
3690 | 21 | #include <unity/storage/provider/ProviderBase.h> | ||
3691 | 22 | |||
3692 | 23 | #include <OnlineAccounts/Account> | ||
3693 | 24 | |||
3694 | 25 | using namespace std; | ||
3695 | 26 | |||
3696 | 27 | namespace unity | ||
3697 | 28 | { | ||
3698 | 29 | namespace storage | ||
3699 | 30 | { | ||
3700 | 31 | namespace provider | ||
3701 | 32 | { | ||
3702 | 33 | namespace testing | ||
3703 | 34 | { | ||
3704 | 35 | |||
3705 | 36 | TestServer::TestServer(unique_ptr<ProviderBase>&& provider, | ||
3706 | 37 | OnlineAccounts::Account* account, | ||
3707 | 38 | QDBusConnection const& connection, | ||
3708 | 39 | string const& object_path) | ||
3709 | 40 | : p_(new internal::TestServerImpl(move(provider), account, | ||
3710 | 41 | connection, object_path)) | ||
3711 | 42 | { | ||
3712 | 43 | } | ||
3713 | 44 | |||
3714 | 45 | TestServer::~TestServer() = default; | ||
3715 | 46 | |||
3716 | 47 | QDBusConnection const& TestServer::connection() const | ||
3717 | 48 | { | ||
3718 | 49 | return p_->connection(); | ||
3719 | 50 | } | ||
3720 | 51 | |||
3721 | 52 | string const& TestServer::object_path() const | ||
3722 | 53 | { | ||
3723 | 54 | return p_->object_path(); | ||
3724 | 55 | } | ||
3725 | 56 | |||
3726 | 57 | } | ||
3727 | 58 | } | ||
3728 | 59 | } | ||
3729 | 60 | } | ||
3730 | 0 | 61 | ||
3731 | === modified file 'src/qt/client/Account.cpp' | |||
3732 | --- src/qt/client/Account.cpp 2016-07-12 02:22:05 +0000 | |||
3733 | +++ src/qt/client/Account.cpp 2016-09-09 02:13:43 +0000 | |||
3734 | @@ -41,7 +41,7 @@ | |||
3735 | 41 | 41 | ||
3736 | 42 | Account::~Account() = default; | 42 | Account::~Account() = default; |
3737 | 43 | 43 | ||
3739 | 44 | Runtime* Account::runtime() const | 44 | shared_ptr<Runtime> Account::runtime() const |
3740 | 45 | { | 45 | { |
3741 | 46 | return p_->runtime(); | 46 | return p_->runtime(); |
3742 | 47 | } | 47 | } |
3743 | 48 | 48 | ||
3744 | === modified file 'src/qt/client/CMakeLists.txt' | |||
3745 | --- src/qt/client/CMakeLists.txt 2016-07-27 02:19:17 +0000 | |||
3746 | +++ src/qt/client/CMakeLists.txt 2016-09-09 02:13:43 +0000 | |||
3747 | @@ -80,7 +80,7 @@ | |||
3748 | 80 | # Build the remote client library | 80 | # Build the remote client library |
3749 | 81 | set_source_files_properties(${CMAKE_SOURCE_DIR}/data/provider.xml PROPERTIES | 81 | set_source_files_properties(${CMAKE_SOURCE_DIR}/data/provider.xml PROPERTIES |
3750 | 82 | CLASSNAME ProviderInterface | 82 | CLASSNAME ProviderInterface |
3752 | 83 | INCLUDE unity/storage/qt/client/internal/remote_client/dbusmarshal.h | 83 | INCLUDE unity/storage/internal/dbusmarshal.h |
3753 | 84 | ) | 84 | ) |
3754 | 85 | 85 | ||
3755 | 86 | qt5_add_dbus_interface(generated_files | 86 | qt5_add_dbus_interface(generated_files |
3756 | @@ -109,6 +109,7 @@ | |||
3757 | 109 | VERSION ${SF_CLIENT_LIBVERSION} | 109 | VERSION ${SF_CLIENT_LIBVERSION} |
3758 | 110 | ) | 110 | ) |
3759 | 111 | target_link_libraries(storage-framework-qt-client | 111 | target_link_libraries(storage-framework-qt-client |
3760 | 112 | storage-framework-common-internal | ||
3761 | 112 | Qt5::Concurrent | 113 | Qt5::Concurrent |
3762 | 113 | Qt5::Core | 114 | Qt5::Core |
3763 | 114 | Qt5::DBus | 115 | Qt5::DBus |
3764 | 115 | 116 | ||
3765 | === modified file 'src/qt/client/Exceptions.cpp' | |||
3766 | --- src/qt/client/Exceptions.cpp 2016-07-22 01:45:39 +0000 | |||
3767 | +++ src/qt/client/Exceptions.cpp 2016-09-09 02:13:43 +0000 | |||
3768 | @@ -42,6 +42,11 @@ | |||
3769 | 42 | return what_string_.c_str(); | 42 | return what_string_.c_str(); |
3770 | 43 | } | 43 | } |
3771 | 44 | 44 | ||
3772 | 45 | QString StorageException::error_message() const | ||
3773 | 46 | { | ||
3774 | 47 | return error_message_; | ||
3775 | 48 | } | ||
3776 | 49 | |||
3777 | 45 | LocalCommsException::LocalCommsException(QString const& error_message) | 50 | LocalCommsException::LocalCommsException(QString const& error_message) |
3778 | 46 | : StorageException("LocalCommsException", error_message) | 51 | : StorageException("LocalCommsException", error_message) |
3779 | 47 | { | 52 | { |
3780 | @@ -76,10 +81,9 @@ | |||
3781 | 76 | throw *this; | 81 | throw *this; |
3782 | 77 | } | 82 | } |
3783 | 78 | 83 | ||
3785 | 79 | DeletedException::DeletedException(QString const& error_message, QString const& identity, QString const& name) | 84 | DeletedException::DeletedException(QString const& error_message, QString const& identity) |
3786 | 80 | : StorageException("DeletedException", error_message) | 85 | : StorageException("DeletedException", error_message) |
3787 | 81 | , identity_(identity) | 86 | , identity_(identity) |
3788 | 82 | , name_(name) | ||
3789 | 83 | { | 87 | { |
3790 | 84 | } | 88 | } |
3791 | 85 | 89 | ||
3792 | @@ -100,13 +104,8 @@ | |||
3793 | 100 | return identity_; | 104 | return identity_; |
3794 | 101 | } | 105 | } |
3795 | 102 | 106 | ||
3796 | 103 | QString DeletedException::name() const | ||
3797 | 104 | { | ||
3798 | 105 | return name_; | ||
3799 | 106 | } | ||
3800 | 107 | |||
3801 | 108 | RuntimeDestroyedException::RuntimeDestroyedException(QString const& method) | 107 | RuntimeDestroyedException::RuntimeDestroyedException(QString const& method) |
3803 | 109 | : StorageException("RuntimeDestroyedException", method + ": Runtime was destroyed previously") | 108 | : StorageException("RuntimeDestroyedException", method + ": runtime was destroyed previously") |
3804 | 110 | { | 109 | { |
3805 | 111 | } | 110 | } |
3806 | 112 | 111 | ||
3807 | @@ -276,8 +275,9 @@ | |||
3808 | 276 | throw *this; | 275 | throw *this; |
3809 | 277 | } | 276 | } |
3810 | 278 | 277 | ||
3812 | 279 | ResourceException::ResourceException(QString const& error_message) | 278 | ResourceException::ResourceException(QString const& error_message, int error_code) |
3813 | 280 | : StorageException("ResourceException", error_message) | 279 | : StorageException("ResourceException", error_message) |
3814 | 280 | , error_code_(error_code) | ||
3815 | 281 | { | 281 | { |
3816 | 282 | } | 282 | } |
3817 | 283 | 283 | ||
3818 | @@ -293,6 +293,11 @@ | |||
3819 | 293 | throw *this; | 293 | throw *this; |
3820 | 294 | } | 294 | } |
3821 | 295 | 295 | ||
3822 | 296 | int ResourceException::error_code() const noexcept | ||
3823 | 297 | { | ||
3824 | 298 | return error_code_; | ||
3825 | 299 | } | ||
3826 | 300 | |||
3827 | 296 | } // namespace client | 301 | } // namespace client |
3828 | 297 | } // namespace qt | 302 | } // namespace qt |
3829 | 298 | } // namespace storage | 303 | } // namespace storage |
3830 | 299 | 304 | ||
3831 | === modified file 'src/qt/client/Item.cpp' | |||
3832 | --- src/qt/client/Item.cpp 2016-07-14 00:25:40 +0000 | |||
3833 | +++ src/qt/client/Item.cpp 2016-09-09 02:13:43 +0000 | |||
3834 | @@ -51,7 +51,7 @@ | |||
3835 | 51 | return p_->name(); | 51 | return p_->name(); |
3836 | 52 | } | 52 | } |
3837 | 53 | 53 | ||
3839 | 54 | Root* Item::root() const | 54 | shared_ptr<Root> Item::root() const |
3840 | 55 | { | 55 | { |
3841 | 56 | return p_->root(); | 56 | return p_->root(); |
3842 | 57 | } | 57 | } |
3843 | 58 | 58 | ||
3844 | === modified file 'src/qt/client/Root.cpp' | |||
3845 | --- src/qt/client/Root.cpp 2016-07-12 02:22:05 +0000 | |||
3846 | +++ src/qt/client/Root.cpp 2016-09-09 02:13:43 +0000 | |||
3847 | @@ -30,6 +30,7 @@ | |||
3848 | 30 | { | 30 | { |
3849 | 31 | 31 | ||
3850 | 32 | using namespace internal; | 32 | using namespace internal; |
3851 | 33 | using namespace std; | ||
3852 | 33 | 34 | ||
3853 | 34 | Root::Root(RootBase* p) | 35 | Root::Root(RootBase* p) |
3854 | 35 | : Folder(p) | 36 | : Folder(p) |
3855 | @@ -38,7 +39,7 @@ | |||
3856 | 38 | 39 | ||
3857 | 39 | Root::~Root() = default; | 40 | Root::~Root() = default; |
3858 | 40 | 41 | ||
3860 | 41 | Account* Root::account() const | 42 | shared_ptr<Account> Root::account() const |
3861 | 42 | { | 43 | { |
3862 | 43 | return dynamic_cast<RootBase*>(p_.get())->account(); | 44 | return dynamic_cast<RootBase*>(p_.get())->account(); |
3863 | 44 | } | 45 | } |
3864 | 45 | 46 | ||
3865 | === modified file 'src/qt/client/Runtime.cpp' | |||
3866 | --- src/qt/client/Runtime.cpp 2016-07-21 04:00:29 +0000 | |||
3867 | +++ src/qt/client/Runtime.cpp 2016-09-09 02:13:43 +0000 | |||
3868 | @@ -64,6 +64,12 @@ | |||
3869 | 64 | return p_->accounts(); | 64 | return p_->accounts(); |
3870 | 65 | } | 65 | } |
3871 | 66 | 66 | ||
3872 | 67 | shared_ptr<Account> Runtime::make_test_account(QString const& bus_name, | ||
3873 | 68 | QString const& object_path) | ||
3874 | 69 | { | ||
3875 | 70 | return p_->make_test_account(bus_name, object_path); | ||
3876 | 71 | } | ||
3877 | 72 | |||
3878 | 67 | } // namespace client | 73 | } // namespace client |
3879 | 68 | } // namespace qt | 74 | } // namespace qt |
3880 | 69 | } // namespace storage | 75 | } // namespace storage |
3881 | 70 | 76 | ||
3882 | === modified file 'src/qt/client/Uploader.cpp' | |||
3883 | --- src/qt/client/Uploader.cpp 2016-07-12 02:22:05 +0000 | |||
3884 | +++ src/qt/client/Uploader.cpp 2016-09-09 02:13:43 +0000 | |||
3885 | @@ -46,6 +46,11 @@ | |||
3886 | 46 | return p_->socket(); | 46 | return p_->socket(); |
3887 | 47 | } | 47 | } |
3888 | 48 | 48 | ||
3889 | 49 | int64_t Uploader::size() const | ||
3890 | 50 | { | ||
3891 | 51 | return p_->size(); | ||
3892 | 52 | } | ||
3893 | 53 | |||
3894 | 49 | QFuture<shared_ptr<File>> Uploader::finish_upload() | 54 | QFuture<shared_ptr<File>> Uploader::finish_upload() |
3895 | 50 | { | 55 | { |
3896 | 51 | return p_->finish_upload(); | 56 | return p_->finish_upload(); |
3897 | 52 | 57 | ||
3898 | === modified file 'src/qt/client/internal/AccountBase.cpp' | |||
3899 | --- src/qt/client/internal/AccountBase.cpp 2016-07-14 04:50:36 +0000 | |||
3900 | +++ src/qt/client/internal/AccountBase.cpp 2016-09-09 02:13:43 +0000 | |||
3901 | @@ -19,6 +19,8 @@ | |||
3902 | 19 | #include <unity/storage/qt/client/internal/AccountBase.h> | 19 | #include <unity/storage/qt/client/internal/AccountBase.h> |
3903 | 20 | 20 | ||
3904 | 21 | #include <unity/storage/qt/client/Exceptions.h> | 21 | #include <unity/storage/qt/client/Exceptions.h> |
3905 | 22 | #include <unity/storage/qt/client/internal/RuntimeBase.h> | ||
3906 | 23 | #include <unity/storage/qt/client/Runtime.h> | ||
3907 | 22 | 24 | ||
3908 | 23 | #include <cassert> | 25 | #include <cassert> |
3909 | 24 | 26 | ||
3910 | @@ -42,13 +44,18 @@ | |||
3911 | 42 | assert(runtime.lock()); | 44 | assert(runtime.lock()); |
3912 | 43 | } | 45 | } |
3913 | 44 | 46 | ||
3915 | 45 | Runtime* AccountBase::runtime() const | 47 | shared_ptr<Runtime> AccountBase::runtime() const |
3916 | 46 | { | 48 | { |
3917 | 47 | if (auto runtime = runtime_.lock()) | 49 | if (auto runtime = runtime_.lock()) |
3918 | 48 | { | 50 | { |
3920 | 49 | return runtime.get(); | 51 | auto runtime_base = runtime->p_; |
3921 | 52 | if (runtime_base->destroyed_) | ||
3922 | 53 | { | ||
3923 | 54 | throw RuntimeDestroyedException("Account::runtime()"); | ||
3924 | 55 | } | ||
3925 | 56 | return runtime; | ||
3926 | 50 | } | 57 | } |
3928 | 51 | throw RuntimeDestroyedException("AccountBase::runtime()"); | 58 | throw RuntimeDestroyedException("Account::runtime()"); |
3929 | 52 | } | 59 | } |
3930 | 53 | 60 | ||
3931 | 54 | void AccountBase::set_public_instance(weak_ptr<Account> const& p) | 61 | void AccountBase::set_public_instance(weak_ptr<Account> const& p) |
3932 | 55 | 62 | ||
3933 | === modified file 'src/qt/client/internal/ItemBase.cpp' | |||
3934 | --- src/qt/client/internal/ItemBase.cpp 2016-07-14 04:50:36 +0000 | |||
3935 | +++ src/qt/client/internal/ItemBase.cpp 2016-09-09 02:13:43 +0000 | |||
3936 | @@ -18,7 +18,9 @@ | |||
3937 | 18 | 18 | ||
3938 | 19 | #include <unity/storage/qt/client/internal/ItemBase.h> | 19 | #include <unity/storage/qt/client/internal/ItemBase.h> |
3939 | 20 | 20 | ||
3940 | 21 | #include <unity/storage/qt/client/Account.h> | ||
3941 | 21 | #include <unity/storage/qt/client/Exceptions.h> | 22 | #include <unity/storage/qt/client/Exceptions.h> |
3942 | 23 | #include <unity/storage/qt/client/Root.h> | ||
3943 | 22 | 24 | ||
3944 | 23 | #include <cassert> | 25 | #include <cassert> |
3945 | 24 | 26 | ||
3946 | @@ -46,21 +48,24 @@ | |||
3947 | 46 | 48 | ||
3948 | 47 | QString ItemBase::native_identity() const | 49 | QString ItemBase::native_identity() const |
3949 | 48 | { | 50 | { |
3950 | 51 | throw_if_destroyed("Item::native_identity()"); | ||
3951 | 49 | return identity_; | 52 | return identity_; |
3952 | 50 | } | 53 | } |
3953 | 51 | 54 | ||
3954 | 52 | ItemType ItemBase::type() const | 55 | ItemType ItemBase::type() const |
3955 | 53 | { | 56 | { |
3956 | 57 | throw_if_destroyed("Item::type()"); | ||
3957 | 54 | return type_; | 58 | return type_; |
3958 | 55 | } | 59 | } |
3959 | 56 | 60 | ||
3961 | 57 | Root* ItemBase::root() const | 61 | shared_ptr<Root> ItemBase::root() const |
3962 | 58 | { | 62 | { |
3964 | 59 | if (auto r = root_.lock()) | 63 | auto root = get_root(); |
3965 | 64 | if (!root) | ||
3966 | 60 | { | 65 | { |
3968 | 61 | return r.get(); | 66 | throw RuntimeDestroyedException("Item::root()"); |
3969 | 62 | } | 67 | } |
3971 | 63 | throw RuntimeDestroyedException("Item::root()"); | 68 | return root; |
3972 | 64 | } | 69 | } |
3973 | 65 | 70 | ||
3974 | 66 | void ItemBase::set_root(std::weak_ptr<Root> root) | 71 | void ItemBase::set_root(std::weak_ptr<Root> root) |
3975 | @@ -75,6 +80,36 @@ | |||
3976 | 75 | public_instance_ = p; | 80 | public_instance_ = p; |
3977 | 76 | } | 81 | } |
3978 | 77 | 82 | ||
3979 | 83 | shared_ptr<Root> ItemBase::get_root() const noexcept | ||
3980 | 84 | { | ||
3981 | 85 | try | ||
3982 | 86 | { | ||
3983 | 87 | auto root = root_.lock(); | ||
3984 | 88 | if (root) | ||
3985 | 89 | { | ||
3986 | 90 | root->account(); // Throws if either account or runtime has been destroyed. | ||
3987 | 91 | return root; | ||
3988 | 92 | } | ||
3989 | 93 | } | ||
3990 | 94 | catch (RuntimeDestroyedException const&) | ||
3991 | 95 | { | ||
3992 | 96 | } | ||
3993 | 97 | return nullptr; | ||
3994 | 98 | } | ||
3995 | 99 | |||
3996 | 100 | void ItemBase::throw_if_destroyed(QString const& method) const | ||
3997 | 101 | { | ||
3998 | 102 | if (deleted_) | ||
3999 | 103 | { | ||
4000 | 104 | QString msg = method + ": \"" + identity_ + "\" was deleted previously"; | ||
4001 | 105 | throw DeletedException(msg, identity_); | ||
4002 | 106 | } | ||
4003 | 107 | if (!get_root()) | ||
4004 | 108 | { | ||
4005 | 109 | throw RuntimeDestroyedException(method); | ||
4006 | 110 | } | ||
4007 | 111 | } | ||
4008 | 112 | |||
4009 | 78 | } // namespace internal | 113 | } // namespace internal |
4010 | 79 | } // namespace client | 114 | } // namespace client |
4011 | 80 | } // namespace qt | 115 | } // namespace qt |
4012 | 81 | 116 | ||
4013 | === modified file 'src/qt/client/internal/RootBase.cpp' | |||
4014 | --- src/qt/client/internal/RootBase.cpp 2016-07-27 02:19:17 +0000 | |||
4015 | +++ src/qt/client/internal/RootBase.cpp 2016-09-09 02:13:43 +0000 | |||
4016 | @@ -18,6 +18,7 @@ | |||
4017 | 18 | 18 | ||
4018 | 19 | #include <unity/storage/qt/client/internal/RootBase.h> | 19 | #include <unity/storage/qt/client/internal/RootBase.h> |
4019 | 20 | 20 | ||
4020 | 21 | #include <unity/storage/qt/client/Account.h> | ||
4021 | 21 | #include <unity/storage/qt/client/Exceptions.h> | 22 | #include <unity/storage/qt/client/Exceptions.h> |
4022 | 22 | 23 | ||
4023 | 23 | #include <cassert> | 24 | #include <cassert> |
4024 | @@ -43,11 +44,19 @@ | |||
4025 | 43 | assert(account.lock()); | 44 | assert(account.lock()); |
4026 | 44 | } | 45 | } |
4027 | 45 | 46 | ||
4029 | 46 | Account* RootBase::account() const | 47 | shared_ptr<Account> RootBase::account() const |
4030 | 47 | { | 48 | { |
4031 | 48 | if (auto acc = account_.lock()) | 49 | if (auto acc = account_.lock()) |
4032 | 49 | { | 50 | { |
4034 | 50 | return acc.get(); | 51 | try |
4035 | 52 | { | ||
4036 | 53 | acc->runtime(); | ||
4037 | 54 | } | ||
4038 | 55 | catch (RuntimeDestroyedException const&) | ||
4039 | 56 | { | ||
4040 | 57 | throw RuntimeDestroyedException("Root::account()"); | ||
4041 | 58 | } | ||
4042 | 59 | return acc; | ||
4043 | 51 | } | 60 | } |
4044 | 52 | throw RuntimeDestroyedException("Root::account()"); | 61 | throw RuntimeDestroyedException("Root::account()"); |
4045 | 53 | } | 62 | } |
4046 | 54 | 63 | ||
4047 | === modified file 'src/qt/client/internal/RuntimeBase.cpp' | |||
4048 | --- src/qt/client/internal/RuntimeBase.cpp 2016-07-12 02:22:05 +0000 | |||
4049 | +++ src/qt/client/internal/RuntimeBase.cpp 2016-09-09 02:13:43 +0000 | |||
4050 | @@ -34,11 +34,6 @@ | |||
4051 | 34 | namespace internal | 34 | namespace internal |
4052 | 35 | { | 35 | { |
4053 | 36 | 36 | ||
4054 | 37 | RuntimeBase::RuntimeBase() | ||
4055 | 38 | : destroyed_(false) | ||
4056 | 39 | { | ||
4057 | 40 | } | ||
4058 | 41 | |||
4059 | 42 | void RuntimeBase::set_public_instance(weak_ptr<Runtime> p) | 37 | void RuntimeBase::set_public_instance(weak_ptr<Runtime> p) |
4060 | 43 | { | 38 | { |
4061 | 44 | assert(p.lock()); | 39 | assert(p.lock()); |
4062 | 45 | 40 | ||
4063 | === modified file 'src/qt/client/internal/UploaderBase.cpp' | |||
4064 | --- src/qt/client/internal/UploaderBase.cpp 2016-07-22 01:45:39 +0000 | |||
4065 | +++ src/qt/client/internal/UploaderBase.cpp 2016-09-09 02:13:43 +0000 | |||
4066 | @@ -25,6 +25,8 @@ | |||
4067 | 25 | #include <QFuture> | 25 | #include <QFuture> |
4068 | 26 | #pragma GCC diagnostic pop | 26 | #pragma GCC diagnostic pop |
4069 | 27 | 27 | ||
4070 | 28 | #include <cassert> | ||
4071 | 29 | |||
4072 | 28 | using namespace std; | 30 | using namespace std; |
4073 | 29 | 31 | ||
4074 | 30 | namespace unity | 32 | namespace unity |
4075 | @@ -38,9 +40,16 @@ | |||
4076 | 38 | namespace internal | 40 | namespace internal |
4077 | 39 | { | 41 | { |
4078 | 40 | 42 | ||
4080 | 41 | UploaderBase::UploaderBase(ConflictPolicy policy) | 43 | UploaderBase::UploaderBase(ConflictPolicy policy, int64_t size) |
4081 | 42 | : policy_(policy) | 44 | : policy_(policy) |
4083 | 43 | { | 45 | , size_(size) |
4084 | 46 | { | ||
4085 | 47 | assert(size >= 0); | ||
4086 | 48 | } | ||
4087 | 49 | |||
4088 | 50 | int64_t UploaderBase::size() const | ||
4089 | 51 | { | ||
4090 | 52 | return size_; | ||
4091 | 44 | } | 53 | } |
4092 | 45 | 54 | ||
4093 | 46 | } // namespace internal | 55 | } // namespace internal |
4094 | 47 | 56 | ||
4095 | === modified file 'src/qt/client/internal/local_client/AccountImpl.cpp' | |||
4096 | --- src/qt/client/internal/local_client/AccountImpl.cpp 2016-07-14 04:50:36 +0000 | |||
4097 | +++ src/qt/client/internal/local_client/AccountImpl.cpp 2016-09-09 02:13:43 +0000 | |||
4098 | @@ -67,7 +67,7 @@ | |||
4099 | 67 | if (ec) | 67 | if (ec) |
4100 | 68 | { | 68 | { |
4101 | 69 | QString msg = "Account::roots(): Cannot stat " + QString(dir) + ": " + QString::fromStdString(ec.message()); | 69 | QString msg = "Account::roots(): Cannot stat " + QString(dir) + ": " + QString::fromStdString(ec.message()); |
4103 | 70 | throw ResourceException(msg); | 70 | throw ResourceException(msg, errno); |
4104 | 71 | } | 71 | } |
4105 | 72 | if (!is_dir) | 72 | if (!is_dir) |
4106 | 73 | { | 73 | { |
4107 | @@ -85,7 +85,7 @@ | |||
4108 | 85 | { | 85 | { |
4109 | 86 | QString msg = "Account::roots(): Cannot create " + QString(dir) + ": " | 86 | QString msg = "Account::roots(): Cannot create " + QString(dir) + ": " |
4110 | 87 | + QString::fromStdString(ec.message()); | 87 | + QString::fromStdString(ec.message()); |
4112 | 88 | throw ResourceException(msg); | 88 | throw ResourceException(msg, ec.value()); |
4113 | 89 | } | 89 | } |
4114 | 90 | } | 90 | } |
4115 | 91 | return data_dir; | 91 | return data_dir; |
4116 | @@ -109,22 +109,32 @@ | |||
4117 | 109 | 109 | ||
4118 | 110 | QString AccountImpl::owner() const | 110 | QString AccountImpl::owner() const |
4119 | 111 | { | 111 | { |
4120 | 112 | runtime(); // Throws RuntimeDestroyedException if runtime was destroyed. | ||
4121 | 112 | return owner_; | 113 | return owner_; |
4122 | 113 | } | 114 | } |
4123 | 114 | 115 | ||
4124 | 115 | QString AccountImpl::owner_id() const | 116 | QString AccountImpl::owner_id() const |
4125 | 116 | { | 117 | { |
4126 | 118 | runtime(); // Throws RuntimeDestroyedException if runtime was destroyed. | ||
4127 | 117 | return owner_id_; | 119 | return owner_id_; |
4128 | 118 | } | 120 | } |
4129 | 119 | 121 | ||
4130 | 120 | QString AccountImpl::description() const | 122 | QString AccountImpl::description() const |
4131 | 121 | { | 123 | { |
4132 | 124 | runtime(); // Throws RuntimeDestroyedException if runtime was destroyed. | ||
4133 | 122 | return description_; | 125 | return description_; |
4134 | 123 | } | 126 | } |
4135 | 124 | 127 | ||
4136 | 125 | QFuture<QVector<Root::SPtr>> AccountImpl::roots() | 128 | QFuture<QVector<Root::SPtr>> AccountImpl::roots() |
4137 | 126 | { | 129 | { |
4139 | 127 | using namespace boost::filesystem; | 130 | try |
4140 | 131 | { | ||
4141 | 132 | runtime(); // Throws RuntimeDestroyedException if runtime was destroyed. | ||
4142 | 133 | } | ||
4143 | 134 | catch (RuntimeDestroyedException const& e) | ||
4144 | 135 | { | ||
4145 | 136 | return make_exceptional_future<QVector<Root::SPtr>>(e); | ||
4146 | 137 | } | ||
4147 | 128 | 138 | ||
4148 | 129 | if (!roots_.isEmpty()) | 139 | if (!roots_.isEmpty()) |
4149 | 130 | { | 140 | { |
4150 | @@ -132,6 +142,9 @@ | |||
4151 | 132 | } | 142 | } |
4152 | 133 | 143 | ||
4153 | 134 | // Create the root on first access. | 144 | // Create the root on first access. |
4154 | 145 | |||
4155 | 146 | using namespace boost::filesystem; | ||
4156 | 147 | |||
4157 | 135 | auto rpath = canonical(get_data_dir()).native(); | 148 | auto rpath = canonical(get_data_dir()).native(); |
4158 | 136 | auto root = RootImpl::make_root(QString::fromStdString(rpath), public_instance_); | 149 | auto root = RootImpl::make_root(QString::fromStdString(rpath), public_instance_); |
4159 | 137 | roots_.append(root); | 150 | roots_.append(root); |
4160 | 138 | 151 | ||
4161 | === modified file 'src/qt/client/internal/local_client/CMakeLists.txt' | |||
4162 | --- src/qt/client/internal/local_client/CMakeLists.txt 2016-07-22 00:17:24 +0000 | |||
4163 | +++ src/qt/client/internal/local_client/CMakeLists.txt 2016-09-09 02:13:43 +0000 | |||
4164 | @@ -7,6 +7,7 @@ | |||
4165 | 7 | ${CMAKE_CURRENT_SOURCE_DIR}/RootImpl.cpp | 7 | ${CMAKE_CURRENT_SOURCE_DIR}/RootImpl.cpp |
4166 | 8 | ${CMAKE_CURRENT_SOURCE_DIR}/Runtime_create.cpp | 8 | ${CMAKE_CURRENT_SOURCE_DIR}/Runtime_create.cpp |
4167 | 9 | ${CMAKE_CURRENT_SOURCE_DIR}/RuntimeImpl.cpp | 9 | ${CMAKE_CURRENT_SOURCE_DIR}/RuntimeImpl.cpp |
4168 | 10 | ${CMAKE_CURRENT_SOURCE_DIR}/storage_exception.cpp | ||
4169 | 10 | ${CMAKE_CURRENT_SOURCE_DIR}/UploaderImpl.cpp | 11 | ${CMAKE_CURRENT_SOURCE_DIR}/UploaderImpl.cpp |
4170 | 11 | ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/client/internal/local_client/DownloaderImpl.h | 12 | ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/client/internal/local_client/DownloaderImpl.h |
4171 | 12 | ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/client/internal/local_client/UploaderImpl.h | 13 | ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/client/internal/local_client/UploaderImpl.h |
4172 | 13 | 14 | ||
4173 | === modified file 'src/qt/client/internal/local_client/DownloaderImpl.cpp' | |||
4174 | --- src/qt/client/internal/local_client/DownloaderImpl.cpp 2016-07-22 00:17:24 +0000 | |||
4175 | +++ src/qt/client/internal/local_client/DownloaderImpl.cpp 2016-09-09 02:13:43 +0000 | |||
4176 | @@ -23,7 +23,10 @@ | |||
4177 | 23 | #include <unity/storage/qt/client/File.h> | 23 | #include <unity/storage/qt/client/File.h> |
4178 | 24 | #include <unity/storage/qt/client/internal/make_future.h> | 24 | #include <unity/storage/qt/client/internal/make_future.h> |
4179 | 25 | 25 | ||
4180 | 26 | #pragma GCC diagnostic push | ||
4181 | 27 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
4182 | 26 | #include <QLocalSocket> | 28 | #include <QLocalSocket> |
4183 | 29 | #pragma GCC diagnostic pop | ||
4184 | 27 | 30 | ||
4185 | 28 | #include <cassert> | 31 | #include <cassert> |
4186 | 29 | 32 | ||
4187 | @@ -79,8 +82,10 @@ | |||
4188 | 79 | input_file_.reset(new QFile(filename_)); | 82 | input_file_.reset(new QFile(filename_)); |
4189 | 80 | if (!input_file_->open(QIODevice::ReadOnly)) | 83 | if (!input_file_->open(QIODevice::ReadOnly)) |
4190 | 81 | { | 84 | { |
4192 | 82 | handle_error("cannot open " + filename_ + ": " + input_file_->errorString()); | 85 | // LCOV_EXCL_START |
4193 | 86 | handle_error("cannot open " + filename_ + ": " + input_file_->errorString(), input_file_->error()); | ||
4194 | 83 | return; | 87 | return; |
4195 | 88 | // LCOV_EXCL_STOP | ||
4196 | 84 | } | 89 | } |
4197 | 85 | bytes_to_write_ = input_file_->size(); | 90 | bytes_to_write_ = input_file_->size(); |
4198 | 86 | 91 | ||
4199 | @@ -116,7 +121,7 @@ | |||
4200 | 116 | + QString::number(written) + " byte"; | 121 | + QString::number(written) + " byte"; |
4201 | 117 | msg += written == 1 ? " was" : "s were"; | 122 | msg += written == 1 ? " was" : "s were"; |
4202 | 118 | msg += " consumed."; | 123 | msg += " consumed."; |
4204 | 119 | make_exceptional_future(qf_, LogicException(msg)); | 124 | qf_.reportException(LogicException(msg)); |
4205 | 120 | } | 125 | } |
4206 | 121 | else | 126 | else |
4207 | 122 | { | 127 | { |
4208 | @@ -131,12 +136,12 @@ | |||
4209 | 131 | case cancelled: | 136 | case cancelled: |
4210 | 132 | { | 137 | { |
4211 | 133 | QString msg = "Downloader::finish_download(): download of " + filename_ + " was cancelled"; | 138 | QString msg = "Downloader::finish_download(): download of " + filename_ + " was cancelled"; |
4213 | 134 | make_exceptional_future(qf_, CancelledException(msg)); | 139 | qf_.reportException(CancelledException(msg)); |
4214 | 135 | break; | 140 | break; |
4215 | 136 | } | 141 | } |
4216 | 137 | case error: | 142 | case error: |
4217 | 138 | { | 143 | { |
4219 | 139 | make_exceptional_future(qf_, ResourceException(error_msg_)); | 144 | qf_.reportException(ResourceException(error_msg_, error_code_)); |
4220 | 140 | break; | 145 | break; |
4221 | 141 | } | 146 | } |
4222 | 142 | default: | 147 | default: |
4223 | @@ -144,7 +149,7 @@ | |||
4224 | 144 | abort(); // LCOV_EXCL_LINE // Impossible | 149 | abort(); // LCOV_EXCL_LINE // Impossible |
4225 | 145 | } | 150 | } |
4226 | 146 | } | 151 | } |
4228 | 147 | make_ready_future(qf_); | 152 | qf_.reportFinished(); |
4229 | 148 | QThread::currentThread()->quit(); | 153 | QThread::currentThread()->quit(); |
4230 | 149 | } | 154 | } |
4231 | 150 | 155 | ||
4232 | @@ -189,7 +194,8 @@ | |||
4233 | 189 | 194 | ||
4234 | 190 | void DownloadWorker::on_error() | 195 | void DownloadWorker::on_error() |
4235 | 191 | { | 196 | { |
4237 | 192 | handle_error(write_socket_->errorString()); | 197 | disconnect(write_socket_.get(), nullptr, this, nullptr); |
4238 | 198 | handle_error(write_socket_->errorString(), write_socket_->error()); | ||
4239 | 193 | } | 199 | } |
4240 | 194 | 200 | ||
4241 | 195 | // Read the next chunk of data from the input file and write it to the socket. | 201 | // Read the next chunk of data from the input file and write it to the socket. |
4242 | @@ -203,25 +209,31 @@ | |||
4243 | 203 | auto bytes_read = input_file_->read(buf.data(), buf.size()); | 209 | auto bytes_read = input_file_->read(buf.data(), buf.size()); |
4244 | 204 | if (bytes_read == -1) | 210 | if (bytes_read == -1) |
4245 | 205 | { | 211 | { |
4247 | 206 | handle_error(filename_ + ": read error: " + input_file_->errorString()); | 212 | // LCOV_EXCL_START |
4248 | 213 | handle_error(filename_ + ": read error: " + input_file_->errorString(), input_file_->error()); | ||
4249 | 207 | return; | 214 | return; |
4250 | 215 | // LCOV_EXCL_STOP | ||
4251 | 208 | } | 216 | } |
4252 | 209 | buf.resize(bytes_read); | 217 | buf.resize(bytes_read); |
4253 | 210 | 218 | ||
4254 | 211 | auto bytes_written = write_socket_->write(buf); | 219 | auto bytes_written = write_socket_->write(buf); |
4255 | 212 | if (bytes_written == -1) | 220 | if (bytes_written == -1) |
4256 | 213 | { | 221 | { |
4258 | 214 | handle_error(filename_ + ": socket error: " + write_socket_->errorString()); | 222 | // LCOV_EXCL_START |
4259 | 223 | handle_error(filename_ + ": socket error: " + write_socket_->errorString(), write_socket_->error()); | ||
4260 | 224 | // LCOV_EXCL_STOP | ||
4261 | 215 | } | 225 | } |
4262 | 216 | else if (bytes_written != bytes_read) | 226 | else if (bytes_written != bytes_read) |
4263 | 217 | { | 227 | { |
4264 | 228 | // LCOV_EXCL_START | ||
4265 | 218 | QString msg = filename_ + ": write error, requested " + bytes_read + " B, but wrote only " | 229 | QString msg = filename_ + ": write error, requested " + bytes_read + " B, but wrote only " |
4266 | 219 | + bytes_written + " B."; | 230 | + bytes_written + " B."; |
4268 | 220 | handle_error(msg); | 231 | handle_error(msg, 0); |
4269 | 232 | // LCOV_EXCL_STOP | ||
4270 | 221 | } | 233 | } |
4271 | 222 | } | 234 | } |
4272 | 223 | 235 | ||
4274 | 224 | void DownloadWorker::handle_error(QString const& msg) | 236 | void DownloadWorker::handle_error(QString const& msg, int error_code) |
4275 | 225 | { | 237 | { |
4276 | 226 | if (state_ == in_progress) | 238 | if (state_ == in_progress) |
4277 | 227 | { | 239 | { |
4278 | @@ -229,6 +241,7 @@ | |||
4279 | 229 | } | 241 | } |
4280 | 230 | state_ = error; | 242 | state_ = error; |
4281 | 231 | error_msg_ = "Downloader: " + msg; | 243 | error_msg_ = "Downloader: " + msg; |
4282 | 244 | error_code_ = error_code; | ||
4283 | 232 | do_finish(); | 245 | do_finish(); |
4284 | 233 | } | 246 | } |
4285 | 234 | 247 | ||
4286 | @@ -245,17 +258,18 @@ | |||
4287 | 245 | 258 | ||
4288 | 246 | DownloaderImpl::DownloaderImpl(weak_ptr<File> file) | 259 | DownloaderImpl::DownloaderImpl(weak_ptr<File> file) |
4289 | 247 | : DownloaderBase(file) | 260 | : DownloaderBase(file) |
4291 | 248 | , read_socket_(new QLocalSocket) | 261 | , read_socket_(new QLocalSocket, [](QLocalSocket* s){ s->deleteLater(); }) |
4292 | 249 | { | 262 | { |
4293 | 250 | // Set up socket pair. | 263 | // Set up socket pair. |
4294 | 251 | int fds[2]; | 264 | int fds[2]; |
4296 | 252 | int rc = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds); | 265 | int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, fds); |
4297 | 253 | if (rc == -1) | 266 | if (rc == -1) |
4298 | 254 | { | 267 | { |
4299 | 255 | // LCOV_EXCL_START | 268 | // LCOV_EXCL_START |
4300 | 256 | QString msg = "Downloader: cannot create socket pair: " | 269 | QString msg = "Downloader: cannot create socket pair: " |
4301 | 257 | + QString::fromStdString(storage::internal::safe_strerror(errno)); | 270 | + QString::fromStdString(storage::internal::safe_strerror(errno)); |
4303 | 258 | make_exceptional_future(qf_, ResourceException(msg)); | 271 | qf_.reportException(ResourceException(msg, errno)); |
4304 | 272 | qf_.reportFinished(); | ||
4305 | 259 | return; | 273 | return; |
4306 | 260 | // LCOV_EXCL_STOP | 274 | // LCOV_EXCL_STOP |
4307 | 261 | } | 275 | } |
4308 | 262 | 276 | ||
4309 | === modified file 'src/qt/client/internal/local_client/FileImpl.cpp' | |||
4310 | --- src/qt/client/internal/local_client/FileImpl.cpp 2016-07-22 01:45:39 +0000 | |||
4311 | +++ src/qt/client/internal/local_client/FileImpl.cpp 2016-09-09 02:13:43 +0000 | |||
4312 | @@ -22,6 +22,7 @@ | |||
4313 | 22 | #include <unity/storage/qt/client/Exceptions.h> | 22 | #include <unity/storage/qt/client/Exceptions.h> |
4314 | 23 | #include <unity/storage/qt/client/File.h> | 23 | #include <unity/storage/qt/client/File.h> |
4315 | 24 | #include <unity/storage/qt/client/internal/local_client/DownloaderImpl.h> | 24 | #include <unity/storage/qt/client/internal/local_client/DownloaderImpl.h> |
4316 | 25 | #include <unity/storage/qt/client/internal/local_client/storage_exception.h> | ||
4317 | 25 | #include <unity/storage/qt/client/internal/local_client/UploaderImpl.h> | 26 | #include <unity/storage/qt/client/internal/local_client/UploaderImpl.h> |
4318 | 26 | #include <unity/storage/qt/client/internal/make_future.h> | 27 | #include <unity/storage/qt/client/internal/make_future.h> |
4319 | 27 | #include <unity/storage/qt/client/Uploader.h> | 28 | #include <unity/storage/qt/client/Uploader.h> |
4320 | @@ -50,47 +51,44 @@ | |||
4321 | 50 | 51 | ||
4322 | 51 | QString FileImpl::name() const | 52 | QString FileImpl::name() const |
4323 | 52 | { | 53 | { |
4325 | 53 | lock_guard<mutex> guard(mutex_); | 54 | lock_guard<decltype(mutex_)> guard(mutex_); |
4326 | 54 | 55 | ||
4331 | 55 | if (deleted_) | 56 | throw_if_destroyed("File::name()"); |
4328 | 56 | { | ||
4329 | 57 | throw deleted_ex("File::name()"); | ||
4330 | 58 | } | ||
4332 | 59 | return name_; | 57 | return name_; |
4333 | 60 | } | 58 | } |
4334 | 61 | 59 | ||
4335 | 62 | int64_t FileImpl::size() const | 60 | int64_t FileImpl::size() const |
4336 | 63 | { | 61 | { |
4344 | 64 | lock_guard<mutex> guard(mutex_); | 62 | lock_guard<decltype(mutex_)> guard(mutex_); |
4345 | 65 | 63 | ||
4346 | 66 | if (deleted_) | 64 | throw_if_destroyed("File::size()"); |
4340 | 67 | { | ||
4341 | 68 | throw deleted_ex("File::size()"); | ||
4342 | 69 | } | ||
4343 | 70 | |||
4347 | 71 | try | 65 | try |
4348 | 72 | { | 66 | { |
4349 | 73 | boost::filesystem::path p = identity_.toStdString(); | 67 | boost::filesystem::path p = identity_.toStdString(); |
4350 | 74 | return file_size(p); | 68 | return file_size(p); |
4351 | 75 | } | 69 | } |
4353 | 76 | catch (std::exception const& e) | 70 | catch (std::exception const&) |
4354 | 77 | { | 71 | { |
4356 | 78 | throw ResourceException(e.what()); | 72 | throw_storage_exception(QString("File::size()"), current_exception()); |
4357 | 79 | } | 73 | } |
4358 | 80 | } | 74 | } |
4359 | 81 | 75 | ||
4360 | 82 | QFuture<Uploader::SPtr> FileImpl::create_uploader(ConflictPolicy policy, int64_t size) | 76 | QFuture<Uploader::SPtr> FileImpl::create_uploader(ConflictPolicy policy, int64_t size) |
4361 | 83 | { | 77 | { |
4363 | 84 | lock_guard<mutex> guard(mutex_); | 78 | lock_guard<decltype(mutex_)> guard(mutex_); |
4364 | 85 | 79 | ||
4368 | 86 | if (deleted_) | 80 | try |
4369 | 87 | { | 81 | { |
4370 | 88 | return make_exceptional_future<Uploader::SPtr>(deleted_ex("File::create_uploader()")); | 82 | throw_if_destroyed("File::create_uploader()"); |
4371 | 83 | } | ||
4372 | 84 | catch (StorageException const& e) | ||
4373 | 85 | { | ||
4374 | 86 | return internal::make_exceptional_future<Uploader::SPtr>(e); | ||
4375 | 89 | } | 87 | } |
4376 | 90 | if (size < 0) | 88 | if (size < 0) |
4377 | 91 | { | 89 | { |
4378 | 92 | QString msg = "File::create_uploader(): size must be >= 0"; | 90 | QString msg = "File::create_uploader(): size must be >= 0"; |
4380 | 93 | return make_exceptional_future<shared_ptr<Uploader>>(InvalidArgumentException(msg)); | 91 | return internal::make_exceptional_future<shared_ptr<Uploader>>(InvalidArgumentException(msg)); |
4381 | 94 | } | 92 | } |
4382 | 95 | 93 | ||
4383 | 96 | auto file = dynamic_pointer_cast<File>(public_instance_.lock()); | 94 | auto file = dynamic_pointer_cast<File>(public_instance_.lock()); |
4384 | @@ -102,11 +100,15 @@ | |||
4385 | 102 | 100 | ||
4386 | 103 | QFuture<Downloader::SPtr> FileImpl::create_downloader() | 101 | QFuture<Downloader::SPtr> FileImpl::create_downloader() |
4387 | 104 | { | 102 | { |
4389 | 105 | lock_guard<mutex> guard(mutex_); | 103 | lock_guard<decltype(mutex_)> guard(mutex_); |
4390 | 106 | 104 | ||
4394 | 107 | if (deleted_) | 105 | try |
4395 | 108 | { | 106 | { |
4396 | 109 | return make_exceptional_future<Downloader::SPtr>(deleted_ex("File::create_downloader()")); | 107 | throw_if_destroyed("File::create_downloader()"); |
4397 | 108 | } | ||
4398 | 109 | catch (StorageException const& e) | ||
4399 | 110 | { | ||
4400 | 111 | return internal::make_exceptional_future<Downloader::SPtr>(e); | ||
4401 | 110 | } | 112 | } |
4402 | 111 | 113 | ||
4403 | 112 | auto pi = public_instance_.lock(); | 114 | auto pi = public_instance_.lock(); |
4404 | 113 | 115 | ||
4405 | === modified file 'src/qt/client/internal/local_client/FolderImpl.cpp' | |||
4406 | --- src/qt/client/internal/local_client/FolderImpl.cpp 2016-07-22 01:45:39 +0000 | |||
4407 | +++ src/qt/client/internal/local_client/FolderImpl.cpp 2016-09-09 02:13:43 +0000 | |||
4408 | @@ -24,7 +24,8 @@ | |||
4409 | 24 | #include <unity/storage/qt/client/Uploader.h> | 24 | #include <unity/storage/qt/client/Uploader.h> |
4410 | 25 | #include <unity/storage/qt/client/internal/make_future.h> | 25 | #include <unity/storage/qt/client/internal/make_future.h> |
4411 | 26 | #include <unity/storage/qt/client/internal/local_client/FileImpl.h> | 26 | #include <unity/storage/qt/client/internal/local_client/FileImpl.h> |
4413 | 27 | #include <unity/storage/qt/client/internal/local_client/tmpfile-prefix.h> | 27 | #include <unity/storage/qt/client/internal/local_client/storage_exception.h> |
4414 | 28 | #include <unity/storage/qt/client/internal/local_client/tmpfile_prefix.h> | ||
4415 | 28 | #include <unity/storage/qt/client/internal/local_client/UploaderImpl.h> | 29 | #include <unity/storage/qt/client/internal/local_client/UploaderImpl.h> |
4416 | 29 | 30 | ||
4417 | 30 | #include <boost/algorithm/string/predicate.hpp> | 31 | #include <boost/algorithm/string/predicate.hpp> |
4418 | @@ -62,22 +63,36 @@ | |||
4419 | 62 | { | 63 | { |
4420 | 63 | } | 64 | } |
4421 | 64 | 65 | ||
4422 | 66 | QString FolderImpl::name() const | ||
4423 | 67 | { | ||
4424 | 68 | lock_guard<decltype(mutex_)> guard(mutex_); | ||
4425 | 69 | |||
4426 | 70 | throw_if_destroyed("Item::name()"); | ||
4427 | 71 | return name_; | ||
4428 | 72 | } | ||
4429 | 73 | |||
4430 | 65 | QFuture<QVector<Item::SPtr>> FolderImpl::list() const | 74 | QFuture<QVector<Item::SPtr>> FolderImpl::list() const |
4431 | 66 | { | 75 | { |
4432 | 76 | try | ||
4433 | 77 | { | ||
4434 | 78 | throw_if_destroyed("Folder::list()"); | ||
4435 | 79 | } | ||
4436 | 80 | catch (StorageException const& e) | ||
4437 | 81 | { | ||
4438 | 82 | return internal::make_exceptional_future<QVector<Item::SPtr>>(e); | ||
4439 | 83 | } | ||
4440 | 84 | |||
4441 | 67 | auto This = dynamic_pointer_cast<FolderImpl const>(shared_from_this()); // Keep this folder alive while the lambda is alive. | 85 | auto This = dynamic_pointer_cast<FolderImpl const>(shared_from_this()); // Keep this folder alive while the lambda is alive. |
4442 | 68 | auto list = [This]() | 86 | auto list = [This]() |
4443 | 69 | { | 87 | { |
4451 | 70 | lock_guard<mutex> guard(This->mutex_); | 88 | lock_guard<decltype(mutex_)> guard(This->mutex_); |
4452 | 71 | 89 | ||
4453 | 72 | if (This->deleted_) | 90 | This->throw_if_destroyed("Folder::list()"); |
4447 | 73 | { | ||
4448 | 74 | throw This->deleted_ex("Folder::list()"); | ||
4449 | 75 | } | ||
4450 | 76 | |||
4454 | 77 | try | 91 | try |
4455 | 78 | { | 92 | { |
4456 | 79 | using namespace boost::filesystem; | 93 | using namespace boost::filesystem; |
4457 | 80 | 94 | ||
4458 | 95 | auto root = This->root_.lock(); | ||
4459 | 81 | QVector<Item::SPtr> results; | 96 | QVector<Item::SPtr> results; |
4460 | 82 | for (directory_iterator it(This->native_identity().toStdString()); it != directory_iterator(); ++it) | 97 | for (directory_iterator it(This->native_identity().toStdString()); it != directory_iterator(); ++it) |
4461 | 83 | { | 98 | { |
4462 | @@ -90,11 +105,11 @@ | |||
4463 | 90 | QString path = QString::fromStdString(dirent.path().native()); | 105 | QString path = QString::fromStdString(dirent.path().native()); |
4464 | 91 | if (is_directory(s)) | 106 | if (is_directory(s)) |
4465 | 92 | { | 107 | { |
4467 | 93 | results.append(make_folder(path, This->root_)); | 108 | results.append(make_folder(path, root)); |
4468 | 94 | } | 109 | } |
4469 | 95 | else if (is_regular_file(s)) | 110 | else if (is_regular_file(s)) |
4470 | 96 | { | 111 | { |
4472 | 97 | results.append(FileImpl::make_file(path, This->root_)); | 112 | results.append(FileImpl::make_file(path, root)); |
4473 | 98 | } | 113 | } |
4474 | 99 | else | 114 | else |
4475 | 100 | { | 115 | { |
4476 | @@ -103,9 +118,9 @@ | |||
4477 | 103 | } | 118 | } |
4478 | 104 | return results; | 119 | return results; |
4479 | 105 | } | 120 | } |
4481 | 106 | catch (std::exception const& e) | 121 | catch (std::exception const&) |
4482 | 107 | { | 122 | { |
4484 | 108 | throw ResourceException(QString("Folder::list(): ") + e.what()); | 123 | throw_storage_exception("Folder::list()", current_exception()); |
4485 | 109 | } | 124 | } |
4486 | 110 | }; | 125 | }; |
4487 | 111 | return QtConcurrent::run(list); | 126 | return QtConcurrent::run(list); |
4488 | @@ -113,49 +128,51 @@ | |||
4489 | 113 | 128 | ||
4490 | 114 | QFuture<QVector<Item::SPtr>> FolderImpl::lookup(QString const& name) const | 129 | QFuture<QVector<Item::SPtr>> FolderImpl::lookup(QString const& name) const |
4491 | 115 | { | 130 | { |
4492 | 131 | try | ||
4493 | 132 | { | ||
4494 | 133 | throw_if_destroyed("Folder::lookup()"); | ||
4495 | 134 | } | ||
4496 | 135 | catch (StorageException const& e) | ||
4497 | 136 | { | ||
4498 | 137 | return internal::make_exceptional_future<QVector<Item::SPtr>>(e); | ||
4499 | 138 | } | ||
4500 | 139 | |||
4501 | 116 | auto This = dynamic_pointer_cast<FolderImpl const>(shared_from_this()); // Keep this folder alive while the lambda is alive. | 140 | auto This = dynamic_pointer_cast<FolderImpl const>(shared_from_this()); // Keep this folder alive while the lambda is alive. |
4502 | 117 | auto lookup = [This, name]() -> QVector<Item::SPtr> | 141 | auto lookup = [This, name]() -> QVector<Item::SPtr> |
4503 | 118 | { | 142 | { |
4511 | 119 | lock_guard<mutex> guard(This->mutex_); | 143 | lock_guard<decltype(mutex_)> guard(This->mutex_); |
4512 | 120 | 144 | ||
4513 | 121 | if (This->deleted_) | 145 | This->throw_if_destroyed("Folder::lookup()"); // LCOV_EXCL_LINE |
4507 | 122 | { | ||
4508 | 123 | throw This->deleted_ex("Folder::lookup()"); | ||
4509 | 124 | } | ||
4510 | 125 | |||
4514 | 126 | try | 146 | try |
4515 | 127 | { | 147 | { |
4516 | 128 | using namespace boost::filesystem; | 148 | using namespace boost::filesystem; |
4517 | 129 | 149 | ||
4518 | 150 | auto root = This->root_.lock(); | ||
4519 | 130 | path p = This->native_identity().toStdString(); | 151 | path p = This->native_identity().toStdString(); |
4520 | 131 | auto sanitized_name = sanitize(name, "Folder::lookup()"); | 152 | auto sanitized_name = sanitize(name, "Folder::lookup()"); |
4521 | 132 | if (is_reserved_path(sanitized_name)) | 153 | if (is_reserved_path(sanitized_name)) |
4522 | 133 | { | 154 | { |
4524 | 134 | throw NotExistsException("Folder::lookup(): no such item: " + name, name); | 155 | throw NotExistsException("Folder::lookup(): no such item: \"" + name + "\"", name); |
4525 | 135 | } | 156 | } |
4526 | 136 | p /= sanitized_name; | 157 | p /= sanitized_name; |
4527 | 137 | file_status s = status(p); | 158 | file_status s = status(p); |
4528 | 138 | if (is_directory(s)) | 159 | if (is_directory(s)) |
4529 | 139 | { | 160 | { |
4530 | 140 | QVector<Item::SPtr> v; | 161 | QVector<Item::SPtr> v; |
4532 | 141 | v.append(make_folder(QString::fromStdString(p.native()), This->root_)); | 162 | v.append(make_folder(QString::fromStdString(p.native()), root)); |
4533 | 142 | return v; | 163 | return v; |
4534 | 143 | } | 164 | } |
4535 | 144 | if (is_regular_file(s)) | 165 | if (is_regular_file(s)) |
4536 | 145 | { | 166 | { |
4537 | 146 | QVector<Item::SPtr> v; | 167 | QVector<Item::SPtr> v; |
4539 | 147 | v.append(FileImpl::make_file(QString::fromStdString(p.native()), This->root_)); | 168 | v.append(FileImpl::make_file(QString::fromStdString(p.native()), root)); |
4540 | 148 | return v; | 169 | return v; |
4541 | 149 | } | 170 | } |
4551 | 150 | throw NotExistsException("Folder::lookup(): no such item: " + name, name); | 171 | throw NotExistsException("Folder::lookup(): no such item: \"" + name + "\"", name); |
4552 | 151 | } | 172 | } |
4553 | 152 | catch (StorageException const&) | 173 | catch (std::exception const&) |
4554 | 153 | { | 174 | { |
4555 | 154 | throw; | 175 | throw_storage_exception("Folder::lookup()", current_exception()); |
4547 | 155 | } | ||
4548 | 156 | catch (std::exception const& e) | ||
4549 | 157 | { | ||
4550 | 158 | throw ResourceException(QString("Folder::lookup(): ") + e.what()); | ||
4556 | 159 | } | 176 | } |
4557 | 160 | }; | 177 | }; |
4558 | 161 | return QtConcurrent::run(lookup); | 178 | return QtConcurrent::run(lookup); |
4559 | @@ -163,12 +180,15 @@ | |||
4560 | 163 | 180 | ||
4561 | 164 | QFuture<Folder::SPtr> FolderImpl::create_folder(QString const& name) | 181 | QFuture<Folder::SPtr> FolderImpl::create_folder(QString const& name) |
4562 | 165 | { | 182 | { |
4564 | 166 | lock_guard<mutex> guard(mutex_); | 183 | lock_guard<decltype(mutex_)> guard(mutex_); |
4565 | 167 | 184 | ||
4570 | 168 | QFutureInterface<Folder::SPtr> qf; | 185 | try |
4571 | 169 | if (deleted_) | 186 | { |
4572 | 170 | { | 187 | throw_if_destroyed("Folder::create_folder()"); |
4573 | 171 | return make_exceptional_future<Folder::SPtr>(deleted_ex("Folder::create_folder()")); | 188 | } |
4574 | 189 | catch (StorageException const& e) | ||
4575 | 190 | { | ||
4576 | 191 | return internal::make_exceptional_future<Folder::SPtr>(e); | ||
4577 | 172 | } | 192 | } |
4578 | 173 | 193 | ||
4579 | 174 | try | 194 | try |
4580 | @@ -179,31 +199,40 @@ | |||
4581 | 179 | auto sanitized_name = sanitize(name, "Folder::create_folder()"); | 199 | auto sanitized_name = sanitize(name, "Folder::create_folder()"); |
4582 | 180 | if (is_reserved_path(sanitized_name)) | 200 | if (is_reserved_path(sanitized_name)) |
4583 | 181 | { | 201 | { |
4586 | 182 | QString msg = "Folder::create_folder(): names beginning with " + QString(TMPFILE_PREFIX) + " are reserved"; | 202 | QString msg = "Folder::create_folder(): names beginning with \"" + QString(TMPFILE_PREFIX) + "\" are reserved"; |
4587 | 183 | return make_exceptional_future<Folder::SPtr>(InvalidArgumentException(msg)); | 203 | throw InvalidArgumentException(msg); |
4588 | 184 | } | 204 | } |
4589 | 185 | p /= sanitized_name; | 205 | p /= sanitized_name; |
4590 | 206 | if (exists(p)) | ||
4591 | 207 | { | ||
4592 | 208 | QString msg = "Folder::create_folder(): item with name \"" + name + "\" exists already"; | ||
4593 | 209 | throw ExistsException(msg, native_identity() + "/" + name, name); | ||
4594 | 210 | } | ||
4595 | 186 | create_directory(p); | 211 | create_directory(p); |
4596 | 187 | return make_ready_future(make_folder(QString::fromStdString(p.native()), root_)); | 212 | return make_ready_future(make_folder(QString::fromStdString(p.native()), root_)); |
4597 | 188 | } | 213 | } |
4599 | 189 | catch (std::exception const& e) | 214 | catch (std::exception const&) |
4600 | 190 | { | 215 | { |
4602 | 191 | return make_exceptional_future<Folder::SPtr>(ResourceException(QString("Folder::create_folder: ") + e.what())); | 216 | return make_exceptional_future<Folder::SPtr>("Folder::create_folder()", current_exception()); |
4603 | 192 | } | 217 | } |
4604 | 193 | } | 218 | } |
4605 | 194 | 219 | ||
4606 | 195 | QFuture<shared_ptr<Uploader>> FolderImpl::create_file(QString const& name, int64_t size) | 220 | QFuture<shared_ptr<Uploader>> FolderImpl::create_file(QString const& name, int64_t size) |
4607 | 196 | { | 221 | { |
4609 | 197 | unique_lock<mutex> guard(mutex_); | 222 | lock_guard<decltype(mutex_)> guard(mutex_); |
4610 | 198 | 223 | ||
4614 | 199 | if (deleted_) | 224 | try |
4615 | 200 | { | 225 | { |
4616 | 201 | return make_exceptional_future<Uploader::SPtr>(deleted_ex("Folder::create_file()")); | 226 | throw_if_destroyed("Folder::create_file()"); |
4617 | 227 | } | ||
4618 | 228 | catch (StorageException const& e) | ||
4619 | 229 | { | ||
4620 | 230 | return internal::make_exceptional_future<shared_ptr<Uploader>>(e); | ||
4621 | 202 | } | 231 | } |
4622 | 203 | if (size < 0) | 232 | if (size < 0) |
4623 | 204 | { | 233 | { |
4624 | 205 | QString msg = "Folder::create_file(): size must be >= 0"; | 234 | QString msg = "Folder::create_file(): size must be >= 0"; |
4626 | 206 | return make_exceptional_future<shared_ptr<Uploader>>(InvalidArgumentException(msg)); | 235 | return internal::make_exceptional_future<shared_ptr<Uploader>>(InvalidArgumentException(msg)); |
4627 | 207 | } | 236 | } |
4628 | 208 | 237 | ||
4629 | 209 | try | 238 | try |
4630 | @@ -214,14 +243,14 @@ | |||
4631 | 214 | auto sanitized_name = sanitize(name, "Folder::create_file()"); | 243 | auto sanitized_name = sanitize(name, "Folder::create_file()"); |
4632 | 215 | if (is_reserved_path(sanitized_name)) | 244 | if (is_reserved_path(sanitized_name)) |
4633 | 216 | { | 245 | { |
4636 | 217 | QString msg = "Folder::create_file(): names beginning with " + QString(TMPFILE_PREFIX) + " are reserved"; | 246 | QString msg = "Folder::create_file(): names beginning with \"" + QString(TMPFILE_PREFIX) + "\" are reserved"; |
4637 | 218 | return make_exceptional_future<Uploader::SPtr>(InvalidArgumentException(msg)); | 247 | throw InvalidArgumentException(msg); |
4638 | 219 | } | 248 | } |
4639 | 220 | p /= sanitized_name; | 249 | p /= sanitized_name; |
4640 | 221 | if (exists(p)) | 250 | if (exists(p)) |
4641 | 222 | { | 251 | { |
4642 | 223 | QString msg = "Folder::create_file(): item with name \"" + name + "\" exists already"; | 252 | QString msg = "Folder::create_file(): item with name \"" + name + "\" exists already"; |
4644 | 224 | return make_exceptional_future<Uploader::SPtr>(ExistsException(msg, native_identity(), name)); | 253 | throw ExistsException(msg, native_identity() + "/" + name, name); |
4645 | 225 | } | 254 | } |
4646 | 226 | auto impl = new UploaderImpl(shared_ptr<File>(), | 255 | auto impl = new UploaderImpl(shared_ptr<File>(), |
4647 | 227 | size, | 256 | size, |
4648 | @@ -231,9 +260,9 @@ | |||
4649 | 231 | Uploader::SPtr uploader(new Uploader(impl)); | 260 | Uploader::SPtr uploader(new Uploader(impl)); |
4650 | 232 | return make_ready_future(uploader); | 261 | return make_ready_future(uploader); |
4651 | 233 | } | 262 | } |
4653 | 234 | catch (std::exception const& e) | 263 | catch (std::exception const&) |
4654 | 235 | { | 264 | { |
4656 | 236 | return make_exceptional_future<Uploader::SPtr>(ResourceException(QString("Folder::create_file: ") + e.what())); | 265 | return make_exceptional_future<Uploader::SPtr>("Folder::create_file()", current_exception()); |
4657 | 237 | } | 266 | } |
4658 | 238 | } | 267 | } |
4659 | 239 | 268 | ||
4660 | 240 | 269 | ||
4661 | === modified file 'src/qt/client/internal/local_client/ItemImpl.cpp' | |||
4662 | --- src/qt/client/internal/local_client/ItemImpl.cpp 2016-07-22 00:17:24 +0000 | |||
4663 | +++ src/qt/client/internal/local_client/ItemImpl.cpp 2016-09-09 02:13:43 +0000 | |||
4664 | @@ -21,14 +21,16 @@ | |||
4665 | 21 | #include <unity/storage/internal/safe_strerror.h> | 21 | #include <unity/storage/internal/safe_strerror.h> |
4666 | 22 | #include <unity/storage/qt/client/Account.h> | 22 | #include <unity/storage/qt/client/Account.h> |
4667 | 23 | #include <unity/storage/qt/client/Exceptions.h> | 23 | #include <unity/storage/qt/client/Exceptions.h> |
4668 | 24 | #include <unity/storage/qt/client/internal/make_future.h> | ||
4669 | 25 | #include <unity/storage/qt/client/internal/local_client/AccountImpl.h> | 24 | #include <unity/storage/qt/client/internal/local_client/AccountImpl.h> |
4670 | 26 | #include <unity/storage/qt/client/internal/local_client/FileImpl.h> | 25 | #include <unity/storage/qt/client/internal/local_client/FileImpl.h> |
4671 | 27 | #include <unity/storage/qt/client/internal/local_client/RootImpl.h> | 26 | #include <unity/storage/qt/client/internal/local_client/RootImpl.h> |
4673 | 28 | #include <unity/storage/qt/client/internal/local_client/tmpfile-prefix.h> | 27 | #include <unity/storage/qt/client/internal/local_client/storage_exception.h> |
4674 | 28 | #include <unity/storage/qt/client/internal/local_client/tmpfile_prefix.h> | ||
4675 | 29 | #include <unity/storage/qt/client/internal/make_future.h> | ||
4676 | 29 | 30 | ||
4677 | 30 | #include <boost/algorithm/string/predicate.hpp> | 31 | #include <boost/algorithm/string/predicate.hpp> |
4678 | 31 | #pragma GCC diagnostic push | 32 | #pragma GCC diagnostic push |
4679 | 33 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
4680 | 32 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | 34 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" |
4681 | 33 | #include <QtConcurrent> | 35 | #include <QtConcurrent> |
4682 | 34 | #pragma GCC diagnostic pop | 36 | #pragma GCC diagnostic pop |
4683 | @@ -54,7 +56,6 @@ | |||
4684 | 54 | 56 | ||
4685 | 55 | ItemImpl::ItemImpl(QString const& identity, ItemType type) | 57 | ItemImpl::ItemImpl(QString const& identity, ItemType type) |
4686 | 56 | : ItemBase(identity, type) | 58 | : ItemBase(identity, type) |
4687 | 57 | , deleted_(false) | ||
4688 | 58 | { | 59 | { |
4689 | 59 | assert(!identity.isEmpty()); | 60 | assert(!identity.isEmpty()); |
4690 | 60 | auto path = boost::filesystem::canonical(identity.toStdString()); | 61 | auto path = boost::filesystem::canonical(identity.toStdString()); |
4691 | @@ -64,102 +65,70 @@ | |||
4692 | 64 | 65 | ||
4693 | 65 | ItemImpl::~ItemImpl() = default; | 66 | ItemImpl::~ItemImpl() = default; |
4694 | 66 | 67 | ||
4695 | 67 | QString ItemImpl::name() const | ||
4696 | 68 | { | ||
4697 | 69 | lock_guard<mutex> guard(mutex_); | ||
4698 | 70 | |||
4699 | 71 | if (deleted_) | ||
4700 | 72 | { | ||
4701 | 73 | throw deleted_ex("Item::name()"); | ||
4702 | 74 | } | ||
4703 | 75 | return name_; | ||
4704 | 76 | } | ||
4705 | 77 | |||
4706 | 78 | QString ItemImpl::etag() const | 68 | QString ItemImpl::etag() const |
4707 | 79 | { | 69 | { |
4709 | 80 | lock_guard<mutex> guard(mutex_); | 70 | lock_guard<decltype(mutex_)> guard(mutex_); |
4710 | 81 | 71 | ||
4715 | 82 | if (deleted_) | 72 | throw_if_destroyed("Item::etag()"); |
4712 | 83 | { | ||
4713 | 84 | throw deleted_ex("Item::etag()"); | ||
4714 | 85 | } | ||
4716 | 86 | return etag_; | 73 | return etag_; |
4717 | 87 | } | 74 | } |
4718 | 88 | 75 | ||
4719 | 89 | QVariantMap ItemImpl::metadata() const | 76 | QVariantMap ItemImpl::metadata() const |
4720 | 90 | { | 77 | { |
4722 | 91 | lock_guard<mutex> guard(mutex_); | 78 | lock_guard<decltype(mutex_)> guard(mutex_); |
4723 | 92 | 79 | ||
4728 | 93 | if (deleted_) | 80 | throw_if_destroyed("Item::metadata()"); |
4725 | 94 | { | ||
4726 | 95 | throw deleted_ex("Item::metadata()"); | ||
4727 | 96 | } | ||
4729 | 97 | return metadata_; | 81 | return metadata_; |
4730 | 98 | } | 82 | } |
4731 | 99 | 83 | ||
4732 | 100 | QDateTime ItemImpl::last_modified_time() const | 84 | QDateTime ItemImpl::last_modified_time() const |
4733 | 101 | { | 85 | { |
4735 | 102 | lock_guard<mutex> guard(mutex_); | 86 | lock_guard<decltype(mutex_)> guard(mutex_); |
4736 | 103 | 87 | ||
4741 | 104 | if (deleted_) | 88 | throw_if_destroyed("Item::last_modified_time()"); |
4738 | 105 | { | ||
4739 | 106 | throw deleted_ex("Item::last_modified_time()"); | ||
4740 | 107 | } | ||
4742 | 108 | return modified_time_; | 89 | return modified_time_; |
4743 | 109 | } | 90 | } |
4744 | 110 | 91 | ||
4745 | 111 | namespace | ||
4746 | 112 | { | ||
4747 | 113 | |||
4748 | 114 | using namespace boost::filesystem; | ||
4749 | 115 | |||
4750 | 116 | void copy_recursively(path const& source, path const& target) | ||
4751 | 117 | { | ||
4752 | 118 | auto s = status(source); | ||
4753 | 119 | if (is_regular_file(s)) | ||
4754 | 120 | { | ||
4755 | 121 | copy_file(source, target); | ||
4756 | 122 | return; | ||
4757 | 123 | } | ||
4758 | 124 | else if (is_directory(s)) | ||
4759 | 125 | { | ||
4760 | 126 | copy_directory(source, target); // Poorly named in boost; this creates the target dir without recursion | ||
4761 | 127 | for (directory_iterator it(source); it != directory_iterator(); ++it) | ||
4762 | 128 | { | ||
4763 | 129 | path source_entry = it->path(); | ||
4764 | 130 | path target_entry = target; | ||
4765 | 131 | target_entry /= source_entry.filename(); | ||
4766 | 132 | copy_recursively(source_entry, target_entry); | ||
4767 | 133 | } | ||
4768 | 134 | } | ||
4769 | 135 | else | ||
4770 | 136 | { | ||
4771 | 137 | // Ignore everything that's not a directory or file. | ||
4772 | 138 | } | ||
4773 | 139 | } | ||
4774 | 140 | |||
4775 | 141 | } // namespace | ||
4776 | 142 | |||
4777 | 143 | QFuture<shared_ptr<Item>> ItemImpl::copy(shared_ptr<Folder> const& new_parent, QString const& new_name) | 92 | QFuture<shared_ptr<Item>> ItemImpl::copy(shared_ptr<Folder> const& new_parent, QString const& new_name) |
4778 | 144 | { | 93 | { |
4779 | 94 | if (!new_parent) | ||
4780 | 95 | { | ||
4781 | 96 | QString msg = "Item::copy(): new_parent cannot be nullptr"; | ||
4782 | 97 | return internal::make_exceptional_future<shared_ptr<Item>>(InvalidArgumentException(msg)); | ||
4783 | 98 | } | ||
4784 | 99 | auto new_parent_impl = dynamic_pointer_cast<FolderImpl>(new_parent->p_); | ||
4785 | 100 | |||
4786 | 101 | lock(mutex_, new_parent_impl->mutex_); | ||
4787 | 102 | lock_guard<decltype(mutex_)> this_guard(mutex_, std::adopt_lock); | ||
4788 | 103 | lock_guard<decltype(mutex_)> other_guard(new_parent_impl->mutex_, adopt_lock); | ||
4789 | 104 | |||
4790 | 105 | try | ||
4791 | 106 | { | ||
4792 | 107 | throw_if_destroyed("Item::copy()"); | ||
4793 | 108 | new_parent_impl->throw_if_destroyed("Item::copy()"); | ||
4794 | 109 | } | ||
4795 | 110 | catch (StorageException const& e) | ||
4796 | 111 | { | ||
4797 | 112 | return internal::make_exceptional_future<shared_ptr<Item>>(e); | ||
4798 | 113 | } | ||
4799 | 114 | |||
4800 | 145 | auto This = dynamic_pointer_cast<ItemImpl>(shared_from_this()); // Keep this item alive while the lambda is alive. | 115 | auto This = dynamic_pointer_cast<ItemImpl>(shared_from_this()); // Keep this item alive while the lambda is alive. |
4801 | 146 | auto copy = [This, new_parent, new_name]() -> Item::SPtr | 116 | auto copy = [This, new_parent, new_name]() -> Item::SPtr |
4802 | 147 | { | 117 | { |
4803 | 148 | auto new_parent_impl = dynamic_pointer_cast<FolderImpl>(new_parent->p_); | 118 | auto new_parent_impl = dynamic_pointer_cast<FolderImpl>(new_parent->p_); |
4804 | 149 | 119 | ||
4805 | 150 | lock(This->mutex_, new_parent_impl->mutex_); | 120 | lock(This->mutex_, new_parent_impl->mutex_); |
4815 | 151 | lock_guard<mutex> this_guard(This->mutex_, std::adopt_lock); | 121 | lock_guard<decltype(mutex_)> this_guard(This->mutex_, std::adopt_lock); |
4816 | 152 | lock_guard<mutex> other_guard(new_parent_impl->mutex_, adopt_lock); | 122 | lock_guard<decltype(mutex_)> other_guard(new_parent_impl->mutex_, adopt_lock); |
4817 | 153 | 123 | ||
4818 | 154 | if (This->deleted_ || new_parent_impl->deleted_) | 124 | This->throw_if_destroyed("Item::copy()"); |
4819 | 155 | { | 125 | new_parent_impl->throw_if_destroyed("Item::copy()"); |
4820 | 156 | throw This->deleted_ex("Item::copy"); | 126 | |
4821 | 157 | } | 127 | // TODO: This needs to deeply compare account identity because the client may have refreshed the accounts list. |
4822 | 158 | 128 | if (This->root()->account() != new_parent->root()->account()) // Throws if account or runtime were destroyed. | |
4814 | 159 | if (This->root()->account() != new_parent->root()->account()) | ||
4823 | 160 | { | 129 | { |
4824 | 161 | // Can't do cross-account copy. | 130 | // Can't do cross-account copy. |
4826 | 162 | QString msg = QString("Item::copy(): Source (") + This->name_ + ") and target (" | 131 | QString msg = QString("Item::copy(): source (") + This->name_ + ") and target (" |
4827 | 163 | + new_name + ") must belong to the same account"; | 132 | + new_name + ") must belong to the same account"; |
4828 | 164 | throw LogicException(msg); | 133 | throw LogicException(msg); |
4829 | 165 | } | 134 | } |
4830 | @@ -175,22 +144,22 @@ | |||
4831 | 175 | target_path /= sanitized_name; | 144 | target_path /= sanitized_name; |
4832 | 176 | if (is_reserved_path(target_path)) | 145 | if (is_reserved_path(target_path)) |
4833 | 177 | { | 146 | { |
4835 | 178 | QString msg = "Item::copy(): names beginning with " + QString(TMPFILE_PREFIX) + " are reserved"; | 147 | QString msg = "Item::copy(): names beginning with \"" + QString(TMPFILE_PREFIX) + "\" are reserved"; |
4836 | 179 | throw InvalidArgumentException(msg); | 148 | throw InvalidArgumentException(msg); |
4837 | 180 | } | 149 | } |
4838 | 181 | 150 | ||
4839 | 151 | if (exists(target_path)) | ||
4840 | 152 | { | ||
4841 | 153 | QString msg = "Item::copy(): item with name \"" + new_name + "\" exists already"; | ||
4842 | 154 | throw ExistsException(msg, This->identity_, This->name_); | ||
4843 | 155 | } | ||
4844 | 156 | |||
4845 | 182 | if (This->type_ == ItemType::file) | 157 | if (This->type_ == ItemType::file) |
4846 | 183 | { | 158 | { |
4847 | 184 | copy_file(source_path, target_path); | 159 | copy_file(source_path, target_path); |
4848 | 185 | return FileImpl::make_file(QString::fromStdString(target_path.native()), new_parent_impl->root_); | 160 | return FileImpl::make_file(QString::fromStdString(target_path.native()), new_parent_impl->root_); |
4849 | 186 | } | 161 | } |
4850 | 187 | 162 | ||
4851 | 188 | if (exists(target_path)) | ||
4852 | 189 | { | ||
4853 | 190 | QString msg = "Item::copy(): item with name \"" + new_name + "\" exists already"; | ||
4854 | 191 | throw ExistsException(msg, This->identity_, This->name_); | ||
4855 | 192 | } | ||
4856 | 193 | |||
4857 | 194 | // For recursive copy, we create a temporary directory in lieu of target_path and recursively copy | 163 | // For recursive copy, we create a temporary directory in lieu of target_path and recursively copy |
4858 | 195 | // everything into the temporary directory. This ensures that we don't invalidate directory iterators | 164 | // everything into the temporary directory. This ensures that we don't invalidate directory iterators |
4859 | 196 | // by creating things while we are iterating, potentially getting trapped in an infinite loop. | 165 | // by creating things while we are iterating, potentially getting trapped in an infinite loop. |
4860 | @@ -199,7 +168,7 @@ | |||
4861 | 199 | create_directories(tmp_path); | 168 | create_directories(tmp_path); |
4862 | 200 | for (directory_iterator it(source_path); it != directory_iterator(); ++it) | 169 | for (directory_iterator it(source_path); it != directory_iterator(); ++it) |
4863 | 201 | { | 170 | { |
4865 | 202 | if (tmp_path.compare(canonical(it->path())) == 0) | 171 | if (is_reserved_path(it->path())) |
4866 | 203 | { | 172 | { |
4867 | 204 | continue; // Don't recurse into the temporary directory | 173 | continue; // Don't recurse into the temporary directory |
4868 | 205 | } | 174 | } |
4869 | @@ -209,15 +178,15 @@ | |||
4870 | 209 | path source_entry = it->path(); | 178 | path source_entry = it->path(); |
4871 | 210 | path target_entry = tmp_path; | 179 | path target_entry = tmp_path; |
4872 | 211 | target_entry /= source_entry.filename(); | 180 | target_entry /= source_entry.filename(); |
4874 | 212 | copy_recursively(source_entry, target_entry); | 181 | ItemImpl::copy_recursively(source_entry, target_entry); |
4875 | 213 | } | 182 | } |
4876 | 214 | } | 183 | } |
4877 | 215 | rename(tmp_path, target_path); | 184 | rename(tmp_path, target_path); |
4878 | 216 | return FolderImpl::make_folder(QString::fromStdString(target_path.native()), new_parent_impl->root_); | 185 | return FolderImpl::make_folder(QString::fromStdString(target_path.native()), new_parent_impl->root_); |
4879 | 217 | } | 186 | } |
4881 | 218 | catch (std::exception const& e) | 187 | catch (std::exception const&) |
4882 | 219 | { | 188 | { |
4884 | 220 | throw ResourceException(QString("Item::copy(): ") + e.what()); | 189 | throw_storage_exception("Item::copy()", current_exception()); |
4885 | 221 | } | 190 | } |
4886 | 222 | }; | 191 | }; |
4887 | 223 | return QtConcurrent::run(copy); | 192 | return QtConcurrent::run(copy); |
4888 | @@ -225,31 +194,51 @@ | |||
4889 | 225 | 194 | ||
4890 | 226 | QFuture<shared_ptr<Item>> ItemImpl::move(shared_ptr<Folder> const& new_parent, QString const& new_name) | 195 | QFuture<shared_ptr<Item>> ItemImpl::move(shared_ptr<Folder> const& new_parent, QString const& new_name) |
4891 | 227 | { | 196 | { |
4892 | 197 | if (!new_parent) | ||
4893 | 198 | { | ||
4894 | 199 | QString msg = "Item::move(): new_parent cannot be nullptr"; | ||
4895 | 200 | return internal::make_exceptional_future<shared_ptr<Item>>(InvalidArgumentException(msg)); | ||
4896 | 201 | } | ||
4897 | 202 | auto new_parent_impl = dynamic_pointer_cast<FolderImpl>(new_parent->p_); | ||
4898 | 203 | |||
4899 | 204 | lock(mutex_, new_parent_impl->mutex_); | ||
4900 | 205 | lock_guard<decltype(mutex_)> this_guard(mutex_, std::adopt_lock); | ||
4901 | 206 | lock_guard<decltype(mutex_)> other_guard(new_parent_impl->mutex_, adopt_lock); | ||
4902 | 207 | |||
4903 | 208 | try | ||
4904 | 209 | { | ||
4905 | 210 | throw_if_destroyed("Item::move()"); | ||
4906 | 211 | new_parent_impl->throw_if_destroyed("Item::move()"); | ||
4907 | 212 | } | ||
4908 | 213 | catch (StorageException const& e) | ||
4909 | 214 | { | ||
4910 | 215 | return internal::make_exceptional_future<shared_ptr<Item>>(e); | ||
4911 | 216 | } | ||
4912 | 217 | |||
4913 | 228 | auto This = dynamic_pointer_cast<ItemImpl>(shared_from_this()); // Keep this item alive while the lambda is alive. | 218 | auto This = dynamic_pointer_cast<ItemImpl>(shared_from_this()); // Keep this item alive while the lambda is alive. |
4914 | 229 | auto move = [This, new_parent, new_name]() -> Item::SPtr | 219 | auto move = [This, new_parent, new_name]() -> Item::SPtr |
4915 | 230 | { | 220 | { |
4916 | 231 | auto new_parent_impl = dynamic_pointer_cast<FolderImpl>(new_parent->p_); | 221 | auto new_parent_impl = dynamic_pointer_cast<FolderImpl>(new_parent->p_); |
4917 | 232 | 222 | ||
4918 | 233 | lock(This->mutex_, new_parent_impl->mutex_); | 223 | lock(This->mutex_, new_parent_impl->mutex_); |
4928 | 234 | lock_guard<mutex> this_guard(This->mutex_, std::adopt_lock); | 224 | lock_guard<decltype(mutex_)> this_guard(This->mutex_, std::adopt_lock); |
4929 | 235 | lock_guard<mutex> other_guard(new_parent_impl->mutex_, adopt_lock); | 225 | lock_guard<decltype(mutex_)> other_guard(new_parent_impl->mutex_, adopt_lock); |
4930 | 236 | 226 | ||
4931 | 237 | if (This->deleted_ || new_parent_impl->deleted_) | 227 | This->throw_if_destroyed("Item::move()"); |
4932 | 238 | { | 228 | new_parent_impl->throw_if_destroyed("Item::move()"); |
4933 | 239 | throw This->deleted_ex("Item::move"); | 229 | |
4934 | 240 | } | 230 | // TODO: This needs to deeply compare account identity because the client may have refreshed the accounts list. |
4935 | 241 | 231 | if (This->root()->account() != new_parent->root()->account()) // Throws if account or runtime were destroyed. | |
4927 | 242 | if (This->root()->account() != new_parent->root()->account()) | ||
4936 | 243 | { | 232 | { |
4937 | 244 | // Can't do cross-account move. | 233 | // Can't do cross-account move. |
4939 | 245 | QString msg = QString("Item::move(): Source (") + This->name_ + ") and target (" | 234 | QString msg = QString("Item::move(): source (") + This->name_ + ") and target (" |
4940 | 246 | + new_name + ") must belong to the same account"; | 235 | + new_name + ") must belong to the same account"; |
4941 | 247 | throw LogicException(msg); | 236 | throw LogicException(msg); |
4942 | 248 | } | 237 | } |
4943 | 249 | if (This->type_ == ItemType::root) | 238 | if (This->type_ == ItemType::root) |
4944 | 250 | { | 239 | { |
4945 | 251 | // Can't move a root. | 240 | // Can't move a root. |
4947 | 252 | throw LogicException("Item::move(): Cannot move root folder"); | 241 | throw LogicException("Item::move(): cannot move root folder"); |
4948 | 253 | } | 242 | } |
4949 | 254 | 243 | ||
4950 | 255 | try | 244 | try |
4951 | @@ -265,7 +254,7 @@ | |||
4952 | 265 | } | 254 | } |
4953 | 266 | if (is_reserved_path(target_path)) | 255 | if (is_reserved_path(target_path)) |
4954 | 267 | { | 256 | { |
4956 | 268 | QString msg = "Item::move(): names beginning with " + QString(TMPFILE_PREFIX) + " are reserved"; | 257 | QString msg = "Item::move(): names beginning with \"" + QString(TMPFILE_PREFIX) + "\" are reserved"; |
4957 | 269 | throw InvalidArgumentException(msg); | 258 | throw InvalidArgumentException(msg); |
4958 | 270 | } | 259 | } |
4959 | 271 | rename(This->native_identity().toStdString(), target_path); | 260 | rename(This->native_identity().toStdString(), target_path); |
4960 | @@ -276,9 +265,9 @@ | |||
4961 | 276 | } | 265 | } |
4962 | 277 | return FileImpl::make_file(QString::fromStdString(target_path.native()), new_parent_impl->root_); | 266 | return FileImpl::make_file(QString::fromStdString(target_path.native()), new_parent_impl->root_); |
4963 | 278 | } | 267 | } |
4965 | 279 | catch (std::exception const& e) | 268 | catch (std::exception const&) |
4966 | 280 | { | 269 | { |
4968 | 281 | throw ResourceException(QString("Item::move(): ") + e.what()); | 270 | throw_storage_exception(QString("Item::move(): "), current_exception()); |
4969 | 282 | } | 271 | } |
4970 | 283 | }; | 272 | }; |
4971 | 284 | return QtConcurrent::run(move); | 273 | return QtConcurrent::run(move); |
4972 | @@ -286,18 +275,15 @@ | |||
4973 | 286 | 275 | ||
4974 | 287 | QFuture<QVector<Folder::SPtr>> ItemImpl::parents() const | 276 | QFuture<QVector<Folder::SPtr>> ItemImpl::parents() const |
4975 | 288 | { | 277 | { |
4977 | 289 | lock_guard<mutex> guard(mutex_); | 278 | lock_guard<decltype(mutex_)> guard(mutex_); |
4978 | 290 | 279 | ||
4981 | 291 | QFutureInterface<QVector<Folder::SPtr>> qf; | 280 | try |
4980 | 292 | if (deleted_) | ||
4982 | 293 | { | 281 | { |
4984 | 294 | return make_exceptional_future<QVector<Folder::SPtr>>(deleted_ex("Item::parents()")); | 282 | throw_if_destroyed("Item::parents()"); |
4985 | 295 | } | 283 | } |
4989 | 296 | 284 | catch (StorageException const& e) | |
4987 | 297 | Root::SPtr root = root_.lock(); | ||
4988 | 298 | if (!root) | ||
4990 | 299 | { | 285 | { |
4992 | 300 | return make_exceptional_future<QVector<Folder::SPtr>>(RuntimeDestroyedException("Item::parents()")); | 286 | return internal::make_exceptional_future<QVector<Folder::SPtr>>(e); |
4993 | 301 | } | 287 | } |
4994 | 302 | 288 | ||
4995 | 303 | using namespace boost::filesystem; | 289 | using namespace boost::filesystem; |
4996 | @@ -306,10 +292,11 @@ | |||
4997 | 306 | path p = native_identity().toStdString(); | 292 | path p = native_identity().toStdString(); |
4998 | 307 | QString parent_path = QString::fromStdString(p.parent_path().native()); | 293 | QString parent_path = QString::fromStdString(p.parent_path().native()); |
4999 | 308 | 294 | ||
5000 | 295 | auto root = root_.lock(); |
Looks good, thanks!