|
35 | 35 | #include <unistd.h>
|
36 | 36 | #include <sys/types.h>
|
37 | 37 | #include <stdlib.h>
|
| 38 | +#include <errno.h> |
38 | 39 |
|
39 | 40 | #include "nemo-file-operations.h"
|
40 | 41 |
|
@@ -970,6 +971,57 @@ get_parent_name (GFile *file, gchar **name)
|
970 | 971 | *name = get;
|
971 | 972 | }
|
972 | 973 |
|
| 974 | +/* adapted from gio/glocalfile.c */ |
| 975 | +static gboolean |
| 976 | +_g_local_file_delete (GFile *file, |
| 977 | + GCancellable *cancellable, |
| 978 | + GError **error) |
| 979 | +{ |
| 980 | + gchar *path; |
| 981 | + |
| 982 | + path = g_file_get_path (file); |
| 983 | + |
| 984 | + if (g_remove (path) == -1) { |
| 985 | + int errsv = errno; |
| 986 | + |
| 987 | + /* Posix allows EEXIST too, but the more sane error |
| 988 | + is G_IO_ERROR_NOT_FOUND, and it's what nautilus |
| 989 | + expects */ |
| 990 | + if (errsv == EEXIST) { |
| 991 | + errsv = ENOTEMPTY; |
| 992 | + } |
| 993 | + |
| 994 | + g_set_error (error, G_IO_ERROR, |
| 995 | + g_io_error_from_errno (errsv), |
| 996 | + _("Error removing file: %s"), |
| 997 | + g_strerror (errsv)); |
| 998 | + |
| 999 | + g_free (path); |
| 1000 | + return FALSE; |
| 1001 | + } |
| 1002 | + |
| 1003 | + g_free (path); |
| 1004 | + return TRUE; |
| 1005 | +} |
| 1006 | + |
| 1007 | +static gboolean |
| 1008 | +file_delete_wrapper (GFile *file, |
| 1009 | + GCancellable *cancellable, |
| 1010 | + GError **error) |
| 1011 | +{ |
| 1012 | + gboolean ret; |
| 1013 | + |
| 1014 | + ret = FALSE; |
| 1015 | + |
| 1016 | + if (g_file_is_native (file)) { |
| 1017 | + ret = _g_local_file_delete (file, cancellable, error); |
| 1018 | + } else { |
| 1019 | + ret = g_file_delete (file, cancellable, error); |
| 1020 | + } |
| 1021 | + |
| 1022 | + return ret; |
| 1023 | +} |
| 1024 | + |
973 | 1025 | static void
|
974 | 1026 | generate_initial_job_details (NemoProgressInfo *info,
|
975 | 1027 | OpKind kind,
|
@@ -1727,7 +1779,7 @@ delete_dir (CommonJob *job, GFile *dir,
|
1727 | 1779 | if (!job_aborted (job) &&
|
1728 | 1780 | /* Don't delete dir if there was a skipped file */
|
1729 | 1781 | !local_skipped_file) {
|
1730 |
| - if (!g_file_delete (dir, job->cancellable, &error)) { |
| 1782 | + if (!file_delete_wrapper (dir, job->cancellable, &error)) { |
1731 | 1783 | if (job->skip_all_error) {
|
1732 | 1784 | goto skip;
|
1733 | 1785 | }
|
@@ -1786,7 +1838,7 @@ delete_file (CommonJob *job, GFile *file,
|
1786 | 1838 | }
|
1787 | 1839 |
|
1788 | 1840 | error = NULL;
|
1789 |
| - if (g_file_delete (file, job->cancellable, &error)) { |
| 1841 | + if (file_delete_wrapper (file, job->cancellable, &error)) { |
1790 | 1842 | nemo_file_changes_queue_file_removed (file);
|
1791 | 1843 | transfer_info->num_files ++;
|
1792 | 1844 | report_delete_progress (job, source_info, transfer_info);
|
@@ -3776,7 +3828,7 @@ copy_move_directory (CopyMoveJob *copy_job,
|
3776 | 3828 | if (!job_aborted (job) && copy_job->is_move &&
|
3777 | 3829 | /* Don't delete source if there was a skipped file */
|
3778 | 3830 | !local_skipped_file) {
|
3779 |
| - if (!g_file_delete (src, job->cancellable, &error)) { |
| 3831 | + if (!file_delete_wrapper (src, job->cancellable, &error)) { |
3780 | 3832 | if (job->skip_all_error) {
|
3781 | 3833 | goto skip;
|
3782 | 3834 | }
|
@@ -3902,7 +3954,7 @@ remove_target_recursively (CommonJob *job,
|
3902 | 3954 |
|
3903 | 3955 | error = NULL;
|
3904 | 3956 |
|
3905 |
| - if (!g_file_delete (file, job->cancellable, &error)) { |
| 3957 | + if (!file_delete_wrapper (file, job->cancellable, &error)) { |
3906 | 3958 | if (job->skip_all_error ||
|
3907 | 3959 | IS_IO_ERROR (error, CANCELLED)) {
|
3908 | 3960 | goto skip2;
|
@@ -4482,7 +4534,7 @@ copy_move_file (CopyMoveJob *copy_job,
|
4482 | 4534 | error = NULL;
|
4483 | 4535 |
|
4484 | 4536 | /* Copying a dir onto file, first remove the file */
|
4485 |
| - if (!g_file_delete (dest, job->cancellable, &error) && |
| 4537 | + if (!file_delete_wrapper (dest, job->cancellable, &error) && |
4486 | 4538 | !IS_IO_ERROR (error, NOT_FOUND)) {
|
4487 | 4539 | if (job->skip_all_error) {
|
4488 | 4540 | g_error_free (error);
|
@@ -6514,7 +6566,7 @@ delete_trash_file (CommonJob *job,
|
6514 | 6566 | }
|
6515 | 6567 |
|
6516 | 6568 | if (!job_aborted (job) && del_file) {
|
6517 |
| - g_file_delete (file, job->cancellable, NULL); |
| 6569 | + file_delete_wrapper (file, job->cancellable, NULL); |
6518 | 6570 |
|
6519 | 6571 | if ((*deletions_since_progress)++ > 100) {
|
6520 | 6572 | nemo_progress_info_pulse_progress (job->progress);
|
|
0 commit comments