[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug#339136: Changes in stat package output break apt-move
From: |
Jim Meyering |
Subject: |
Re: Bug#339136: Changes in stat package output break apt-move |
Date: |
Tue, 15 Nov 2005 11:42:12 +0100 |
[ For those reading this via bug-coreutils, the original bug report
is here: http://bugs.debian.org/339136. ]
Thanks for the report.
FYI, this change was mentioned in the NEWS for upstream coreutils-5.3.0,
10 months ago.
With stat, a specified format is no longer automatically newline terminated.
If you want a newline at the end of your output, append `\n' to the format
string.
One problem is that the NEWS entry is inaccurate,
since appending \n doesn't help at all.
Unfortunately, no one reported the problem before this.
Petr Vandrovec <address@hidden> wrote:
> Package: coreutils
> Version: 5.93-2
> Severity: critical
> Justification: renders apt-move unusable
>
> Hello,
> in the past 'stat -L -c "%s" / /' produced
>
> 4096 <LF>
> 4096 <LF>
>
> while now (since 5.93 update) it produces
>
> 40964096
You can work around that portably by using e.g.,
stat -L -c %s: / / | tr : '\n'
I expect to make stat accept \n, as NEWS says it does,
and to document that. Preliminary patch below.
I'm vacillating on whether to accept other backslash escapes.
> without any explanation why this happened. This breaks at least apt-move and
> some programs I've written.
>
> But what's worse is that now stat does not provide any way how to get each of
> stat results on separate line - "%s\n" just generates "4096\n4096\n", without
> interpreting \n...
>
> Can you revert to the old behavior and provide special option for new (IMHO
> broken) one, or provide some method how to embed LF to the output without
> actually having LF embedded directly into shell scripts? Though I would
> prefer
> backward compatibility over even bigger incompatibility.
>
> See bug 339024 for apt-move's half of story.
Index: stat.c
===================================================================
RCS file: /fetish/cu/src/stat.c,v
retrieving revision 1.89
diff -u -p -r1.89 stat.c
--- stat.c 15 Oct 2005 10:15:48 -0000 1.89
+++ stat.c 15 Nov 2005 10:41:03 -0000
@@ -536,6 +536,24 @@ print_stat (char *pformat, size_t buf_le
}
static void
+print_esc (FILE *fp, char const *s)
+{
+ while (*s)
+ {
+ if (*s == '\\' && s[1] == 'n')
+ {
+ fputc ('\n', fp);
+ ++s;
+ }
+ else
+ {
+ fputc (*s, fp);
+ }
+ ++s;
+ }
+}
+
+static void
print_it (char const *masterformat, char const *filename,
void (*print_func) (char *, size_t, char, char const *, void const *),
void const *data)
@@ -558,7 +576,7 @@ print_it (char const *masterformat, char
{
size_t len;
*p++ = '\0';
- fputs (b, stdout);
+ print_esc (stdout, b);
len = strspn (p, "#-+.I 0123456789");
dest[0] = '%';
@@ -573,6 +591,9 @@ print_it (char const *masterformat, char
b = NULL;
/* fall through */
case '%':
+ if (0 < len)
+ error (EXIT_FAILURE, 0, _("%s%s: invalid directive"),
+ quotearg_colon (dest), *p ? "%" : "");
putchar ('%');
break;
default:
@@ -582,7 +603,7 @@ print_it (char const *masterformat, char
}
else
{
- fputs (b, stdout);
+ print_esc (stdout, b);
b = NULL;
}
}
- Re: Bug#339136: Changes in stat package output break apt-move,
Jim Meyering <=