Skip to content

Commit 1ff745e

Browse files
committed
nemo-file-operations.c: use g_remove for native (path-reachable)
files. Allowing the normal g_file_delete involves gvfs whether the file is native or not. Performance comparison deleting 850mb (41,000 files): git master: ~1m with this patch: ~7s
1 parent a7c6aad commit 1ff745e

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

libnemo-private/nemo-file-operations.c

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <unistd.h>
3636
#include <sys/types.h>
3737
#include <stdlib.h>
38+
#include <errno.h>
3839

3940
#include "nemo-file-operations.h"
4041

@@ -970,6 +971,57 @@ get_parent_name (GFile *file, gchar **name)
970971
*name = get;
971972
}
972973

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+
9731025
static void
9741026
generate_initial_job_details (NemoProgressInfo *info,
9751027
OpKind kind,
@@ -1727,7 +1779,7 @@ delete_dir (CommonJob *job, GFile *dir,
17271779
if (!job_aborted (job) &&
17281780
/* Don't delete dir if there was a skipped file */
17291781
!local_skipped_file) {
1730-
if (!g_file_delete (dir, job->cancellable, &error)) {
1782+
if (!file_delete_wrapper (dir, job->cancellable, &error)) {
17311783
if (job->skip_all_error) {
17321784
goto skip;
17331785
}
@@ -1786,7 +1838,7 @@ delete_file (CommonJob *job, GFile *file,
17861838
}
17871839

17881840
error = NULL;
1789-
if (g_file_delete (file, job->cancellable, &error)) {
1841+
if (file_delete_wrapper (file, job->cancellable, &error)) {
17901842
nemo_file_changes_queue_file_removed (file);
17911843
transfer_info->num_files ++;
17921844
report_delete_progress (job, source_info, transfer_info);
@@ -3776,7 +3828,7 @@ copy_move_directory (CopyMoveJob *copy_job,
37763828
if (!job_aborted (job) && copy_job->is_move &&
37773829
/* Don't delete source if there was a skipped file */
37783830
!local_skipped_file) {
3779-
if (!g_file_delete (src, job->cancellable, &error)) {
3831+
if (!file_delete_wrapper (src, job->cancellable, &error)) {
37803832
if (job->skip_all_error) {
37813833
goto skip;
37823834
}
@@ -3902,7 +3954,7 @@ remove_target_recursively (CommonJob *job,
39023954

39033955
error = NULL;
39043956

3905-
if (!g_file_delete (file, job->cancellable, &error)) {
3957+
if (!file_delete_wrapper (file, job->cancellable, &error)) {
39063958
if (job->skip_all_error ||
39073959
IS_IO_ERROR (error, CANCELLED)) {
39083960
goto skip2;
@@ -4482,7 +4534,7 @@ copy_move_file (CopyMoveJob *copy_job,
44824534
error = NULL;
44834535

44844536
/* 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) &&
44864538
!IS_IO_ERROR (error, NOT_FOUND)) {
44874539
if (job->skip_all_error) {
44884540
g_error_free (error);
@@ -6514,7 +6566,7 @@ delete_trash_file (CommonJob *job,
65146566
}
65156567

65166568
if (!job_aborted (job) && del_file) {
6517-
g_file_delete (file, job->cancellable, NULL);
6569+
file_delete_wrapper (file, job->cancellable, NULL);
65186570

65196571
if ((*deletions_since_progress)++ > 100) {
65206572
nemo_progress_info_pulse_progress (job->progress);

0 commit comments

Comments
 (0)