Hi! This patch being proposed is created for support of the trash in gnome or in kde. The files get into the trash only from /home directory and while mc is run in gnome or kde. I think that root does not need the trash but users must not delete files outside home directory and not work without GUI.
-- Sincerely yours, Vadim Likhota
--- mc-4.6.1a/src/file.h.trash 2006-01-29 22:26:05.000000000 +0200 +++ mc-4.6.1a/src/file.h 2006-05-04 21:28:56.000000000 +0300 @@ -13,8 +13,8 @@ int copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel, int move_over, int delete, struct link *parent_dirs, off_t *progress_count, double *progress_bytes); -int erase_dir (FileOpContext *ctx, const char *s, off_t *progress_count, - double *progress_bytes); +int erase_dir (FileOpContext *ctx, const char *s, const char *dr, + off_t *progress_count, double *progress_bytes); int panel_operate (void *source_panel, FileOperation op, int force_single); --- mc-4.6.1a/src/file.c.trash 2006-01-29 22:26:05.000000000 +0200 +++ mc-4.6.1a/src/file.c 2006-05-04 21:27:35.000000000 +0300 @@ -128,7 +128,7 @@ static int query_recursive (FileOpContext * ctx, const char *s); static int do_file_error (const char *str); static int erase_dir_iff_empty (FileOpContext *ctx, const char *s); -static int erase_file (FileOpContext *ctx, const char *s, +static int erase_file (FileOpContext *ctx, const char *s, const char *fl, off_t *progress_count, double *progress_bytes, int is_toplevel_file); static int files_error (const char *format, const char *file1, @@ -992,7 +992,7 @@ if (S_ISDIR (buf.st_mode)) { return_status = erase_dir_iff_empty (ctx, path); } else - return_status = erase_file (ctx, path, 0, 0, 0); + return_status = erase_file (ctx, path, next->d_name, 0, 0, 0); } } g_free (path); @@ -1248,7 +1248,7 @@ erase_dir_iff_empty (ctx, erase_list->name); } else return_status = - erase_file (ctx, erase_list->name, 0, 0, 0); + erase_file (ctx, erase_list->name, NULL, 0, 0, 0); lp = erase_list; erase_list = erase_list->next; g_free (lp); @@ -1271,33 +1271,70 @@ /* {{{ Erase routines */ /* Don't update progress status if progress_count==NULL */ static int -erase_file (FileOpContext *ctx, const char *s, off_t *progress_count, +erase_file (FileOpContext *ctx, const char *s, const char *fl, off_t *progress_count, double *progress_bytes, int is_toplevel_file) { int return_status; - struct stat buf; - - if (file_progress_show_deleting (ctx, s) == FILE_ABORT) - return FILE_ABORT; - mc_refresh (); - if (progress_count && mc_lstat (s, &buf)) { - /* ignore, most likely the mc_unlink fails, too */ - buf.st_size = 0; - } - - while (mc_unlink (s)) { - return_status = - file_error (_(" Cannot delete file \"%s\" \n %s "), s); - if (return_status != FILE_RETRY) +#ifdef __linux__ + if ( safe_delete && strncmp(s, "/home", 5) == 0 && system_type > 1 && fl ) { + char *d; + + if ( system_type == 3 ) { /* kde */ + char *di; + + d = g_strconcat (trash_dir, "/files/", fl, (char *) NULL); + if ( (return_status = move_file_file(ctx, s, d, progress_count, progress_bytes)) == FILE_CONT) { + FILE *f; + + di = g_strconcat (trash_dir, "/info/", fl, ".trashinfo", (char *) NULL); + f = fopen(di, "w+"); + fprintf(f, "[Trash Info]\nPath=%s\nDeletionDate=\n", s); + fclose(f); + g_free(di); + } + g_free(d); return return_status; + } + d = concat_dir_and_file (trash_dir, fl); + return_status = move_file_file(ctx, s, d, progress_count, progress_bytes); + + g_free(d); + return return_status; } + else { /* not use trash */ +#endif + struct stat buf; + char *trash; + FILE *f = fopen("/home/vadim/mc_out", "w+"); + + trash = concat_dir_and_file (trash_dir, fl); + fprintf(f, "%s\n", trash); + fclose(f); + + if (file_progress_show_deleting (ctx, s) == FILE_ABORT) + return FILE_ABORT; + mc_refresh (); + + if (progress_count && mc_lstat (s, &buf)) { + /* ignore, most likely the mc_unlink fails, too */ + buf.st_size = 0; + } + + while (mc_unlink (s)) { + return_status = + file_error (_(" Cannot delete file \"%s\" \n %s "), s); + if (return_status != FILE_RETRY) + return return_status; + } - if (progress_count) - return progress_update_one (ctx, progress_count, progress_bytes, + if (progress_count) + return progress_update_one (ctx, progress_count, progress_bytes, buf.st_size, is_toplevel_file); - else - return FILE_CONT; +#ifdef __linux__ + } /* not use trash */ +#endif + return FILE_CONT; } static int @@ -1336,7 +1373,7 @@ != FILE_CONT); else return_status = - erase_file (ctx, path, progress_count, progress_bytes, 0); + erase_file (ctx, path, NULL, progress_count, progress_bytes, 0); g_free (path); } mc_closedir (reading); @@ -1383,7 +1420,7 @@ } int -erase_dir (FileOpContext *ctx, const char *s, off_t *progress_count, +erase_dir (FileOpContext *ctx, const char *s, const char *dr, off_t *progress_count, double *progress_bytes) { int error; @@ -1405,22 +1442,53 @@ we would have to check also for EIO. I hope the new way is fool proof. (Norbert) */ - error = check_dir_is_empty (s); - if (error == 0) { /* not empty */ - error = query_recursive (ctx, s); - if (error == FILE_CONT) - return recursive_erase (ctx, s, progress_count, - progress_bytes); - else +#ifdef __linux + if ( safe_delete && strncmp(s, "/home", 5) == 0 && system_type > 1 && dr ) { + char *d; + + if ( system_type == 3 ) { /* kde */ + char *di; + + d = g_strconcat (trash_dir, "/files/", dr, (char *) NULL); + if ( (error = move_file_file(ctx, s, d, progress_count, progress_bytes)) == FILE_CONT) { + FILE *f; + + di = g_strconcat (trash_dir, "/info/", dr, ".trashinfo", (char *) NULL); + f = fopen(di, "w+"); + fprintf(f, "[Trash Info]\nPath=%s\nDeletionDate=\n", s); + fclose(f); + g_free(di); + } + g_free(d); return error; + } + d = concat_dir_and_file (trash_dir, dr); + error = move_file_file(ctx, s, d, progress_count, progress_bytes); + + g_free(d); + return error; } + else { /* not use trash */ +#endif + error = check_dir_is_empty (s); + if (error == 0) { /* not empty */ + error = query_recursive (ctx, s); + if (error == FILE_CONT) + return recursive_erase (ctx, s, progress_count, + progress_bytes); + else + return error; + } - while (my_rmdir (s) == -1) { - error = - file_error (_(" Cannot remove directory \"%s\" \n %s "), s); - if (error != FILE_RETRY) - return error; - } + while (my_rmdir (s) == -1) { + error = + file_error (_(" Cannot remove directory \"%s\" \n %s "), s); + if (error != FILE_RETRY) + return error; + } +#ifdef __linux + } /* not use trash */ +#endif return FILE_CONT; } @@ -1861,10 +1929,10 @@ if (operation == OP_DELETE) { if (S_ISDIR (src_stat.st_mode)) - value = erase_dir (ctx, source_with_path, &count, &bytes); + value = erase_dir (ctx, source_with_path, source, &count, &bytes); else value = - erase_file (ctx, source_with_path, &count, &bytes, 1); + erase_file (ctx, source_with_path, source, &count, &bytes, 1); } else { temp = transform_source (ctx, source_with_path); @@ -1955,10 +2023,10 @@ if (operation == OP_DELETE) { if (S_ISDIR (src_stat.st_mode)) value = - erase_dir (ctx, source_with_path, &count, &bytes); + erase_dir (ctx, source_with_path, source, &count, &bytes); else value = - erase_file (ctx, source_with_path, &count, &bytes, + erase_file (ctx, source_with_path, source, &count, &bytes, 1); } else { temp = transform_source (ctx, source_with_path); --- mc-4.6.1a/src/tree.c.trash 2005-08-16 01:36:53.000000000 +0300 +++ mc-4.6.1a/src/tree.c 2006-05-04 21:30:18.000000000 +0300 @@ -721,7 +721,7 @@ ctx = file_op_context_new (OP_DELETE); file_op_context_create_ui (ctx, FALSE); - if (erase_dir (ctx, tree->selected_ptr->name, &count, &bytes) == + if (erase_dir (ctx, tree->selected_ptr->name, NULL, &count, &bytes) == FILE_CONT) tree_forget_cmd (tree); file_op_context_destroy (ctx); --- mc-4.6.1a/src/main.h.trash 2006-01-29 22:26:05.000000000 +0200 +++ mc-4.6.1a/src/main.h 2006-05-02 20:59:53.000000000 +0300 @@ -71,6 +71,10 @@ extern int midnight_shutdown; extern char cmd_buf [512]; extern const char *shell; +#ifdef __linux__ +extern int system_type; +extern const char *trash_dir; +#endif /* Ugly hack in order to distinguish between left and right panel in menubar */ extern int is_right; /* If the selected menu was the right */ --- mc-4.6.1a/src/main.c.trash 2006-01-29 22:26:05.000000000 +0200 +++ mc-4.6.1a/src/main.c 2006-05-04 22:22:16.000000000 +0300 @@ -233,6 +233,14 @@ /* The home directory */ const char *home_dir = NULL; +#ifdef __linux__ +/* console - 0 ; x system - 1 ; gnome = 2 ; kde - 3 */ +int system_type = 0; + +/* Trash in home directory */ +const char *trash_dir = NULL; +#endif + /* The value of the other directory, only used when loading the setup */ char *other_dir = NULL; @@ -2162,6 +2170,27 @@ home_dir = mc_home; } +#ifdef __linux__ + { + const char *dp = getenv("DISPLAY"); + const char *ds = getenv("DESKTOP_SESSION"); + + if ( dp && strlen(dp) > 0 ) { + system_type = 1; + if ( ds ) { + if ( !strcmp(ds, "gnome" ) ) { + system_type = 2; + trash_dir = concat_dir_and_file (home_dir, ".Trash"); + } + else if ( !strcmp(ds, "kde" ) ) { + system_type = 3; + trash_dir = concat_dir_and_file (home_dir, ".local/share/Trash"); + } + } + } + } +#endif + vfs_init (); #ifdef HAVE_SLANG
_______________________________________________ Mc-devel mailing list http://mail.gnome.org/mailman/listinfo/mc-devel