Merge lp:~michihenning/unity-scopes-api/app-directory into lp:unity-scopes-api/devel

Proposed by Michi Henning
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 537
Merged at revision: 532
Proposed branch: lp:~michihenning/unity-scopes-api/app-directory
Merge into: lp:unity-scopes-api/devel
Diff against target: 879 lines (+315/-98)
24 files modified
CONFIGFILES (+19/-2)
RELEASE_NOTES.md (+3/-0)
debian/changelog (+3/-2)
debian/libunity-scopes3.symbols (+9/-2)
doc/tutorial.dox (+28/-0)
include/unity/scopes/ScopeBase.h (+19/-1)
include/unity/scopes/internal/RuntimeConfig.h (+6/-3)
include/unity/scopes/internal/RuntimeImpl.h (+3/-1)
include/unity/scopes/internal/ScopeBaseImpl.h (+6/-0)
include/unity/scopes/testing/TypedScopeFixture.h (+25/-4)
scoperegistry/scoperegistry.cpp (+9/-5)
src/scopes/ScopeBase.cpp (+5/-0)
src/scopes/internal/RuntimeConfig.cpp (+56/-27)
src/scopes/internal/RuntimeImpl.cpp (+22/-12)
src/scopes/internal/ScopeBaseImpl.cpp (+22/-0)
src/scopes/testing/TypedScopeFixture.cpp (+21/-4)
test/gtest/scopes/internal/RuntimeConfig/CacheDir.ini (+3/-2)
test/gtest/scopes/internal/RuntimeConfig/ConfigDir.ini (+3/-2)
test/gtest/scopes/internal/RuntimeConfig/NoAppDir.ini (+2/-0)
test/gtest/scopes/internal/RuntimeConfig/NoCacheDir.ini (+1/-1)
test/gtest/scopes/internal/RuntimeConfig/NoConfigDir.ini (+2/-1)
test/gtest/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp (+41/-25)
test/gtest/scopes/internal/RuntimeImpl/Runtime.ini.in (+3/-2)
test/gtest/scopes/internal/RuntimeImpl/RuntimeImpl_test.cpp (+4/-2)
To merge this branch: bzr merge lp:~michihenning/unity-scopes-api/app-directory
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+241648@code.launchpad.net

Commit message

Added app_directory() method to ScopeBase. It returns the directory that is shared if an app and a scope are installed from a single click packages. The directory is writable to the app, but only readable to the scope, so the app can pass information to the scope, but not vice versa.

Updated doc accordingly and added new section to the tutorial for this.

Renamed DataDir config item in Runtime.ini to CacheDir, for consistency with the public API naming.

Added tests and tightened a few existing tests.

Added missing directory set methods to TypedScopeFixture.

Description of the change

Added app_directory() method to ScopeBase. It returns the directory that is shared if an app and a scope are installed from a single click packages. The directory is writable to the app, but only readable to the scope, so the app can pass information to the scope, but not vice versa.

Updated doc accordingly and added new section to the tutorial for this.

Renamed DataDir config item in Runtime.ini to CacheDir, for consistency with the public API naming.

Added tests and tightened a few existing tests.

Added missing directory set methods to TypedScopeFixture.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good, but since it's not a small change, I have to find and comment on something ;)

-unity-scopes-api (0.6.8-0ubuntu1) UNRELEASED; urgency=medium
+unity-scopes-api (0.6.8-0ubuntu2) UNRELEASED; urgency=medium

Since it's unreleased, it should remain unchanged ('0.6.8-0ubuntu1').

review: Needs Fixing
537. By Michi Henning

Merged devel and resolved conflicts. Fixed version
in changelog.

Revision history for this message
Michi Henning (michihenning) wrote :

> Looks good, but since it's not a small change, I have to find and comment on
> something ;)

I think Michal must have passed his genetic imprint to you before he left! ;-)

