[PATCH] Re: Parent directory's permissions in mini-status



Hi Sergey,

On Thu, 2005-03-31 at 13:00, Sergey Ilyevsky wrote:
> It seems that mc shows wrong permission for parent dir in mini-status,
> or in long-file (or user-defined) listing mode.

Just discussed this with Roland Illig who came up with a patch that
seems to work correctly. I further fixed his patch to not need
add_dotdot_to_list() anymore by moving the relevant parts to
set_zero_dir(). I hope my assumption that set_zero_dir() is never called
with an empty list is correct. This way we can safely drop the
list->size check that was in add_dotdot_to_list().

Please verify the correctness of this patch.

Leonard.

-- 
mount -t life -o ro /dev/dna /genetic/research

--- src/dir.c.dotdotdir	2004-11-03 21:31:59.000000000 +0100
+++ src/dir.c	2005-04-02 13:32:57.000000000 +0200
@@ -336,11 +336,11 @@ clean_dir (dir_list *list, int count)
 	list->list [i].fname = 0;
     }
 }
-
+/*
 static int
 add_dotdot_to_list (dir_list *list, int index)
 {
-    /* Need to grow the *list? */
+    /* Need to grow the *list?
     if (index == list->size) {
 	list->list = g_realloc (list->list, sizeof (file_entry) *
 			      (list->size + RESIZE_STEPS));
@@ -359,12 +359,20 @@ add_dotdot_to_list (dir_list *list, int 
     (list->list) [index].st.st_mode = 040755;
     return 1;
 }
-
+*/
 /* Used to set up a directory list when there is no access to a directory */
 int
 set_zero_dir (dir_list *list)
 {
-    return (add_dotdot_to_list (list, 0));
+    memset (&(list->list) [0], 0, sizeof(file_entry));
+    (list->list) [0].fnamelen = 2;
+    (list->list) [0].fname = g_strdup ("..");
+    (list->list) [0].f.link_to_dir = 0;
+    (list->list) [0].f.stale_link = 0;
+    (list->list) [0].f.dir_size_computed = 0;
+    (list->list) [0].f.marked = 0;
+    (list->list) [0].st.st_mode = 040755;
+    return 1;
 }
 
 /* If you change handle_dirent then check also handle_path. */
@@ -372,13 +380,14 @@ set_zero_dir (dir_list *list)
 static int
 handle_dirent (dir_list *list, const char *filter, struct dirent *dp,
 	       struct stat *buf1, int next_free, int *link_to_dir,
-	       int *stale_link)
+	       int *stale_link, gboolean want_dotdot)
 {
     if (dp->d_name[0] == '.' && dp->d_name[1] == 0)
 	return 0;
-    if (dp->d_name[0] == '.' && dp->d_name[1] == '.' && dp->d_name[2] == 0)
-	return 0;
-    if (!show_dot_files && (dp->d_name[0] == '.'))
+    if (strcmp(dp->d_name, "..") == 0) {
+	if (!want_dotdot)
+	    return 0;
+    } else if (!show_dot_files && (dp->d_name[0] == '.'))
 	return 0;
     if (!show_backups && dp->d_name[NLENGTH (dp) - 1] == '~')
 	return 0;
@@ -432,8 +441,10 @@ handle_path (dir_list *list, const char 
 {
     if (path [0] == '.' && path [1] == 0)
 	return 0;
+/*
     if (path [0] == '.' && path [1] == '.' && path [2] == 0)
 	return 0;
+*/
     if (mc_lstat (path, buf1) == -1)
         return 0;
 
@@ -481,7 +492,7 @@ do_load_dir (const char *path, dir_list 
     while ((dp = mc_readdir (dirp))) {
 	status =
 	    handle_dirent (list, filter, dp, &st, next_free, &link_to_dir,
-			   &stale_link);
+			   &stale_link, strcmp(path, "/") != 0);
 	if (status == 0)
 	    continue;
 	if (status == -1) {
@@ -503,8 +514,10 @@ do_load_dir (const char *path, dir_list 
 
     if (next_free) {
 	/* Add ".." except the root directory */
+/*
 	if (strcmp (path, "/") != 0)
 	    add_dotdot_to_list (list, next_free++);
+*/
 	do_sort (list, sort, next_free - 1, reverse, case_sensitive);
     } else {
 	next_free = set_zero_dir (list);
@@ -601,7 +614,7 @@ do_reload_dir (const char *path, dir_lis
     while ((dp = mc_readdir (dirp))) {
 	status =
 	    handle_dirent (list, filter, dp, &st, next_free, &link_to_dir,
-			   &stale_link);
+			   &stale_link, strcmp(path, "/") != 0);
 	if (status == 0)
 	    continue;
 	if (status == -1) {
@@ -650,8 +663,10 @@ do_reload_dir (const char *path, dir_lis
     g_hash_table_destroy (marked_files);
     if (next_free) {
 	/* Add ".." except the root directory */
+/*
 	if (strcmp (path, "/") != 0)
 	    add_dotdot_to_list (list, next_free++);
+*/
 	do_sort (list, sort, next_free - 1, rev, case_sensitive);
     } else
 	next_free = set_zero_dir (list);


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