Skip to content

Commit

Permalink
caja-file-operations: fix division by 0 for delete
Browse files Browse the repository at this point in the history
Aligning to the copy operation case, this fixes the condition for
showing an estimate of the remaining duration for delete operations,
preventing a possible division by 0 due to a zero transfer rate.
  • Loading branch information
basicmaster committed Jan 13, 2024
1 parent 0bac0f9 commit 01bf8cf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libcaja-private/caja-file-operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ report_delete_progress (CommonJob *job,
TransferInfo *transfer_info)
{
int files_left;
double elapsed;
double elapsed, transfer_rate;
gint64 now;
char *files_left_s;

Expand All @@ -1522,15 +1522,19 @@ report_delete_progress (CommonJob *job,
f (_("Deleting files")));

elapsed = g_timer_elapsed (job->time, NULL);
if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE) {
transfer_rate = 0;
if (elapsed > 0) {
transfer_rate = transfer_info->num_files / elapsed;
}

if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE ||
transfer_rate <= 0) {

caja_progress_info_set_details (job->progress, files_left_s);
} else {
char *details, *time_left_s;
int remaining_time;
double transfer_rate;

transfer_rate = transfer_info->num_files / elapsed;
remaining_time = files_left / transfer_rate;

/* Translators: %T will expand to a time like "2 minutes".
Expand Down

0 comments on commit 01bf8cf

Please sign in to comment.