From 248ef1aa5a6bbaa65387508b81f3fe2ebbc5ec7d Mon Sep 17 00:00:00 2001 From: zhuyaliang <15132211195@163.com> Date: Fri, 4 Aug 2023 11:11:16 +0800 Subject: Check if the remaining disk space is sufficient when add extract --- src/fr-window.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src') diff --git a/src/fr-window.c b/src/fr-window.c index cbb0ea6..20ca551 100644 --- a/src/fr-window.c +++ b/src/fr-window.c @@ -6419,6 +6419,34 @@ archive_is_encrypted (FrWindow *window, return encrypted; } +static gboolean +archive_extract_check_disk_space_full (GPtrArray *files, + const char *extract_to_dir) +{ + guint64 freespace; + guint64 archive_size = 0; + guint i; + + freespace = get_dest_free_space (g_filename_from_uri (extract_to_dir, NULL, NULL)); + + for (i = 0; i len; i++) + { + FileData *fdata = g_ptr_array_index (files, i); + archive_size += fdata->size; + } + /* When the decompressed target file is less than 100MB, + 2 * (target file size) needs to disk space + and when it is greater than 100MB, + 100MB + (target file size) needs to disk space */ + + if (archive_size <= 1024 * 1024 * 100) + archive_size = archive_size * 2; + else + archive_size += 1024 * 1024 * 100; + + return freespace < archive_size * 2; +} + void fr_window_archive_extract_here (FrWindow *window, gboolean skip_older, @@ -6672,6 +6700,20 @@ fr_window_archive_extract (FrWindow *window, edata, (GFreeFunc) extract_data_free); + if (archive_extract_check_disk_space_full (window->archive->command->files, extract_to_dir)) + { + GtkWidget *d; + + d = _gtk_error_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_MODAL, + NULL, + _("Insufficient remaining disk space"), + NULL); + gtk_dialog_run (GTK_DIALOG (d)); + gtk_widget_destroy(d); + return; + } + if (archive_is_encrypted (window, edata->file_list) && (window->priv->password == NULL)) { dlg_ask_password (window); return; -- cgit v1.2.1