Skip to content

Commit

Permalink
caja-file-operations: stop timer when waiting
Browse files Browse the repository at this point in the history
When a copy/move operation is created while another operation is already
active, the new operation is queued. As the (already running) operation
timer of the new operation is not stopped during the waiting period,
that period is (erroneously) included in the transfer rate calculation
and leads to initially low/slowly increasing transfer rates be shown.

Hence stop the operation timer when the (queued) operation is waiting.

Fixes mate-desktop#1420 and mate-desktop#1623.
  • Loading branch information
basicmaster committed Dec 31, 2023
1 parent 7b83931 commit ab55e0b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 11 additions & 11 deletions libcaja-private/caja-file-operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ trash_files (CommonJob *job, GList *files, int *files_skipped)
for (l = files;
l != NULL && !job_aborted (job);
l = l->next) {
caja_progress_info_get_ready (job->progress);
caja_progress_info_get_ready (job->progress, job->time);

file = l->data;

Expand Down Expand Up @@ -3611,7 +3611,7 @@ copy_move_directory (CopyMoveJob *copy_job,
nextinfo = g_file_enumerator_next_file (enumerator, job->cancellable, skip_error?NULL:&error);
while (!job_aborted (job) &&
(info = nextinfo) != NULL) {
caja_progress_info_get_ready (job->progress);
caja_progress_info_get_ready (job->progress, job->time);

nextinfo = g_file_enumerator_next_file (enumerator, job->cancellable, skip_error?NULL:&error);
src_file = g_file_get_child (src,
Expand Down Expand Up @@ -4579,7 +4579,7 @@ copy_files (CopyMoveJob *job,
for (l = job->files;
l != NULL && !job_aborted (common);
l = l->next) {
caja_progress_info_get_ready (common->progress);
caja_progress_info_get_ready (common->progress, common->time);

src = l->data;

Expand Down Expand Up @@ -4897,7 +4897,7 @@ move_file_prepare (CopyMoveJob *move_job,
}

retry:
caja_progress_info_get_ready (job->progress);
caja_progress_info_get_ready (job->progress, job->time);

flags = G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_NO_FALLBACK_FOR_MOVE;
if (overwrite) {
Expand Down Expand Up @@ -5073,7 +5073,7 @@ move_files_prepare (CopyMoveJob *job,

total = left = g_list_length (job->files);

caja_progress_info_get_ready (common->progress);
caja_progress_info_get_ready (common->progress, common->time);
report_move_progress (job, total, left);

i = 0;
Expand Down Expand Up @@ -5139,7 +5139,7 @@ move_files (CopyMoveJob *job,
for (l = fallbacks;
l != NULL && !job_aborted (common);
l = l->next) {
caja_progress_info_get_ready (common->progress);
caja_progress_info_get_ready (common->progress, common->time);

fallback = l->data;
src = fallback->file;
Expand Down Expand Up @@ -5564,7 +5564,7 @@ link_job (GIOSchedulerJob *io_job,
for (l = job->files;
l != NULL && !job_aborted (common);
l = l->next) {
caja_progress_info_get_ready (common->progress);
caja_progress_info_get_ready (common->progress, common->time);

src = l->data;

Expand Down Expand Up @@ -5708,7 +5708,7 @@ set_permissions_file (SetPermissionsJob *job,

caja_progress_info_pulse_progress (common->progress);

caja_progress_info_get_ready (common->progress);
caja_progress_info_get_ready (common->progress, common->time);

free_info = FALSE;
if (info == NULL) {
Expand Down Expand Up @@ -6076,7 +6076,7 @@ create_job (GIOSchedulerJob *io_job,
count = 1;

retry:
caja_progress_info_get_ready (common->progress);
caja_progress_info_get_ready (common->progress, common->time);

error = NULL;
if (job->make_dir) {
Expand Down Expand Up @@ -6406,7 +6406,7 @@ delete_trash_file (CommonJob *job,
gboolean del_file,
gboolean del_children)
{
caja_progress_info_get_ready (job->progress);
caja_progress_info_get_ready (job->progress, job->time);

if (job_aborted (job)) {
return;
Expand Down Expand Up @@ -6555,7 +6555,7 @@ mark_desktop_file_trusted (CommonJob *common,
GFileInfo *info;

retry:
caja_progress_info_get_ready (common->progress);
caja_progress_info_get_ready (common->progress, common->time);

error = NULL;
if (!g_file_load_contents (file,
Expand Down
4 changes: 3 additions & 1 deletion libcaja-private/caja-progress-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ widget_state_notify_paused_callback (ProgressWidgetData *data)
}

void
caja_progress_info_get_ready (CajaProgressInfo *info)
caja_progress_info_get_ready (CajaProgressInfo *info, GTimer *time)
{
if (info->waiting) {
G_LOCK (progress_info);
Expand All @@ -717,8 +717,10 @@ caja_progress_info_get_ready (CajaProgressInfo *info)
g_source_set_callback (source, (GSourceFunc)widget_state_notify_paused_callback, info->widget, NULL);
g_source_attach (source, NULL);

g_timer_stop (time);
while (info->waiting)
g_cond_wait (&info->waiting_c, &G_LOCK_NAME(progress_info));
g_timer_continue (time);
}
G_UNLOCK (progress_info);
}
Expand Down
2 changes: 1 addition & 1 deletion libcaja-private/caja-progress-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ GType caja_progress_info_get_type (void) G_GNUC_CONST;
*/

CajaProgressInfo *caja_progress_info_new (gboolean should_start, gboolean can_pause);
void caja_progress_info_get_ready (CajaProgressInfo *info);
void caja_progress_info_get_ready (CajaProgressInfo *info, GTimer *time);
void caja_progress_info_disable_pause (CajaProgressInfo *info);

GList * caja_get_all_progress_info (void);
Expand Down

0 comments on commit ab55e0b

Please sign in to comment.