From e00a6b481cd61ca2969f271d309dba2c20648c92 Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Sun, 22 Sep 2024 21:28:39 +0200 Subject: 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. --- libdino/src/util/util.vala | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libdino/src/util') diff --git a/libdino/src/util/util.vala b/libdino/src/util/util.vala index 553ebbfe..1a95cb36 100644 --- a/libdino/src/util/util.vala +++ b/libdino/src/util/util.vala @@ -69,6 +69,38 @@ 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"); +} + +public void recurse_delete_folder(File file, string space = "", Cancellable? cancellable = null) throws Error { + FileEnumerator enumerator = file.enumerate_children ( + "standard::*", + FileQueryInfoFlags.NOFOLLOW_SYMLINKS, + cancellable); + + FileInfo info = null; + while (cancellable.is_cancelled () == false && ((info = enumerator.next_file (cancellable)) != null)) { + if (info.get_file_type () == FileType.DIRECTORY) { + File subdir = file.resolve_relative_path (info.get_name ()); + recurse_delete_folder(subdir, space + " ", cancellable); + } else { + FileUtils.remove(file.get_path() + "/" + info.get_name()); + } + } + var res = DirUtils.remove(file.get_path()); + if (res == -1){ + debug("Error: Folder %s not removed using GLib. Check permissions or ownership ?", file.get_path()); + } + else { + debug("Folder %s removed using GLib.", file.get_path()); + } + + if (cancellable.is_cancelled ()) { + throw new IOError.CANCELLED ("I/O Error: Recursive deletion of folder %s was cancelled.", file.get_path()); + } +} + [CCode (cname = "dino_gettext", cheader_filename = "dino_i18n.h")] public static extern unowned string _(string s); -- cgit v1.2.3-70-g09d2