Thanks for spotting this, should be fixed now!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Thanks, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CONFIGFILES'
2--- CONFIGFILES 2014-11-10 11:25:45 +0000
3+++ CONFIGFILES 2014-11-18 20:53:45 +0000
4@@ -92,9 +92,9 @@
5 config group, otherwise the middleware can prematurely conclude that
6 a locate() request failed to start a scope.
7
8-- DataDir
9+- CacheDir
10
11- The parent directory under which the run time writes scope-specific data files
12+ The parent directory under which a scope can write scope-specific data files
13 (such as caches).
14
15 The default value is $HOME/.local/share/unity-scopes.
16@@ -105,6 +105,22 @@
17 $HOME/.local/share/unity-scopes/leaf-net/<scope_id>/some_file (for confined scopes)
18 and $HOME/.local/share/unity-scopes/unconfined/<scope_id>/some_file (for unconfined scopes).
19
20+- AppDir
21+
22+ The parent directory under which a scope can read data provided by an
23+ app that was installed from the same click package.
24+
25+ The default value is $HOME/.local/share.
26+
27+ Note that the actual directory is a subdirectory of
28+ this directory, for example:
29+
30+ $HOME/.local/share/<app-pkgname>
31+
32+ The app has read/write permission for this directory and the files in it,
33+ the scope has read-only permission, so communication is from the app to
34+ the scope, not vice versa.
35+
36 - ConfigDir
37
38 The parent directory under which the runtime writes the scope configration files.
39@@ -116,6 +132,7 @@
40
41 $HOME/.config/unity-scopes/<scope_id>/settings.ini
42
43+
44 Zmq.ini
45 -------
46
47
48=== modified file 'RELEASE_NOTES.md'
49--- RELEASE_NOTES.md 2014-11-13 05:05:54 +0000
50+++ RELEASE_NOTES.md 2014-11-18 20:53:45 +0000
51@@ -7,6 +7,9 @@
52 - Replaced dbus-send with "list updated" pub/sub to invalidate smart scopes.
53 - Added support for Version attribute in scope.ini file, and added version() accessor
54 to ScopeMetadata.
55+ - Added app_directory() method ScopeBase for scopes that are installed from the same
56+ click package as an app. This allows the app to share data with its scope (but
57+ not vice versa).
58 - Added missing methods for settings_definitions(), location_data_needed(),
59 and child_scope_ids() to testing::ScopeMetadataBuilder.
60
61
62=== modified file 'debian/changelog'
63--- debian/changelog 2014-11-12 23:12:58 +0000
64+++ debian/changelog 2014-11-18 20:53:45 +0000
65@@ -1,16 +1,17 @@
66-unity-scopes-api (0.6.8-0ubuntu2) UNRELEASED; urgency=medium
67+unity-scopes-api (0.6.8-0ubuntu1) UNRELEASED; urgency=medium
68
69 [ Pawel Stolowski ]
70 * Added support for ChildScopes scope .ini option.
71 * Replaced dbus-send with "list updated" pub/sub to invalidate smart scopes.
72
73 [ Michi Henning ]
74+ * Added app_directory() method to ScopeBase.
75 * Added support for Version attribute in scope.ini file, and added
76 version() accessor to ScopeMetadata.
77 * Added missing methods for settings_definitions(), location_data_needed(),
78 and child_scope_ids() to testing::ScopeMetadataBuilder.
79
80- -- Michi Henning <michi.henning@canonical.com> Thu, 13 Nov 2014 09:12:20 +1000
81+ -- Michi Henning <michi.henning@canonical.com> Thu, 13 Nov 2014 13:10:09 +1000
82
83 unity-scopes-api (0.6.7+14.10.20141014-0ubuntu1) 14.09; urgency=low
84
85
86=== modified file 'debian/libunity-scopes3.symbols'
87--- debian/libunity-scopes3.symbols 2014-11-18 08:46:17 +0000
88+++ debian/libunity-scopes3.symbols 2014-11-18 20:53:45 +0000
89@@ -396,10 +396,12 @@
90 (c++)"unity::scopes::internal::RegistryObject::set_remote_registry(std::shared_ptr<unity::scopes::internal::MWRegistry> const&)@Base" 0.4.0+14.04.20140312.1
91 (c++)"unity::scopes::internal::RegistryObject::ss_list_update()@Base" 0replaceme
92 (c++)"unity::scopes::internal::RegistryObject::state_receiver()@Base" 0.4.2+14.04.20140404.2
93+ (c++)"unity::scopes::internal::RuntimeConfig::app_directory() const@Base" 0replaceme
94+ (c++)"unity::scopes::internal::RuntimeConfig::cache_directory() const@Base" 0replaceme
95 (c++)"unity::scopes::internal::RuntimeConfig::config_directory() const@Base" 0.6.2+rtm+rtm+rtm+14.09.20140818
96- (c++)"unity::scopes::internal::RuntimeConfig::data_directory() const@Base" 0.5.2+14.10.20140709.2
97+ (c++)"unity::scopes::internal::RuntimeConfig::default_app_directory()@Base" 0replaceme
98+ (c++)"unity::scopes::internal::RuntimeConfig::default_cache_directory()@Base" 0replaceme
99 (c++)"unity::scopes::internal::RuntimeConfig::default_config_directory()@Base" 0.6.2+rtm+rtm+rtm+14.09.20140818
100- (c++)"unity::scopes::internal::RuntimeConfig::default_data_directory()@Base" 0.5.2+14.10.20140709.2
101 (c++)"unity::scopes::internal::RuntimeConfig::default_middleware_configfile() const@Base" 0.4.2+14.04.20140404.2
102 (c++)"unity::scopes::internal::RuntimeConfig::default_middleware() const@Base" 0.4.2+14.04.20140404.2
103 (c++)"unity::scopes::internal::RuntimeConfig::reap_expiry() const@Base" 0.4.5+14.10.20140513
104@@ -417,6 +419,7 @@
105 (c++)"unity::scopes::internal::RuntimeImpl::demangled_id() const@Base" 0replaceme
106 (c++)"unity::scopes::internal::RuntimeImpl::destroy()@Base" 0.4.0+14.04.20140312.1
107 (c++)"unity::scopes::internal::RuntimeImpl::factory() const@Base" 0.4.0+14.04.20140312.1
108+ (c++)"unity::scopes::internal::RuntimeImpl::find_app_dir() const@Base" 0replaceme
109 (c++)"unity::scopes::internal::RuntimeImpl::find_cache_dir() const@Base" 0replaceme
110 (c++)"unity::scopes::internal::RuntimeImpl::find_tmp_dir() const@Base" 0replaceme
111 (c++)"unity::scopes::internal::RuntimeImpl::future_queue() const@Base" 0.4.3+14.10.20140428
112@@ -748,6 +751,7 @@
113 (c++)"unity::scopes::Runtime::Runtime(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0.4.0+14.04.20140312.1
114 (c++)"unity::scopes::Runtime::string_to_proxy(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const@Base" 0.4.0+14.04.20140312.1
115 (c++)"unity::scopes::ScopeBase::activate(unity::scopes::Result const&, unity::scopes::ActionMetadata const&)@Base" 0.4.0+14.04.20140312.1
116+ (c++)"unity::scopes::ScopeBase::app_directory() const@Base" 0replaceme
117 (c++)"unity::scopes::ScopeBase::cache_directory() const@Base" 0.6.0+14.10.20140804.1
118 (c++)"unity::scopes::ScopeBase::perform_action(unity::scopes::Result const&, unity::scopes::ActionMetadata const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0.4.0+14.04.20140312.1
119 (c++)"unity::scopes::ScopeBase::registry() const@Base" 0.6.0+14.10.20140804.1
120@@ -875,8 +879,11 @@
121 (c++)"unity::scopes::testing::StudentsTTest::one_sample(unity::scopes::testing::Sample const&, double, double)@Base" 0.4.0+14.04.20140312.1
122 (c++)"unity::scopes::testing::StudentsTTest::Result::~Result()@Base" 0.4.2+14.04.20140404.2
123 (c++)"unity::scopes::testing::StudentsTTest::two_independent_samples(unity::scopes::testing::Sample const&, unity::scopes::testing::Sample const&)@Base" 0.4.0+14.04.20140312.1
124+ (c++)"unity::scopes::testing::TypedScopeFixtureHelper::set_app_directory(std::shared_ptr<unity::scopes::ScopeBase> const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0replaceme
125+ (c++)"unity::scopes::testing::TypedScopeFixtureHelper::set_cache_directory(std::shared_ptr<unity::scopes::ScopeBase> const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0replaceme
126 (c++)"unity::scopes::testing::TypedScopeFixtureHelper::set_registry(std::shared_ptr<unity::scopes::ScopeBase> const&, std::shared_ptr<unity::scopes::Registry> const&)@Base" 0.6.2+rtm+rtm+rtm+14.09.20140818
127 (c++)"unity::scopes::testing::TypedScopeFixtureHelper::set_scope_directory(std::shared_ptr<unity::scopes::ScopeBase> const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0.6.6+14.10.20140916
128+ (c++)"unity::scopes::testing::TypedScopeFixtureHelper::set_tmp_directory(std::shared_ptr<unity::scopes::ScopeBase> const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0replaceme
129 (c++)"unity::scopes::TimeoutException::operator=(unity::scopes::TimeoutException const&)@Base" 0.4.0+14.04.20140312.1
130 (c++)"unity::scopes::TimeoutException::self() const@Base" 0.4.0+14.04.20140312.1
131 (c++)"unity::scopes::TimeoutException::~TimeoutException()@Base" 0.4.0+14.04.20140312.1
132
133=== modified file 'doc/tutorial.dox'
134--- doc/tutorial.dox 2014-11-10 11:25:45 +0000
135+++ doc/tutorial.dox 2014-11-18 20:53:45 +0000
136@@ -760,6 +760,34 @@
137 }
138 ~~~
139
140+\subsection directories File system access
141+
142+Scopes that are installed from click packages are subject to confinement and are not allowed
143+to access most parts of the file system. However, a few locations are available to a scope.
144+You can access these paths by calling methods on \link unity::scopes::ScopeBase ScopeBase\endlink.
145+
146+\note Do not call these methods from the constructor of your `ScopeBase` implementation. If you
147+do, these methods throw `LogicException`. Instead, call them from
148+\link unity::scopes::ScopeBase::start() start()\endlink or any time thereafter.
149+
150+\link unity::scopes::ScopeBase::scope_directory() scope_directory()\endlink returns the path of the installation
151+directory of the scope. This directory contains the scope's `.so` and `.ini` files, plus whatever other
152+files you decide to package with your scope. The scope has read-only permission for this directory.
153+
154+\link unity::scopes::ScopeBase::cache_directory() cache_directory()\endlink returns the path of a
155+directory that is (exclusively) writable for the scope. You can use this directory to store
156+persistent information, such as a cache of results.
157+
158+\link unity::scopes::ScopeBase::app_directory() app_directory()\endlink returns the path of a
159+read-only directory. If the scope is packaged together with an app, the app has permission to write
160+files in this location, that is, this directory can be used make information provided by the app
161+available to the scope (but not vice versa).
162+
163+\link unity::scopes::ScopeBase::tmp_directory() tmp_directory()\endlink returns the path of a
164+read-only directory that is (exclusively) writable for the scope. This directory is periodically
165+cleaned of unused files. The exact amount of time may vary, but is on the order of a few hours.
166+The directory is also cleaned during reboot.
167+
168 \subsection online_accounts Online Accounts
169
170 A scope may require access to an online account in order to evaluate particular results, perform certain actions, or
171
172=== modified file 'include/unity/scopes/ScopeBase.h'
173--- include/unity/scopes/ScopeBase.h 2014-11-03 05:31:30 +0000
174+++ include/unity/scopes/ScopeBase.h 2014-11-18 20:53:45 +0000
175@@ -272,10 +272,28 @@
176 virtual std::string cache_directory() const final;
177
178 /**
179+ \brief Returns a directory that is shared with an app in the same click package.
180+
181+ If a scope and an app share a single click package, this directory and the
182+ files in it are writable by the app, and read-only to the scope. This allows
183+ the app to write information into the filesystem that can be read by the scope
184+ (but not vice versa).
185+
186+ \note The app directory is available only after this ScopeBase is instantiated; do not
187+ call this method from the constructor!
188+
189+ \return The root directory of a filesystem sub-tree that the scope shares with
190+ an application installed from the same click-package.
191+ \throws LogicException if called from the constructor of this instance.
192+ */
193+ virtual std::string app_directory() const final;
194+
195+ /**
196 \brief Returns a tmp directory that is (exclusively) writable for the scope.
197
198 This directory is periodically cleaned of unused files. The exact amount of time
199- may vary, but is on the order of a few hours.
200+ may vary, but is on the order of a few hours. The directory is also cleaned
201+ during reboot.
202
203 \note The tmp directory is available only after this ScopeBase is instantiated; do not
204 call this method from the constructor!
205
206=== modified file 'include/unity/scopes/internal/RuntimeConfig.h'
207--- include/unity/scopes/internal/RuntimeConfig.h 2014-11-03 05:31:30 +0000
208+++ include/unity/scopes/internal/RuntimeConfig.h 2014-11-18 20:53:45 +0000
209@@ -44,10 +44,12 @@
210 std::string default_middleware_configfile() const;
211 int reap_expiry() const;
212 int reap_interval() const;
213- std::string data_directory() const;
214+ std::string cache_directory() const;
215+ std::string app_directory() const;
216 std::string config_directory() const;
217+ static std::string default_cache_directory();
218+ static std::string default_app_directory();
219 static std::string default_config_directory();
220- static std::string default_data_directory();
221
222 private:
223 std::string registry_identity_;
224@@ -58,7 +60,8 @@
225 std::string default_middleware_configfile_;
226 int reap_expiry_;
227 int reap_interval_;
228- std::string data_directory_;
229+ std::string cache_directory_;
230+ std::string app_directory_;
231 std::string config_directory_;
232 };
233
234
235=== modified file 'include/unity/scopes/internal/RuntimeImpl.h'
236--- include/unity/scopes/internal/RuntimeImpl.h 2014-11-03 05:31:30 +0000
237+++ include/unity/scopes/internal/RuntimeImpl.h 2014-11-18 20:53:45 +0000
238@@ -72,6 +72,7 @@
239 bool confined() const;
240 std::string confinement_type() const;
241 std::string find_cache_dir() const;
242+ std::string find_app_dir() const;
243 std::string find_tmp_dir() const;
244
245 bool destroyed_;
246@@ -85,7 +86,8 @@
247 mutable std::string ss_registry_identity_;
248 int reap_expiry_;
249 int reap_interval_;
250- std::string data_dir_;
251+ std::string cache_dir_;
252+ std::string app_dir_;
253 std::string config_dir_;
254 std::string tmp_dir_;
255 mutable Reaper::SPtr reply_reaper_;
256
257=== modified file 'include/unity/scopes/internal/ScopeBaseImpl.h'
258--- include/unity/scopes/internal/ScopeBaseImpl.h 2014-11-03 05:31:30 +0000
259+++ include/unity/scopes/internal/ScopeBaseImpl.h 2014-11-18 20:53:45 +0000
260@@ -47,6 +47,9 @@
261 void set_cache_directory(std::string const& path);
262 std::string cache_directory() const;
263
264+ void set_app_directory(std::string const& path);
265+ std::string app_directory() const;
266+
267 void set_tmp_directory(std::string const& path);
268 std::string tmp_directory() const;
269
270@@ -64,6 +67,9 @@
271 std::string cache_directory_;
272 bool cache_dir_initialized_;
273
274+ std::string app_directory_;
275+ bool app_dir_initialized_;
276+
277 std::string tmp_directory_;
278 bool tmp_dir_initialized_;
279
280
281=== modified file 'include/unity/scopes/testing/TypedScopeFixture.h'
282--- include/unity/scopes/testing/TypedScopeFixture.h 2014-11-03 05:31:30 +0000
283+++ include/unity/scopes/testing/TypedScopeFixture.h 2014-11-18 20:53:45 +0000
284@@ -53,13 +53,14 @@
285 }
286 };
287
288-struct TypedScopeFixtureHelper
289+class TypedScopeFixtureHelper
290 {
291-private:
292+ static void set_scope_directory(std::shared_ptr<ScopeBase> const& scope, std::string const& path);
293+ static void set_cache_directory(std::shared_ptr<ScopeBase> const& scope, std::string const& path);
294+ static void set_app_directory(std::shared_ptr<ScopeBase> const& scope, std::string const& path);
295+ static void set_tmp_directory(std::shared_ptr<ScopeBase> const& scope, std::string const& path);
296 static void set_registry(std::shared_ptr<ScopeBase> const& scope, RegistryProxy const& r);
297
298- static void set_scope_directory(std::shared_ptr<ScopeBase> const& scope, std::string const& path);
299-
300 template<typename Scope>
301 friend class TypedScopeFixture;
302 };
303@@ -86,6 +87,26 @@
304 TypedScopeFixtureHelper::set_scope_directory(scope, path);
305 }
306
307+ void set_cache_directory(std::string const& path)
308+ {
309+ TypedScopeFixtureHelper::set_cache_directory(scope, path);
310+ }
311+
312+ void set_app_directory(std::string const& path)
313+ {
314+ TypedScopeFixtureHelper::set_app_directory(scope, path);
315+ }
316+
317+ void set_tmp_directory(std::string const& path)
318+ {
319+ TypedScopeFixtureHelper::set_tmp_directory(scope, path);
320+ }
321+
322+ static void set_registry(std::shared_ptr<ScopeBase> const& scope, RegistryProxy const& r)
323+ {
324+ TypedScopeFixtureHelper::set_registry(scope, r);
325+ }
326+
327 void TearDown()
328 {
329 EXPECT_NO_THROW(scope->stop());
330
331=== modified file 'scoperegistry/scoperegistry.cpp'
332--- scoperegistry/scoperegistry.cpp 2014-11-18 08:46:17 +0000
333+++ scoperegistry/scoperegistry.cpp 2014-11-18 20:53:45 +0000
334@@ -485,13 +485,17 @@
335 identity = runtime->registry_identity();
336 ss_reg_id = runtime->ss_registry_identity();
337
338- // TODO: HACK: We create the root of the data directory for confined scopes,
339- // in case the scope is confined and the dir doesn't exist
340- // yet. This really should be done by the click-installation but,
341+ // TODO: HACK: We create the root of the cache and app directories for
342+ // confined scopes, in case the scope is confined and the dir doesn't
343+ // exist yet. This really should be done by the click-installation but,
344 // prior to RTM, we don't rely on that.
345- string data_root = rt_config.data_directory() + "/leaf-net";
346 boost::system::error_code ec;
347- !boost::filesystem::exists(data_root, ec) && ::mkdir(data_root.c_str(), 0700);
348+
349+ string cache_root = rt_config.cache_directory() + "/leaf-net";
350+ !boost::filesystem::exists(cache_root, ec) && ::mkdir(cache_root.c_str(), 0700);
351+
352+ string app_root = rt_config.app_directory();
353+ !boost::filesystem::exists(app_root, ec) && ::mkdir(app_root.c_str(), 0700);
354 } // Release memory for config parser
355
356 // Make sure that the parent directories for confined scope tmp directory exist.
357
358=== modified file 'src/scopes/ScopeBase.cpp'
359--- src/scopes/ScopeBase.cpp 2014-08-14 17:23:22 +0000
360+++ src/scopes/ScopeBase.cpp 2014-11-18 20:53:45 +0000
361@@ -82,6 +82,11 @@
362 return p->cache_directory();
363 }
364
365+std::string ScopeBase::app_directory() const
366+{
367+ return p->app_directory();
368+}
369+
370 std::string ScopeBase::tmp_directory() const
371 {
372 return p->tmp_directory();
373
374=== modified file 'src/scopes/internal/RuntimeConfig.cpp'
375--- src/scopes/internal/RuntimeConfig.cpp 2014-08-13 17:07:12 +0000
376+++ src/scopes/internal/RuntimeConfig.cpp 2014-11-18 20:53:45 +0000
377@@ -46,7 +46,8 @@
378 const string default_middleware_configfile_key = ".ConfigFile";
379 const string reap_expiry_key = "Reap.Expiry";
380 const string reap_interval_key = "Reap.Interval";
381-const string data_dir_key = "DataDir";
382+const string cache_dir_key = "CacheDir";
383+const string app_dir_key = "AppDir";
384 const string config_dir_key = "ConfigDir";
385
386 } // namespace
387@@ -66,7 +67,8 @@
388 reap_interval_ = DFLT_REAP_INTERVAL;
389 try
390 {
391- data_directory_ = default_data_directory();
392+ cache_directory_ = default_cache_directory();
393+ app_directory_ = default_app_directory();
394 config_directory_ = default_config_directory();
395 }
396 catch (ResourceException const& e)
397@@ -94,16 +96,28 @@
398 {
399 throw_ex("Illegal value (" + to_string(reap_interval_) + ") for " + reap_interval_key + ": value must be > 0");
400 }
401- data_directory_ = get_optional_string(runtime_config_group, data_dir_key);
402- if (data_directory_.empty())
403- {
404- try
405- {
406- data_directory_ = default_data_directory();
407- }
408- catch (ResourceException const& e)
409- {
410- throw_ex("No DataDir configured and failed to get default");
411+ cache_directory_ = get_optional_string(runtime_config_group, cache_dir_key);
412+ if (cache_directory_.empty())
413+ {
414+ try
415+ {
416+ cache_directory_ = default_cache_directory();
417+ }
418+ catch (ResourceException const& e)
419+ {
420+ throw_ex("No CacheDir configured and failed to get default");
421+ }
422+ }
423+ app_directory_ = get_optional_string(runtime_config_group, app_dir_key);
424+ if (app_directory_.empty())
425+ {
426+ try
427+ {
428+ app_directory_ = default_app_directory();
429+ }
430+ catch (ResourceException const& e)
431+ {
432+ throw_ex("No AppDir configured and failed to get default");
433 }
434 }
435 config_directory_ = get_optional_string(runtime_config_group, config_dir_key);
436@@ -131,7 +145,8 @@
437 default_middleware_ + default_middleware_configfile_key,
438 reap_expiry_key,
439 reap_interval_key,
440- data_dir_key,
441+ cache_dir_key,
442+ app_dir_key,
443 config_dir_key
444 }
445 }
446@@ -183,9 +198,14 @@
447 return reap_interval_;
448 }
449
450-string RuntimeConfig::data_directory() const
451-{
452- return data_directory_;
453+string RuntimeConfig::cache_directory() const
454+{
455+ return cache_directory_;
456+}
457+
458+string RuntimeConfig::app_directory() const
459+{
460+ return app_directory_;
461 }
462
463 string RuntimeConfig::config_directory() const
464@@ -193,6 +213,26 @@
465 return config_directory_;
466 }
467
468+string RuntimeConfig::default_cache_directory()
469+{
470+ char const* home = getenv("HOME");
471+ if (!home || *home == '\0')
472+ {
473+ throw ResourceException("RuntimeConfig::default_cache_directory(): $HOME not set");
474+ }
475+ return string(home) + "/.local/share/unity-scopes";
476+}
477+
478+string RuntimeConfig::default_app_directory()
479+{
480+ char const* home = getenv("HOME");
481+ if (!home || *home == '\0')
482+ {
483+ throw ResourceException("RuntimeConfig::default_app_directory(): $HOME not set");
484+ }
485+ return string(home) + "/.local/share";
486+}
487+
488 string RuntimeConfig::default_config_directory()
489 {
490 char const* home = getenv("HOME");
491@@ -203,17 +243,6 @@
492 return string(home) + "/.config/unity-scopes";
493 }
494
495-string RuntimeConfig::default_data_directory()
496-{
497- char const* home = getenv("HOME");
498- if (!home || *home == '\0')
499- {
500- throw ResourceException("RuntimeConfig::default_data_directory(): $HOME not set");
501- }
502- return string(home) + "/.local/share/unity-scopes";
503-}
504-
505-
506 } // namespace internal
507
508 } // namespace scopes
509
510=== modified file 'src/scopes/internal/RuntimeImpl.cpp'
511--- src/scopes/internal/RuntimeImpl.cpp 2014-10-10 07:01:36 +0000
512+++ src/scopes/internal/RuntimeImpl.cpp 2014-11-18 20:53:45 +0000
513@@ -102,7 +102,8 @@
514 registry_ = make_shared<RegistryImpl>(registry_mw_proxy, this);
515 }
516
517- data_dir_ = config.data_directory();
518+ cache_dir_ = config.cache_directory();
519+ app_dir_ = config.app_directory();
520 config_dir_ = config.config_directory();
521 }
522 catch (unity::Exception const& e)
523@@ -340,18 +341,15 @@
524
525 auto mw = factory()->create(scope_id_, reg_conf.mw_kind(), reg_conf.mw_configfile());
526
527- {
528- boost::filesystem::path dir = boost::filesystem::canonical(scope_ini_file).parent_path();
529- scope_base->p->set_scope_directory(dir.native());
530- }
531+ boost::filesystem::path scope_dir = boost::filesystem::canonical(scope_ini_file).parent_path();
532+ scope_base->p->set_scope_directory(scope_dir.native());
533
534 {
535 // Try to open the scope settings database, if any.
536 string config_dir = config_dir_ + "/" + scope_id_;
537 string settings_db = config_dir + "/settings.ini";
538
539- string scope_dir = scope_base->scope_directory();
540- string settings_schema = scope_dir + "/" + scope_id_ + "-settings.ini";
541+ string settings_schema = scope_dir.native() + "/" + scope_id_ + "-settings.ini";
542
543 boost::system::error_code ec;
544 if (boost::filesystem::exists(settings_schema, ec))
545@@ -367,6 +365,7 @@
546
547 scope_base->p->set_registry(registry_);
548 scope_base->p->set_cache_directory(find_cache_dir());
549+ scope_base->p->set_app_directory(find_app_dir());
550 scope_base->p->set_tmp_directory(find_tmp_dir());
551
552 try
553@@ -489,8 +488,8 @@
554 string RuntimeImpl::demangled_id() const
555 {
556 // For scopes that are in a click package together with an app,
557- // such as YouTube, the cache directory is shared between the app and
558- // the scope. The cache directory name is the scope ID up to the first
559+ // such as YouTube, the scope id is <scope_id>_<app_id>
560+ // The app directory and cache directory names are the scope ID up to the first
561 // underscore. For example, com.ubuntu.scopes.youtube_youtube is the
562 // scope ID, but the cache dir name is com.ubuntu.scopes.youtube.
563 auto id = scope_id_;
564@@ -528,10 +527,10 @@
565
566 string RuntimeImpl::find_cache_dir() const
567 {
568- // Create the data_dir_/<confinement-type>/<id> directories if they don't exist.
569+ // Create the cache_dir_/<confinement-type>/<id> directories if they don't exist.
570 boost::system::error_code ec;
571- !confined() && !boost::filesystem::exists(data_dir_, ec) && ::mkdir(data_dir_.c_str(), 0700);
572- string dir = data_dir_ + "/" + confinement_type();
573+ !confined() && !boost::filesystem::exists(cache_dir_, ec) && ::mkdir(cache_dir_.c_str(), 0700);
574+ string dir = cache_dir_ + "/" + confinement_type();
575 !confined() && !boost::filesystem::exists(dir, ec) && ::mkdir(dir.c_str(), 0700);
576
577 // A confined scope is allowed to create this dir.
578@@ -541,6 +540,17 @@
579 return dir;
580 }
581
582+string RuntimeImpl::find_app_dir() const
583+{
584+ // Create the app_dir_/<id> directories if they don't exist.
585+ boost::system::error_code ec;
586+ !confined() && !boost::filesystem::exists(app_dir_, ec) && ::mkdir(app_dir_.c_str(), 0700);
587+ string dir = app_dir_ + "/" + demangled_id();
588+ !confined() && !boost::filesystem::exists(dir, ec) && ::mkdir(dir.c_str(), 0700);
589+
590+ return dir;
591+}
592+
593 string RuntimeImpl::find_tmp_dir() const
594 {
595 // Set tmp dir.
596
597=== modified file 'src/scopes/internal/ScopeBaseImpl.cpp'
598--- src/scopes/internal/ScopeBaseImpl.cpp 2014-07-11 06:28:13 +0000
599+++ src/scopes/internal/ScopeBaseImpl.cpp 2014-11-18 20:53:45 +0000
600@@ -38,6 +38,7 @@
601 ScopeBaseImpl::ScopeBaseImpl()
602 : scope_dir_initialized_(false)
603 , cache_dir_initialized_(false)
604+ , app_dir_initialized_(false)
605 , registry_initialized_(false)
606 , settings_db_initialized_(false)
607 {
608@@ -82,6 +83,27 @@
609 return cache_directory_;
610 }
611
612+void ScopeBaseImpl::set_app_directory(std::string const& path)
613+{
614+ lock_guard<mutex> lock(mutex_);
615+ app_directory_ = path;
616+ app_dir_initialized_ = true;
617+}
618+
619+std::string ScopeBaseImpl::app_directory() const
620+{
621+ lock_guard<mutex> lock(mutex_);
622+ if (!app_dir_initialized_)
623+ {
624+ throw LogicException("ScopeBase::app_directory() cannot be called from constructor");
625+ }
626+ if (app_directory_.empty())
627+ {
628+ throw ConfigException("ScopeBase::app_directory(): no app directory available");
629+ }
630+ return app_directory_;
631+}
632+
633 void ScopeBaseImpl::set_tmp_directory(std::string const& path)
634 {
635 lock_guard<mutex> lock(mutex_);
636
637=== modified file 'src/scopes/testing/TypedScopeFixture.cpp'
638--- src/scopes/testing/TypedScopeFixture.cpp 2014-09-16 09:10:07 +0000
639+++ src/scopes/testing/TypedScopeFixture.cpp 2014-11-18 20:53:45 +0000
640@@ -23,13 +23,30 @@
641 using namespace unity::scopes::testing;
642
643 /// @cond
644+
645+void TypedScopeFixtureHelper::set_scope_directory(std::shared_ptr<unity::scopes::ScopeBase> const& scope, std::string const& path)
646+{
647+ scope->p->set_scope_directory(path);
648+}
649+
650+void TypedScopeFixtureHelper::set_cache_directory(std::shared_ptr<unity::scopes::ScopeBase> const& scope, std::string const& path)
651+{
652+ scope->p->set_cache_directory(path);
653+}
654+
655+void TypedScopeFixtureHelper::set_app_directory(std::shared_ptr<unity::scopes::ScopeBase> const& scope, std::string const& path)
656+{
657+ scope->p->set_app_directory(path);
658+}
659+
660+void TypedScopeFixtureHelper::set_tmp_directory(std::shared_ptr<unity::scopes::ScopeBase> const& scope, std::string const& path)
661+{
662+ scope->p->set_tmp_directory(path);
663+}
664+
665 void TypedScopeFixtureHelper::set_registry(std::shared_ptr<unity::scopes::ScopeBase> const& scope, RegistryProxy const& r)
666 {
667 scope->p->set_registry(r);
668 }
669
670-void TypedScopeFixtureHelper::set_scope_directory(std::shared_ptr<unity::scopes::ScopeBase> const& scope, std::string const& path)
671-{
672- scope->p->set_scope_directory(path);
673-}
674 /// @endcond
675
676=== renamed file 'test/gtest/scopes/internal/RuntimeConfig/DataDir.ini' => 'test/gtest/scopes/internal/RuntimeConfig/CacheDir.ini'
677--- test/gtest/scopes/internal/RuntimeConfig/DataDir.ini 2014-08-13 17:07:12 +0000
678+++ test/gtest/scopes/internal/RuntimeConfig/CacheDir.ini 2014-11-18 20:53:45 +0000
679@@ -1,3 +1,4 @@
680 [Runtime]
681-DataDir = Foo
682-ConfigDir = Foo
683+CacheDir = cachedir
684+AppDir = appdir
685+ConfigDir = configdir
686
687=== modified file 'test/gtest/scopes/internal/RuntimeConfig/ConfigDir.ini'
688--- test/gtest/scopes/internal/RuntimeConfig/ConfigDir.ini 2014-08-14 07:31:07 +0000
689+++ test/gtest/scopes/internal/RuntimeConfig/ConfigDir.ini 2014-11-18 20:53:45 +0000
690@@ -1,3 +1,4 @@
691 [Runtime]
692-DataDir = Foo
693-ConfigDir = Foo
694+CacheDir = cachedir
695+AppDir = appdir
696+ConfigDir = configdir
697
698=== added file 'test/gtest/scopes/internal/RuntimeConfig/NoAppDir.ini'
699--- test/gtest/scopes/internal/RuntimeConfig/NoAppDir.ini 1970-01-01 00:00:00 +0000
700+++ test/gtest/scopes/internal/RuntimeConfig/NoAppDir.ini 2014-11-18 20:53:45 +0000
701@@ -0,0 +1,2 @@
702+[Runtime]
703+CacheDir = cachedir
704
705=== renamed file 'test/gtest/scopes/internal/RuntimeConfig/NoDataDir.ini' => 'test/gtest/scopes/internal/RuntimeConfig/NoCacheDir.ini'
706--- test/gtest/scopes/internal/RuntimeConfig/NoDataDir.ini 2014-08-13 17:07:12 +0000
707+++ test/gtest/scopes/internal/RuntimeConfig/NoCacheDir.ini 2014-11-18 20:53:45 +0000
708@@ -1,2 +1,2 @@
709 [Runtime]
710-ConfigDir = Foo
711\ No newline at end of file
712+ConfigDir = configdir
713
714=== modified file 'test/gtest/scopes/internal/RuntimeConfig/NoConfigDir.ini'
715--- test/gtest/scopes/internal/RuntimeConfig/NoConfigDir.ini 2014-08-14 07:31:07 +0000
716+++ test/gtest/scopes/internal/RuntimeConfig/NoConfigDir.ini 2014-11-18 20:53:45 +0000
717@@ -1,2 +1,3 @@
718 [Runtime]
719-DataDir = Foo
720+CacheDir = cachedir
721+AppDir = appdir
722
723=== modified file 'test/gtest/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp'
724--- test/gtest/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp 2014-08-13 17:07:12 +0000
725+++ test/gtest/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp 2014-11-18 20:53:45 +0000
726@@ -42,28 +42,44 @@
727 EXPECT_EQ(DFLT_REAP_INTERVAL, c.reap_interval());
728 }
729
730-TEST(RuntimeConfig, _default_data_dir)
731+TEST(RuntimeConfig, _default_cache_dir)
732 {
733 setenv("HOME", TEST_SRC_DIR, 1);
734
735 RuntimeConfig c("");
736- EXPECT_EQ(TEST_SRC_DIR "/.local/share/unity-scopes", c.data_directory());
737-}
738-
739-TEST(RuntimeConfig, overridden_data_dir)
740-{
741- unsetenv("HOME");
742-
743- RuntimeConfig c(TEST_SRC_DIR "/DataDir.ini");
744- EXPECT_EQ("Foo", c.data_directory());
745-}
746-
747-TEST(RuntimeConfig, overridden_data_dir_with_home_dir)
748-{
749- setenv("HOME", TEST_SRC_DIR, 1);
750-
751- RuntimeConfig c(TEST_SRC_DIR "/DataDir.ini");
752- EXPECT_EQ("Foo", c.data_directory());
753+ EXPECT_EQ(TEST_SRC_DIR "/.local/share/unity-scopes", c.cache_directory());
754+}
755+
756+TEST(RuntimeConfig, overridden_cache_dir)
757+{
758+ unsetenv("HOME");
759+
760+ RuntimeConfig c(TEST_SRC_DIR "/CacheDir.ini");
761+ EXPECT_EQ("cachedir", c.cache_directory());
762+}
763+
764+TEST(RuntimeConfig, overridden_cache_dir_with_home_dir)
765+{
766+ setenv("HOME", TEST_SRC_DIR, 1);
767+
768+ RuntimeConfig c(TEST_SRC_DIR "/CacheDir.ini");
769+ EXPECT_EQ("cachedir", c.cache_directory());
770+}
771+
772+TEST(RuntimeConfig, overridden_app_dir)
773+{
774+ unsetenv("HOME");
775+
776+ RuntimeConfig c(TEST_SRC_DIR "/CacheDir.ini");
777+ EXPECT_EQ("appdir", c.app_directory());
778+}
779+
780+TEST(RuntimeConfig, overridden_app_dir_with_home_dir)
781+{
782+ setenv("HOME", TEST_SRC_DIR, 1);
783+
784+ RuntimeConfig c(TEST_SRC_DIR "/ConfigDir.ini");
785+ EXPECT_EQ("appdir", c.app_directory());
786 }
787
788 TEST(RuntimeConfig, overridden_config_dir)
789@@ -71,7 +87,7 @@
790 unsetenv("HOME");
791
792 RuntimeConfig c(TEST_SRC_DIR "/ConfigDir.ini");
793- EXPECT_EQ("Foo", c.config_directory());
794+ EXPECT_EQ("configdir", c.config_directory());
795 }
796
797 TEST(RuntimeConfig, overridden_config_dir_with_home_dir)
798@@ -79,7 +95,7 @@
799 setenv("HOME", TEST_SRC_DIR, 1);
800
801 RuntimeConfig c(TEST_SRC_DIR "/ConfigDir.ini");
802- EXPECT_EQ("Foo", c.config_directory());
803+ EXPECT_EQ("configdir", c.config_directory());
804 }
805
806 TEST(RuntimeConfig, exceptions)
807@@ -124,14 +140,14 @@
808 {
809 unsetenv("HOME");
810
811- RuntimeConfig c(TEST_SRC_DIR "/NoDataDir.ini");
812+ RuntimeConfig c(TEST_SRC_DIR "/NoCacheDir.ini");
813 FAIL();
814- EXPECT_EQ("Foo", c.data_directory());
815+ EXPECT_EQ("cachedir", c.cache_directory());
816 }
817 catch (ConfigException const& e)
818 {
819- EXPECT_STREQ("unity::scopes::ConfigException: \"" TEST_SRC_DIR "/NoDataDir.ini\": No DataDir configured and "
820- "failed to get default:\n unity::ResourceException: RuntimeConfig::default_data_directory(): "
821+ EXPECT_STREQ("unity::scopes::ConfigException: \"" TEST_SRC_DIR "/NoCacheDir.ini\": No CacheDir configured and "
822+ "failed to get default:\n unity::ResourceException: RuntimeConfig::default_cache_directory(): "
823 "$HOME not set",
824 e.what());
825 }
826@@ -142,7 +158,7 @@
827
828 RuntimeConfig c(TEST_SRC_DIR "/NoConfigDir.ini");
829 FAIL();
830- EXPECT_EQ("Foo", c.data_directory());
831+ EXPECT_EQ("cachedir", c.cache_directory());
832 }
833 catch (ConfigException const& e)
834 {
835
836=== modified file 'test/gtest/scopes/internal/RuntimeImpl/Runtime.ini.in'
837--- test/gtest/scopes/internal/RuntimeImpl/Runtime.ini.in 2014-08-13 17:07:12 +0000
838+++ test/gtest/scopes/internal/RuntimeImpl/Runtime.ini.in 2014-11-18 20:53:45 +0000
839@@ -3,5 +3,6 @@
840 Registry.ConfigFile = @CMAKE_CURRENT_BINARY_DIR@/Registry.ini
841 Default.Middleware = Zmq
842 Zmq.ConfigFile = @CMAKE_CURRENT_BINARY_DIR@/Zmq.ini
843-DataDir = @CMAKE_CURRENT_BINARY_DIR@/cache_dir
844-ConfigDir = @CMAKE_CURRENT_BINARY_DIR@/cache_dir
845+CacheDir = @CMAKE_CURRENT_BINARY_DIR@/cache_dir
846+AppDir = @CMAKE_CURRENT_BINARY_DIR@/app_dir
847+ConfigDir = @CMAKE_CURRENT_BINARY_DIR@/config_dir
848
849=== modified file 'test/gtest/scopes/internal/RuntimeImpl/RuntimeImpl_test.cpp'
850--- test/gtest/scopes/internal/RuntimeImpl/RuntimeImpl_test.cpp 2014-09-08 05:55:39 +0000
851+++ test/gtest/scopes/internal/RuntimeImpl/RuntimeImpl_test.cpp 2014-11-18 20:53:45 +0000
852@@ -201,6 +201,7 @@
853 EXPECT_EQ(tmpdir, testscope.tmp_directory());
854
855 EXPECT_EQ(TEST_DIR "/cache_dir/unconfined/TestScope", testscope.cache_directory());
856+ EXPECT_EQ(TEST_DIR "/app_dir/TestScope", testscope.app_directory());
857
858 // Don't destroy the run time until after the scope has finished initializing.
859 initialized.wait();
860@@ -210,9 +211,9 @@
861 }
862
863 {
864- // Check that scopes that share a cache dir with an app (because
865+ // Check that scopes that share an app dir with an app (because
866 // the scope is packaged with the app in a single click package)
867- // share the app's cache directory.
868+ // return the correct path for cache and app dir.
869
870 string const scope_ini_file = TEST_DIR "/TestScope_TestScope.ini";
871
872@@ -236,6 +237,7 @@
873 EXPECT_EQ(tmpdir, testscope.tmp_directory());
874
875 EXPECT_EQ(TEST_DIR "/cache_dir/unconfined/TestScope", testscope.cache_directory());
876+ EXPECT_EQ(TEST_DIR "/app_dir/TestScope", testscope.app_directory());
877
878 // Don't destroy the run time until after the scope has finished initializing.
879 initialized.wait();

Subscribers

People subscribed via source and target branches

to all changes: