Репозитории ALT
S: | 9.4.0.24.75e248-alt1 |
5.1: | 7.6-alt1 |
4.1: | 6.11-alt1 |
4.0: | 5.97-alt6 |
3.0: | 5.3.1-alt0.4 |
Другие репозитории
Upstream: | 8.1pl3 |
Группа :: Система/Основа
Пакет: coreutils
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: coreutils-5.2.0-rh-alt-ls-stat.patch
Скачать
Скачать
diff -uprk.orig coreutils-5.2.0.orig/src/ls.c coreutils-5.2.0/src/ls.c
--- coreutils-5.2.0.orig/src/ls.c 2004-02-01 22:31:00 +0300
+++ coreutils-5.2.0/src/ls.c 2004-02-24 16:48:10 +0300
@@ -165,7 +165,8 @@ enum filetype
symbolic_link DT_INIT (DT_LNK),
sock DT_INIT (DT_SOCK),
arg_directory DT_INIT (2 * (DT_UNKNOWN | DT_FIFO | DT_CHR | DT_DIR | DT_BLK
- | DT_REG | DT_LNK | DT_SOCK))
+ | DT_REG | DT_LNK | DT_SOCK)),
+ command_line
};
struct fileinfo
@@ -174,6 +175,7 @@ struct fileinfo
char *name;
struct stat stat;
+ int stat_failed;
/* For symbolic link, name of the file linked to, otherwise zero. */
char *linkname;
@@ -227,7 +229,8 @@ static int decode_switches (int argc, ch
static int file_interesting (const struct dirent *next);
static uintmax_t gobble_file (const char *name, enum filetype type,
int explicit_arg, const char *dirname);
-static void print_color_indicator (const char *name, mode_t mode, int linkok);
+static void print_color_indicator (const char *name, mode_t mode, int linkok,
+ int stat_failed);
static void put_indicator (const struct bin_str *ind);
static int put_indicator_direct (const struct bin_str *ind);
static void add_ignore_pattern (const char *pattern);
@@ -247,7 +250,7 @@ static int format_group_width (gid_t g);
static void print_long_format (const struct fileinfo *f);
static void print_many_per_line (void);
static void print_name_with_quoting (const char *p, mode_t mode,
- int linkok,
+ int linkok, int stat_failed,
struct obstack *stack);
static void prep_non_filename_text (void);
static void print_type_indicator (mode_t mode);
@@ -1121,7 +1124,7 @@ main (int argc, char **argv)
for (; i < argc; i++)
{
- gobble_file (argv[i], unknown, 1, "");
+ gobble_file (argv[i], command_line, 1, "");
}
if (dir_defaulted)
@@ -2334,7 +2337,7 @@ gobble_file (const char *name, enum file
if (explicit_arg
|| format_needs_stat
|| (format_needs_type
- && (type == unknown
+ && (type == unknown || type == command_line
/* FIXME: remove this disjunct.
I don't think we care about symlinks here, but for now
@@ -2396,10 +2399,25 @@ gobble_file (const char *name, enum file
break;
}
- if (err < 0)
+ f->stat_failed = (err < 0);
+ if (f->stat_failed)
{
- error (0, errno, "%s", quotearg_colon (path));
- exit_status = 1;
+ /* We treat stat failures for files the user named special.
+ There is no guarantee that these files really exist so
+ we do not print any information. */
+ if (type == command_line)
+ {
+ error (0, errno, "%s", quotearg_colon (path));
+ exit_status = 1;
+ return 0;
+ }
+
+ f->filetype = type;
+ memset (&f->stat, '\0', sizeof (f->stat));
+
+ f->name = xstrdup (name);
+ files_index++;
+
return 0;
}
@@ -2968,9 +2986,9 @@ get_current_time (void)
WIDTH. */
static void
-format_user (uid_t u, int width)
+format_user (uid_t u, int width, int stat_failed)
{
- char const *name = (numeric_ids ? NULL : getuser (u));
+ char const *name = stat_failed ? "?" : (numeric_ids ? NULL : getuser (u));
if (name)
printf ("%-*s ", width, name);
else
@@ -2982,9 +3000,9 @@ format_user (uid_t u, int width)
/* Likewise, for groups. */
static void
-format_group (gid_t g, int width)
+format_group (gid_t g, int width, int stat_failed)
{
- char const *name = (numeric_ids ? NULL : getgroup (g));
+ char const *name = stat_failed ? "?" : (numeric_ids ? NULL : getgroup (g));
if (name)
printf ("%-*s ", width, name);
else
@@ -3089,7 +3107,7 @@ print_long_format (const struct fileinfo
{
char hbuf[INT_BUFSIZE_BOUND (uintmax_t)];
sprintf (p, "%*s ", inode_number_width,
- umaxtostr (f->stat.st_ino, hbuf));
+ f->stat_failed ? "?" : umaxtostr (f->stat.st_ino, hbuf));
p += inode_number_width + 1;
}
@@ -3097,8 +3115,10 @@ print_long_format (const struct fileinfo
{
char hbuf[LONGEST_HUMAN_READABLE + 1];
sprintf (p, "%*s ", block_size_width,
- human_readable (ST_NBLOCKS (f->stat), hbuf, human_output_opts,
- ST_NBLOCKSIZE, output_block_size));
+ f->stat_failed
+ ? "?"
+ : human_readable (ST_NBLOCKS (f->stat), hbuf, human_output_opts,
+ ST_NBLOCKSIZE, output_block_size));
p += block_size_width + 1;
}
@@ -3107,7 +3127,7 @@ print_long_format (const struct fileinfo
{
char hbuf[INT_BUFSIZE_BOUND (uintmax_t)];
sprintf (p, "%s %*s ", modebuf, nlink_width,
- umaxtostr (f->stat.st_nlink, hbuf));
+ f->stat_failed ? "?" : umaxtostr (f->stat.st_nlink, hbuf));
}
p += sizeof modebuf + nlink_width + 1;
@@ -3118,18 +3138,19 @@ print_long_format (const struct fileinfo
DIRED_FPUTS (buf, stdout, p - buf);
if (print_owner)
- format_user (f->stat.st_uid, owner_width);
+ format_user (f->stat.st_uid, owner_width, f->stat_failed);
if (print_group)
- format_group (f->stat.st_gid, group_width);
+ format_group (f->stat.st_gid, group_width, f->stat_failed);
if (print_author)
- format_user (f->stat.st_author, author_width);
+ format_user (f->stat.st_author, author_width, f->stat_failed);
p = buf;
}
- if (S_ISCHR (f->stat.st_mode) || S_ISBLK (f->stat.st_mode))
+ if (!f->stat_failed
+ && (S_ISCHR (f->stat.st_mode) || S_ISBLK (f->stat.st_mode)))
{
char majorbuf[INT_BUFSIZE_BOUND (uintmax_t)];
char minorbuf[INT_BUFSIZE_BOUND (uintmax_t)];
@@ -3147,13 +3168,15 @@ print_long_format (const struct fileinfo
char hbuf[LONGEST_HUMAN_READABLE + 1];
uintmax_t size = unsigned_file_size (f->stat.st_size);
sprintf (p, "%*s ", file_size_width,
- human_readable (size, hbuf, human_output_opts,
- 1, file_output_block_size));
+ f->stat_failed
+ ? "?"
+ : human_readable (size, hbuf, human_output_opts,
+ 1, file_output_block_size));
}
p += file_size_width + 1;
- if ((when_local = localtime (&when)))
+ if (!f->stat_failed && (when_local = localtime (&when)))
{
time_t six_months_ago;
int recent;
@@ -3208,15 +3231,17 @@ print_long_format (const struct fileinfo
print it as a huge integer number of seconds. */
char hbuf[INT_BUFSIZE_BOUND (intmax_t)];
sprintf (p, "%*s ", long_time_expected_width (),
- (TYPE_SIGNED (time_t)
- ? imaxtostr (when, hbuf)
- : umaxtostr (when, hbuf)));
+ f->stat_failed
+ ? "?"
+ : (TYPE_SIGNED (time_t)
+ ? imaxtostr (when, hbuf)
+ : umaxtostr (when, hbuf)));
p += strlen (p);
}
DIRED_FPUTS (buf, stdout, p - buf);
print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
- &dired_obstack);
+ f->stat_failed, &dired_obstack);
if (f->filetype == symbolic_link)
{
@@ -3224,7 +3249,7 @@ print_long_format (const struct fileinfo
{
DIRED_FPUTS_LITERAL (" -> ", stdout);
print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1,
- NULL);
+ f->stat_failed, NULL);
if (indicator_style != none)
print_type_indicator (f->linkmode);
}
@@ -3406,10 +3431,10 @@ quote_name (FILE *out, const char *name,
static void
print_name_with_quoting (const char *p, mode_t mode, int linkok,
- struct obstack *stack)
+ int stat_failed, struct obstack *stack)
{
if (print_with_color)
- print_color_indicator (p, mode, linkok);
+ print_color_indicator (p, mode, linkok, stat_failed);
if (stack)
PUSH_CURRENT_DIRED_POS (stack);
@@ -3454,7 +3479,8 @@ print_file_name_and_frills (const struct
human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
ST_NBLOCKSIZE, output_block_size));
- print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok, NULL);
+ print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
+ f->stat_failed, NULL);
if (indicator_style != none)
print_type_indicator (f->stat.st_mode);
@@ -3493,7 +3519,8 @@ print_type_indicator (mode_t mode)
}
static void
-print_color_indicator (const char *name, mode_t mode, int linkok)
+print_color_indicator (const char *name, mode_t mode, int linkok,
+ int stat_failed)
{
int type = C_FILE;
struct color_ext_type *ext; /* Color extension */
@@ -3523,6 +3550,8 @@ print_color_indicator (const char *name,
type = C_CHR;
else if (S_ISDOOR (mode))
type = C_DOOR;
+ else if (stat_failed)
+ type = C_ORPHAN;
if (type == C_FILE && (mode & S_IXUGO) != 0)
type = C_EXEC;