[PATCH] Fix for tottaly broken background operations support - part 2



Hello,

Ok, the next part. More are coming.

This part doesn't even depend on the first one. Both can be reviewed
independently. This one is pretty straight forward. The following call in
copy_file_file() in file.c is not background operation safe:

    if (dst_status == DEST_SHORT) {
        /* Remove short file */
        int result;
        result = query_dialog (_("Copy"),
                _("Incomplete file was retrieved. Keep it?"),
                D_ERROR, 2, _("&Delete"), _("&Keep"));

query_dialog() is not supposed to be called from a background MC. This
patch replaces query_dialog() with the background safe function
query_copy_incomplete().
--- src/background.c	2005-07-14 12:07:29.027421942 +0300
+++ src/background.c.last	2005-07-14 12:03:56.594691651 +0300
@@ -274,6 +274,9 @@ background_attention (int fd, void *clos
     if (type == Return_Integer){
 	if (!have_ctx)
 	    switch (argc){
+	    case 0:
+		result = (*(int (*)(int))routine)(Background);
+		break;
 	    case 1:
 		result = (*(int (*)(int, char *))routine)(Background, data [0]);
 		break;
Index: src/file.c
===================================================================
RCS file: /cvsroot/mc/mc/src/file.c,v
retrieving revision 1.142
diff -u -p -r1.142 file.c
--- src/file.c	5 Jul 2005 18:18:39 -0000	1.142
+++ src/file.c	14 Jul 2005 09:01:00 -0000
@@ -130,6 +130,7 @@ static int query_replace (FileOpContext 
 			  struct stat *_s_stat, struct stat *_d_stat);
 static int query_recursive (FileOpContext * ctx, const char *s);
 static int do_file_error (const char *str);
+static int query_copy_incomplete (void);
 static int erase_dir_iff_empty (FileOpContext *ctx, const char *s);
 static int erase_file (FileOpContext *ctx, const char *s,
 		       off_t *progress_count, double *progress_bytes,
@@ -775,9 +776,7 @@ copy_file_file (FileOpContext *ctx, cons
     if (dst_status == DEST_SHORT) {
 	/* Remove short file */
 	int result;
-	result = query_dialog (_("Copy"),
-		_("Incomplete file was retrieved. Keep it?"),
-		D_ERROR, 2, _("&Delete"), _("&Keep"));
+	result = query_copy_incomplete ();
 	if (!result)
 	    mc_unlink (dst_path);
     } else if (dst_status == DEST_FULL) {
@@ -2161,6 +2161,18 @@ real_query_recursive (FileOpContext *ctx
     }
 }
 
+static int
+real_query_copy_incomplete (enum OperationMode mode)
+{
+    int result;
+
+    result = query_dialog (_("Copy"),
+			   _("Incomplete file was retrieved. Keep it?"),
+			   D_ERROR, 2, _("&Delete"), _("&Keep"));
+
+    return result;
+}
+
 #ifdef WITH_BACKGROUND
 static int
 do_file_error (const char *str)
@@ -2197,6 +2209,15 @@ query_replace (FileOpContext *ctx, const
 						 _s_stat, _d_stat);
 }
 
+static int
+query_copy_incomplete (void)
+{
+    if (we_are_background)
+	return parent_call (real_query_copy_incomplete, NULL, 0);
+    else
+	return real_query_copy_incomplete (Foreground);
+}
+
 #else
 static int
 do_file_error (const char *str)
@@ -2216,6 +2237,12 @@ query_replace (FileOpContext *ctx, const
 {
     return file_progress_real_query_replace (ctx, Foreground, destname,
 					     _s_stat, _d_stat);
+}
+
+static int
+query_copy_incomplete (void)
+{
+    return real_query_copy_incomplete (Foreground);
 }
 
 #endif				/* !WITH_BACKGROUND */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]