Mercurial > libervia-desktop-kivy
changeset 381:eb3f622d8791
android: create/clean a temporary directory on startup:
directory returned by tempfiles on Android is actually the root directory of the
application, so it is not cleaned. To work around that a `/tmp` directory inside it is now
created, and cleaned on startup if it already exists.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Feb 2020 20:47:17 +0100 |
parents | 9d3481663964 |
children | c7f1176cd2a9 |
files | cagou/core/cagou_main.py cagou/core/platform_/android.py |
diffstat | 2 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/cagou/core/cagou_main.py Tue Feb 04 20:47:17 2020 +0100 +++ b/cagou/core/cagou_main.py Tue Feb 04 20:47:17 2020 +0100 @@ -462,6 +462,9 @@ resync() self.contact_lists.fill() + def getConfig(self, section, name, default=None): + return config.getConfig(main_config, section, name, default) + def onBridgeConnected(self): super(Cagou, self).onBridgeConnected() self.registerSignal("otrState", iface="plugin")
--- a/cagou/core/platform_/android.py Tue Feb 04 20:47:17 2020 +0100 +++ b/cagou/core/platform_/android.py Tue Feb 04 20:47:17 2020 +0100 @@ -22,6 +22,8 @@ import json from functools import partial from urllib.parse import urlparse +from pathlib import Path +import shutil from jnius import autoclass, cast from android import activity from sat.core.i18n import _ @@ -77,6 +79,15 @@ activity.bind(on_new_intent=self.on_new_intent) self.cache.append((self.on_new_intent, mActivity.getIntent())) host.addListener('profilePlugged', self.onProfilePlugged) + local_dir = Path(host.getConfig('', 'local_dir')).resolve() + self.tmp_dir = local_dir / 'tmp' + # we assert to avoid disaster if `/ 'tmp'` is removed by mistake on the line + # above + assert self.tmp_dir.resolve() != local_dir + # we reset tmp dir on each run, to be sure that there is no residual file + if self.tmp_dir.exists(): + shutil.rmtree(self.tmp_dir) + self.tmp_dir.mkdir(0o700) def on_initFrontendState(self): # XXX: we use a separated socket instead of bridge because if we