[Cxplorer-cvs 01117] CVS update: cxplorer/src

Back to archive index

Yasumichi Akahoshi yasum****@users*****
2005年 5月 15日 (日) 00:35:10 JST


Index: cxplorer/src/cxp-right-pane.c
diff -u cxplorer/src/cxp-right-pane.c:1.45 cxplorer/src/cxp-right-pane.c:1.46
--- cxplorer/src/cxp-right-pane.c:1.45	Sat May 14 14:45:59 2005
+++ cxplorer/src/cxp-right-pane.c	Sun May 15 00:35:10 2005
@@ -600,7 +600,10 @@
 	gchar *dispname;
 	gchar **filetype;
 
-	dispname = cxp_path_get_basename_of_utf8 (fullpath);
+	if((dispname = cxp_path_get_basename_of_utf8 (fullpath)) == NULL)
+	{
+		dispname = g_strdup (_("(Invalid filename)"));
+	}
 	filetype =
 		g_strsplit (magic_file (priv->normal_cookie, fullpath), ",", 2);
 	stat (fullpath, &status);
@@ -763,23 +766,80 @@
 	gchar *fullpath;
 	gchar *filename;
 
+	/* for "rm -rf" */
+	gchar *error_msg;
+	gchar *cmd;
+	gchar *standard_error;
+	gint exit_status;
+
 	gtk_tree_model_get (model, iter, COL_FILE_PATH, &fullpath, COL_TERMINATOR);
+	filename = cxp_path_get_basename_of_utf8 (fullpath);
 
-	if (unlink (fullpath) != 0)
+	if (g_file_test(fullpath, G_FILE_TEST_IS_DIR) && !g_file_test(fullpath, G_FILE_TEST_IS_SYMLINK))
 	{
-		filename = cxp_path_get_basename_of_utf8 (fullpath);
-		dialog = gtk_message_dialog_new (NULL,
-				GTK_DIALOG_DESTROY_WITH_PARENT,
-				GTK_MESSAGE_ERROR,
-				GTK_BUTTONS_CLOSE,
-				"%s:%s",
-				filename,
-				g_strerror (errno));
-		gtk_dialog_run (GTK_DIALOG (dialog));
-		gtk_widget_destroy (dialog);
-		g_free (filename);
+		if(rmdir(fullpath) == -1)
+		{
+			switch(errno)
+			{
+				case ENOTEMPTY:
+					dialog = gtk_message_dialog_new (NULL,
+							GTK_DIALOG_DESTROY_WITH_PARENT,
+							GTK_MESSAGE_ERROR,
+							GTK_BUTTONS_YES_NO,
+							"%s:%s\nDo you really delete it?",
+							filename,
+							g_strerror (errno));
+					if(gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
+					{
+						cmd = g_strdup_printf ("rm -rf '%s'", filename);
+						g_spawn_command_line_sync (cmd, NULL, &standard_error,
+								&exit_status, NULL);
+						if (exit_status != 0)
+						{
+							error_msg = g_locale_to_utf8 (standard_error, -1, NULL, NULL, NULL);
+							dialog = gtk_message_dialog_new (NULL,
+									GTK_DIALOG_DESTROY_WITH_PARENT,
+									GTK_MESSAGE_ERROR,
+									GTK_BUTTONS_CLOSE,
+									"%s",
+									error_msg);
+							gtk_dialog_run (GTK_DIALOG (dialog));
+							gtk_widget_destroy (dialog);
+							g_free (error_msg);
+						}
+					}
+					gtk_widget_destroy (dialog);
+					break;
+				default:
+					dialog = gtk_message_dialog_new (NULL,
+							GTK_DIALOG_DESTROY_WITH_PARENT,
+							GTK_MESSAGE_ERROR,
+							GTK_BUTTONS_CLOSE,
+							"%s:%s",
+							filename,
+							g_strerror (errno));
+					gtk_dialog_run (GTK_DIALOG (dialog));
+					gtk_widget_destroy (dialog);
+			}
+		}
+	}
+	else
+	{
+		if (unlink (fullpath) != 0)
+		{
+			dialog = gtk_message_dialog_new (NULL,
+					GTK_DIALOG_DESTROY_WITH_PARENT,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_CLOSE,
+					"%s:%s",
+					filename,
+					g_strerror (errno));
+			gtk_dialog_run (GTK_DIALOG (dialog));
+			gtk_widget_destroy (dialog);
+		}
 	}
 
+	g_free (filename);
 	g_free (fullpath);
 }
 


Cxplorer-cvs メーリングリストの案内
Back to archive index