diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index 23941d21..6c0af582 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -22,7 +22,12 @@ #include #endif +#ifdef HAVE_ERRNO_H +#include +#endif + #include +#include #include #include @@ -83,6 +88,40 @@ _tij_collect_nofollow (ThunarJob *job, +static gboolean +_tij_delete_file (GFile *file, + GCancellable *cancellable, + GError **error) +{ + gchar *path; + int errsv; + + if (!g_file_is_native (file)) + return g_file_delete (file, cancellable, error); + + /* adapted from _g_local_file_delete of gio/glocalfile.c */ + path = g_file_get_path (file); + + if (g_remove (path) == 0) + { + g_free (path); + return TRUE; + } + + /* Posix allows EEXIST too, but the more sane error is + * G_IO_ERROR_NOT_FOUND, and it's what nautilus expects */ + if ((errsv = errno) == EEXIST) + errsv = ENOTEMPTY; + + g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), + _("Error removing file: %s"), g_strerror (errsv)); + + g_free (path); + return FALSE; +} + + + static gboolean _thunar_io_jobs_create (ThunarJob *job, GArray *param_values, @@ -185,7 +224,7 @@ again: if (response == THUNAR_JOB_RESPONSE_YES) { /* try to remove the file. fail if not possible */ - if (g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err)) + if (_tij_delete_file (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err)) goto again; } @@ -340,7 +379,7 @@ again: if (response == THUNAR_JOB_RESPONSE_YES) { /* try to remove the file, fail if not possible */ - if (g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err)) + if (_tij_delete_file (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err)) goto again; } @@ -464,7 +503,7 @@ _thunar_io_jobs_unlink (ThunarJob *job, again: /* try to delete the file */ - if (g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err)) + if (_tij_delete_file (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err)) { /* notify the thumbnail cache that the corresponding thumbnail can also * be deleted now */ @@ -678,7 +717,7 @@ _thunar_io_jobs_link_file (ThunarJob *job, { /* try to remove the target file. if not possible, err will be set and * the while loop will be aborted */ - g_file_delete (target_file, exo_job_get_cancellable (EXO_JOB (job)), &err); + _tij_delete_file (target_file, exo_job_get_cancellable (EXO_JOB (job)), &err); } /* tell the caller that we skipped this file if the user doesn't want to @@ -842,7 +881,7 @@ _thunar_io_jobs_trash (ThunarJob *job, break; if (response == THUNAR_JOB_RESPONSE_YES) - g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err); + _tij_delete_file (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err); } /* update the thumbnail cache */