diff options
author | eerielili <lionel@les-miquelots.net> | 2024-09-28 14:40:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-28 16:40:03 +0200 |
commit | 439c37539332781f976d4dc7dbdfa37f2b60a3bf (patch) | |
tree | 63a4dbfce62d2947cf5ec282d7923d71748eaf3f /libdino/src | |
parent | 8853ffead3f12778e43f08656c767690fbea76ed (diff) | |
download | dino-439c37539332781f976d4dc7dbdfa37f2b60a3bf.tar.gz dino-439c37539332781f976d4dc7dbdfa37f2b60a3bf.zip |
Store avatars in the user's cache directory. (#1621)
* Store avatars in the user's cache directory.
- Not anymore in ~/.local/share, where media files are stored.
- Already existing ~/.local/share/dino/avatars directory will be
moved to ~/.cache/dino/avatars
- If both directories already exists, the old one (in
~/.local/share) is removed.
* Simplify old-to-new-location logic
---------
Co-authored-by: fiaxh <git@lightrise.org>
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/service/avatar_manager.vala | 35 | ||||
-rw-r--r-- | libdino/src/util/util.vala | 4 |
2 files changed, 37 insertions, 2 deletions
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index f99f37d4..192d5c9d 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -37,8 +37,39 @@ public class AvatarManager : StreamInteractionModule, Object { private AvatarManager(StreamInteractor stream_interactor, Database db) { this.stream_interactor = stream_interactor; this.db = db; - this.folder = Path.build_filename(Dino.get_storage_dir(), "avatars"); - DirUtils.create_with_parents(this.folder, 0700); + + File old_avatars = File.new_build_filename(Dino.get_storage_dir(), "avatars"); + File new_avatars = File.new_build_filename(Dino.get_cache_dir(), "avatars"); + this.folder = new_avatars.get_path(); + + // Move old avatar location to new one + if (old_avatars.query_exists()) { + if (!new_avatars.query_exists()) { + // Move old avatars folder (~/.local/share/dino) to new location (~/.cache/dino) + try { + new_avatars.get_parent().make_directory_with_parents(); + } catch (Error e) { } + try { + old_avatars.move(new_avatars, FileCopyFlags.NONE); + debug("Avatars directory %s moved to %s", old_avatars.get_path(), new_avatars.get_path()); + } catch (Error e) { } + } else { + // If both old and new folders exist, remove the old one + try { + FileEnumerator enumerator = old_avatars.enumerate_children("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS); + FileInfo info = null; + while ((info = enumerator.next_file()) != null) { + FileUtils.remove(old_avatars.get_path() + "/" + info.get_name()); + } + DirUtils.remove(old_avatars.get_path()); + } catch (Error e) { } + } + } + + // Create avatar folder + try { + new_avatars.make_directory_with_parents(); + } catch (Error e) { } stream_interactor.account_added.connect(on_account_added); stream_interactor.module_manager.initialize_account_modules.connect((_, modules) => { diff --git a/libdino/src/util/util.vala b/libdino/src/util/util.vala index 553ebbfe..9f7ae45f 100644 --- a/libdino/src/util/util.vala +++ b/libdino/src/util/util.vala @@ -69,6 +69,10 @@ public static string get_storage_dir() { return Path.build_filename(Environment.get_user_data_dir(), "dino"); } +public static string get_cache_dir() { + return Path.build_filename(Environment.get_user_cache_dir(), "dino"); +} + [CCode (cname = "dino_gettext", cheader_filename = "dino_i18n.h")] public static extern unowned string _(string s); |