]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
When forming a truncated name, use the "[...]" prefix even for
authorJim Meyering <meyering@redhat.com>
Mon, 8 Oct 2007 08:34:04 +0000 (10:34 +0200)
committerJim Meyering <meyering@redhat.com>
Mon, 8 Oct 2007 08:47:40 +0000 (10:47 +0200)
an extremely long name in the current directory.

* src/remove.c (full_filename_): Rename a local variable.
Use two separate "truncated" variables, in case the second
call to right_justify does not indicate any truncation -- which
would happen only if the single component FILENAME were longer
than 511 bytes and DIR_NAME were empty.

ChangeLog
src/c99-to-c89.diff
src/remove.c

index eb8763a02bc5b9f4b1f179cb4b9ec96c54f150e2..f6d6da7b8fba8d4a3dfb42ff772cd57283ea103b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2007-10-08  Jim Meyering  <meyering@redhat.com>
 
+       When forming a truncated name, use the "[...]" prefix even for
+       an extremely long name in the current directory
+       * src/remove.c (full_filename_): Rename a local variable.
+       Use two separate "truncated" variables, in case the second
+       call to right_justify does not indicate any truncation -- which
+       would happen only if the single component FILENAME were longer
+       than 511 bytes and DIR_NAME were empty.
+
        rm could malfunction under unusual circumstances:
        When operating on a relative name longer than 511 bytes,
        and (when either processing a directory that is neither writable
index f6c7664ede3fba556d324bf2f3473a4e7e3510a2..76ecad28cdd59918ad126c7001854785caca1e5a 100644 (file)
@@ -13,7 +13,7 @@ diff -upr src/remove.c src/remove.c
    assert (top_len >= 2);
 
    /* Pop the specified length of file name.  */
-@@ -419,10 +420,11 @@ AD_stack_top (Dirstack_state const *ds)
+@@ -422,10 +423,11 @@ AD_stack_top (Dirstack_state const *ds)
  static void
  AD_stack_pop (Dirstack_state *ds)
  {
@@ -26,7 +26,7 @@ diff -upr src/remove.c src/remove.c
    if (top->unremovable)
      hash_free (top->unremovable);
    obstack_blank (&ds->Active_dir, -(int) sizeof (struct AD_ent));
-@@ -904,6 +906,7 @@ prompt (int fd_cwd, Dirstack_state const
+@@ -907,6 +909,7 @@ prompt (int fd_cwd, Dirstack_state const
            break;
          }
 
@@ -34,7 +34,7 @@ diff -upr src/remove.c src/remove.c
        char const *quoted_name = quote (full_filename (filename));
 
        if (0 < write_protected)
-@@ -943,6 +946,7 @@ prompt (int fd_cwd, Dirstack_state const
+@@ -946,6 +949,7 @@ prompt (int fd_cwd, Dirstack_state const
                    : _("%s: remove %s %s? ")),
                   program_name, file_type (sbuf), quoted_name);
        }
@@ -42,7 +42,7 @@ diff -upr src/remove.c src/remove.c
 
        if (!yesno ())
        return RM_USER_DECLINED;
-@@ -1562,6 +1566,7 @@ rm_1 (Dirstack_state *ds, char const *fi
+@@ -1565,6 +1569,7 @@ rm_1 (Dirstack_state *ds, char const *fi
        return RM_ERROR;
      }
 
@@ -50,7 +50,7 @@ diff -upr src/remove.c src/remove.c
    struct stat st;
    cache_stat_init (&st);
    cycle_check_init (&ds->cycle_check_state);
-@@ -1584,6 +1589,7 @@ rm_1 (Dirstack_state *ds, char const *fi
+@@ -1587,6 +1592,7 @@ rm_1 (Dirstack_state *ds, char const *fi
    AD_push_initial (ds);
    AD_INIT_OTHER_MEMBERS ();
 
@@ -58,7 +58,7 @@ diff -upr src/remove.c src/remove.c
    enum RM_status status = remove_entry (AT_FDCWD, ds, filename,
                                        DT_UNKNOWN, &st, x);
    if (status == RM_NONEMPTY_DIR)
-@@ -1602,6 +1608,8 @@ rm_1 (Dirstack_state *ds, char const *fi
+@@ -1605,6 +1611,8 @@ rm_1 (Dirstack_state *ds, char const *fi
    ds_clear (ds);
    return status;
  }
index 1023048ff563cd16cfd29785ea1387a3d605f4d3..1c6166d5ec47511b271e3cc88370efa84e04265c 100644 (file)
@@ -383,17 +383,20 @@ full_filename_ (Dirstack_state const *ds, const char *filename)
 #define SBUF_SIZE 512
 #define ELLIPSES_PREFIX "[...]"
     static char static_buf[SBUF_SIZE];
-    bool truncated;
-    size_t len;
+    bool file_truncated;
+    bool dir_truncated;
+    size_t n_bytes_remaining;
     char *p;
     char *dir_name = obstack_base (&ds->dir_stack);
     size_t dir_len = obstack_object_size (&ds->dir_stack);
 
     free (g_buf);
-    len = right_justify (static_buf, SBUF_SIZE, filename,
-                        strlen (filename) + 1, &p, &truncated);
-    right_justify (static_buf, len, dir_name, dir_len, &p, &truncated);
-    if (truncated)
+    n_bytes_remaining = right_justify (static_buf, SBUF_SIZE, filename,
+                                      strlen (filename) + 1, &p,
+                                      &file_truncated);
+    right_justify (static_buf, n_bytes_remaining, dir_name, dir_len,
+                  &p, &dir_truncated);
+    if (file_truncated || dir_truncated)
       {
        memcpy (static_buf, ELLIPSES_PREFIX,
                sizeof (ELLIPSES_PREFIX) - 1);