Compare commits

...

7 Commits
rawhide ... f23

7 changed files with 2016 additions and 454 deletions

View File

@ -0,0 +1,249 @@
From c72e9f343f3967fcb936e1131430a6853f1e1d33 Mon Sep 17 00:00:00 2001
From: Dave Chiluk <chiluk@canonical.com>
Date: Mon, 31 Aug 2015 16:07:58 -0500
Subject: [PATCH 1/2] mountlist: add me_mntroot field on Linux machines
* lib/mountlist.c (read_file_system_list): Populate me_mntroot in
mount_entry so Linux machines based on /proc/self/mountinfo can
distinguish between bind mounts and original mounts. In reality bind
mounts aren't treated differently than mountroot=/ mounts by the
kernel, but the user often wants these bind mounts distinguished.
* lib/mountlist.h (struct mount_entry): Add me_mntroot element.
More details at https://pad.lv/1432871
Upstream-commit: c6148bca89e9465fd6ba3a10d273ec4cb58c2dbe
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
lib/mountlist.c | 25 ++++++++++++++++++++++---
lib/mountlist.h | 2 ++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 6f04f55..08ade6f 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -447,6 +447,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (mnt->mnt_fsname);
me->me_mountdir = xstrdup (mnt->mnt_dir);
+ me->me_mntroot = NULL;
me->me_type = xstrdup (mnt->mnt_type);
me->me_type_malloced = 1;
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -478,7 +479,8 @@ read_file_system_list (bool need_fs_type)
while (getline (&line, &buf_size, fp) != -1)
{
unsigned int devmaj, devmin;
- int target_s, target_e, type_s, type_e, source_s, source_e;
+ int target_s, target_e, type_s, type_e;
+ int source_s, source_e, mntroot_s, mntroot_e;
char test;
char *dash;
int rc;
@@ -486,13 +488,15 @@ read_file_system_list (bool need_fs_type)
rc = sscanf(line, "%*u " /* id - discarded */
"%*u " /* parent - discarded */
"%u:%u " /* dev major:minor */
- "%*s " /* mountroot - discarded */
+ "%n%*s%n " /* mountroot */
"%n%*s%n" /* target, start and end */
"%c", /* more data... */
&devmaj, &devmin,
+ &mntroot_s, &mntroot_e,
&target_s, &target_e,
&test);
- if (rc != 3 && rc != 5) /* 5 if %n included in count. */
+
+ if (rc != 3 && rc != 7) /* 7 if %n included in count. */
continue;
/* skip optional fields, terminated by " - " */
@@ -511,16 +515,19 @@ read_file_system_list (bool need_fs_type)
continue;
/* manipulate the sub-strings in place. */
+ line[mntroot_e] = '\0';
line[target_e] = '\0';
dash[type_e] = '\0';
dash[source_e] = '\0';
unescape_tab (dash + source_s);
unescape_tab (line + target_s);
+ unescape_tab (line + mntroot_s);
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (dash + source_s);
me->me_mountdir = xstrdup (line + target_s);
+ me->me_mntroot = xstrdup (line + mntroot_s);
me->me_type = xstrdup (dash + type_s);
me->me_type_malloced = 1;
me->me_dev = makedev (devmaj, devmin);
@@ -566,6 +573,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (mnt->mnt_fsname);
me->me_mountdir = xstrdup (mnt->mnt_dir);
+ me->me_mntroot = NULL;
me->me_type = xstrdup (mnt->mnt_type);
me->me_type_malloced = 1;
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, bind);
@@ -598,6 +606,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (fsp->f_mntfromname);
me->me_mountdir = xstrdup (fsp->f_mntonname);
+ me->me_mntroot = NULL;
me->me_type = fs_type;
me->me_type_malloced = 0;
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -624,6 +633,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (fsp->f_mntfromname);
me->me_mountdir = xstrdup (fsp->f_mntonname);
+ me->me_mntroot = NULL;
me->me_type = xstrdup (fsp->f_fstypename);
me->me_type_malloced = 1;
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -650,6 +660,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (fsd.fd_req.devname);
me->me_mountdir = xstrdup (fsd.fd_req.path);
+ me->me_mntroot = NULL;
me->me_type = gt_names[fsd.fd_req.fstype];
me->me_type_malloced = 0;
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -748,6 +759,7 @@ read_file_system_list (bool need_fs_type)
me->me_devname = xstrdup (fi.device_name[0] != '\0'
? fi.device_name : fi.fsh_name);
me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name);
+ me->me_mntroot = NULL;
me->me_type = xstrdup (fi.fsh_name);
me->me_type_malloced = 1;
me->me_dev = fi.dev;
@@ -797,6 +809,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (stats[counter].f_mntfromname);
me->me_mountdir = xstrdup (stats[counter].f_mntonname);
+ me->me_mntroot = NULL;
me->me_type = xstrdup (FS_TYPE (stats[counter]));
me->me_type_malloced = 1;
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -833,6 +846,7 @@ read_file_system_list (bool need_fs_type)
strcpy (me->me_devname + 5, mnt.mt_dev);
# endif
me->me_mountdir = xstrdup (mnt.mt_filsys);
+ me->me_mntroot = NULL;
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
me->me_type = "";
me->me_type_malloced = 0;
@@ -880,6 +894,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup ((*ent)->mt_resource);
me->me_mountdir = xstrdup ((*ent)->mt_directory);
+ me->me_mntroot = NULL;
me->me_type = xstrdup ((*ent)->mt_fstype);
me->me_type_malloced = 1;
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -942,6 +957,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (mnt.mnt_special);
me->me_mountdir = xstrdup (mnt.mnt_mountp);
+ me->me_mntroot = NULL;
me->me_type = xstrdup (mnt.mnt_fstype);
me->me_type_malloced = 1;
me->me_dummy = MNT_IGNORE (&mnt) != 0;
@@ -1020,6 +1036,7 @@ read_file_system_list (bool need_fs_type)
vmp->vmt_data[VMT_OBJECT].vmt_off);
}
me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
+ me->me_mntroot = NULL;
me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
me->me_type_malloced = 1;
options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
@@ -1063,6 +1080,7 @@ read_file_system_list (bool need_fs_type)
me = xmalloc (sizeof *me);
me->me_devname = xstrdup (dev.f_mntfromname);
me->me_mountdir = xstrdup (dev.f_mntonname);
+ me->me_mntroot = NULL;
me->me_type = xstrdup (dev.f_fstypename);
me->me_type_malloced = 1;
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -1105,6 +1123,7 @@ void free_mount_entry (struct mount_entry *me)
{
free (me->me_devname);
free (me->me_mountdir);
+ free (me->me_mntroot);
if (me->me_type_malloced)
free (me->me_type);
free (me);
diff --git a/lib/mountlist.h b/lib/mountlist.h
index 735776b..9ce3137 100644
--- a/lib/mountlist.h
+++ b/lib/mountlist.h
@@ -27,6 +27,8 @@ struct mount_entry
{
char *me_devname; /* Device node name, including "/dev/". */
char *me_mountdir; /* Mount point directory name. */
+ char *me_mntroot; /* Directory on filesystem of device used */
+ /* as root for the (bind) mount. */
char *me_type; /* "nfs", "4.2", etc. */
dev_t me_dev; /* Device number of me_mountdir. */
unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */
--
2.5.5
From aff5e38d43f8477ccf07eb9e87a849b6c3211302 Mon Sep 17 00:00:00 2001
From: Dave Chiluk <chiluk@canonical.com>
Date: Mon, 21 Sep 2015 15:04:11 -0500
Subject: [PATCH 2/2] df: prioritize mounts nearer the device root
In the presence of bind mounts of a device, the 4th "mount root" field
from /proc/self/mountinfo is now considered, so as to prefer mount
points closer to the root of the device. Note on older systems with
an /etc/mtab file, the source device was listed as the originating
directory, and so this was not an issue.
Details at http://pad.lv/1432871
* src/df.c (filter_mount_list): When deduplicating mount entries,
only prefer sources nearer or at the root of the device, when the
target is nearer the root of the device.
* NEWS: Mention the change in behavior.
Upstream-commit: 3babaf83875ceac896c8dd3a64248e955dfecef9
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/df.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/df.c b/src/df.c
index 0dfd554..e390298 100644
--- a/src/df.c
+++ b/src/df.c
@@ -649,6 +649,13 @@ filter_mount_list (bool devices_only)
if (devlist)
{
+ bool target_nearer_root = strlen (devlist->me->me_mountdir)
+ > strlen (me->me_mountdir);
+ /* With bind mounts, prefer items nearer the root of the source */
+ bool source_below_root = devlist->me->me_mntroot != NULL
+ && me->me_mntroot != NULL
+ && (strlen (devlist->me->me_mntroot)
+ < strlen (me->me_mntroot));
if (! print_grand_total && me->me_remote && devlist->me->me_remote
&& ! STREQ (devlist->me->me_devname, me->me_devname))
{
@@ -660,9 +667,8 @@ filter_mount_list (bool devices_only)
else if ((strchr (me->me_devname, '/')
/* let "real" devices with '/' in the name win. */
&& ! strchr (devlist->me->me_devname, '/'))
- /* let a shorter mountdir win. */
- || (strlen (devlist->me->me_mountdir)
- > strlen (me->me_mountdir))
+ /* let points towards the root of the device win. */
+ || (target_nearer_root && ! source_below_root)
/* let an entry overmounted on a new device win... */
|| (! STREQ (devlist->me->me_devname, me->me_devname)
/* ... but only when matching an existing mnt point,
--
2.5.5

View File

@ -0,0 +1,119 @@
@@ -, +, @@
destination
mv dir dir dir
---
src/copy.c | 12 +++++++----
tests/local.mk | 1 -
tests/mv/dup-source.sh | 46 +++++++++++++++++++++++++++++++++----------
3 files changed, 44 insertions(+), 15 deletions(-)
--- a/src/copy.c
+++ a/src/copy.c
@@ -2278,10 +2278,14 @@ copy_internal (char const *src_name, char const *dst_name,
error (0, 0, _("warning: source directory %s "
"specified more than once"),
quote (top_level_src_name));
- /* We only do backups in move mode and for non dirs,
- and in move mode this won't be the issue as the source will
- be missing for subsequent attempts.
- There we just warn and return here. */
+ /* In move mode, if a previous rename succeeded, then
+ we won't be in this path as the source is missing. If the
+ rename previously failed, then that has been handled.
+ Pretend this instance succeeded so the source isn't removed. */
+ if (x->move_mode && rename_succeeded)
+ *rename_succeeded = true;
+ /* We only do backups in move mode, and for non directories.
+ So just ignore this repeated entry. */
return true;
}
else if (x->dereference == DEREF_ALWAYS
--- a/tests/local.mk
+++ a/tests/local.mk
@@ -443,7 +443,6 @@ all_tests = \
tests/cp/dir-rm-dest.sh \
tests/cp/dir-slash.sh \
tests/cp/dir-vs-file.sh \
- tests/cp/duplicate-sources.sh \
tests/cp/existing-perm-dir.sh \
tests/cp/existing-perm-race.sh \
tests/cp/fail-perm.sh \
--- a/tests/mv/dup-source.sh
+++ a/tests/mv/dup-source.sh
@@ -24,25 +24,37 @@ print_ver_ cp mv
skip_if_root_
+reset_files() { rm -fr a b d; touch a; mkdir b d; }
+
for i in cp; do
# cp may not fail in this case.
-
- rm -fr a d; touch a; mkdir d
+ reset_files
$i a a d/ 2> out || fail=1
- rm -fr a d; touch a; mkdir d
+ reset_files
$i ./a a d/ 2>> out || fail=1
+ # Similarly for directories, but handle
+ # source == dest appropriately.
+ reset_files
+ $i -a ./b b d/ 2>> out || fail=1
+ reset_files
+ returns_ 1 $i -a ./b b b/ 2>> out || fail=1
+
# cp succeeds with --backup=numbered.
- rm -fr a d; touch a; mkdir d
+ reset_files
$i --backup=numbered a a d/ 2>> out || fail=1
# But not with plain '--backup'
- rm -fr a d; touch a; mkdir d
- $i --backup a a d/ 2>> out && fail=1
+ reset_files
+ returns_ 1 $i --backup a a d/ 2>> out || fail=1
+
cat <<EOF > exp
$i: warning: source file 'a' specified more than once
$i: warning: source file 'a' specified more than once
+$i: warning: source directory 'b' specified more than once
+$i: cannot copy a directory, './b', into itself, 'b/b'
+$i: warning: source directory 'b' specified more than once
$i: will not overwrite just-created 'd/a' with 'a'
EOF
compare exp out || fail=1
@@ -50,14 +62,28 @@ done
for i in mv; do
# But mv *does* fail in this case (it has to).
+ reset_files
+ returns_ 1 $i a a d/ 2> out || fail=1
+ returns_ 1 test -e a || fail=1
+ reset_files
+ returns_ 1 $i ./a a d/ 2>> out || fail=1
+ returns_ 1 test -e a || fail=1
+
+ # Similarly for directories, also handling
+ # source == dest appropriately.
+ reset_files
+ returns_ 1 $i ./b b d/ 2>> out || fail=1
+ returns_ 1 test -e b || fail=1
+ reset_files
+ returns_ 1 $i --verbose ./b b b/ 2>> out || fail=1
+ test -d b || fail=1
- rm -fr a d; touch a; mkdir d
- $i a a d/ 2> out && fail=1
- rm -fr a d; touch a; mkdir d
- $i ./a a d/ 2>> out && fail=1
cat <<EOF > exp
$i: cannot stat 'a': No such file or directory
$i: cannot stat 'a': No such file or directory
+$i: cannot stat 'b': No such file or directory
+$i: cannot move './b' to a subdirectory of itself, 'b/b'
+$i: warning: source directory 'b' specified more than once
EOF
compare exp out || fail=1
done
--

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
From lkundrak@v3.sk Thu Jan 28 20:57:48 2016
Return-Path: lkundrak@v3.sk
Received: from zimbra.v3.sk (LHLO zimbra.v3.sk) (10.13.37.31) by
zimbra.v3.sk with LMTP; Thu, 28 Jan 2016 20:57:48 +0100 (CET)
Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix)
with ESMTP id D4DD260F92 for <lkundrak@v3.sk>; Thu, 28 Jan 2016 20:57:47
+0100 (CET)
X-Spam-Flag: NO
X-Spam-Score: -2.9
X-Spam-Level:
X-Spam-Status: No, score=-2.9 tagged_above=-10 required=3
tests=[ALL_TRUSTED=-1, BAYES_00=-1.9] autolearn=ham autolearn_force=no
Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk
[127.0.0.1]) (amavisd-new, port 10032) with ESMTP id HB5H5ynfOcyL; Thu, 28
Jan 2016 20:57:45 +0100 (CET)
Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix)
with ESMTP id 3FEF160F90; Thu, 28 Jan 2016 20:57:45 +0100 (CET)
X-Virus-Scanned: amavisd-new at zimbra.v3.sk
Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk
[127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TUF9p5l6r9SN; Thu, 28
Jan 2016 20:57:44 +0100 (CET)
Received: from odvarok.localdomain (s559633cb.adsl.online.nl
[85.150.51.203]) by zimbra.v3.sk (Postfix) with ESMTPSA id 6763560F8F; Thu,
28 Jan 2016 20:57:44 +0100 (CET)
From: Lubomir Rintel <lkundrak@v3.sk>
To: =?UTF-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <ovasik@redhat.com>, Ondrej
Oprala <ooprala@redhat.com>
Cc: Lubomir Rintel <lkundrak@v3.sk>
Subject: [PATCH] unexpand: fix blank line handling
Date: Thu, 28 Jan 2016 20:57:22 +0100
Message-Id: <1454011042-30492-1-git-send-email-lkundrak@v3.sk>
X-Mailer: git-send-email 2.5.0
X-Evolution-Source: 1409576065.5421.4@dhcp-24-163.brq.redhat.com
Content-Transfer-Encoding: 8bit
Mime-Version: 1.0
echo '' |./src/unexpand -a
Really?
---
src/unexpand.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/unexpand.c b/src/unexpand.c
index d6ff662..762c56b 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -304,7 +304,7 @@ unexpand (void)
next_tab_column = column;
tab_index -= !!tab_index;
}
- else
+ else if (!mb_iseq (c, '\n'))
{
column += mb_width (c);
if (!column)
--
2.5.0

View File

@ -0,0 +1,104 @@
diff -up ./src/expand.c.orig ./src/expand.c
--- ./src/expand.c.orig 2016-06-01 12:42:49.330373488 +0200
+++ ./src/expand.c 2016-06-07 14:35:16.011142041 +0200
@@ -173,15 +173,19 @@ expand (void)
do
{
- do {
+ while (true) {
mbf_getc (c, mbf);
- if (mb_iseof (c))
+ if ((mb_iseof (c)) && (fp = next_file (fp)))
{
- mbf_init (mbf, fp = next_file (fp));
+ mbf_init (mbf, fp);
continue;
}
+ else
+ {
+ break;
+ }
}
- while (false);
+
if (convert)
{
diff -up ./src/unexpand.c.orig ./src/unexpand.c
--- ./src/unexpand.c.orig 2016-06-07 14:26:57.380746446 +0200
+++ ./src/unexpand.c 2016-06-07 14:34:54.059256698 +0200
@@ -220,15 +220,19 @@ unexpand (void)
do
{
- do {
+ while (true) {
mbf_getc (c, mbf);
- if (mb_iseof (c))
+ if ((mb_iseof (c)) && (fp = next_file (fp)))
{
- mbf_init (mbf, fp = next_file (fp));
+ mbf_init (mbf, fp);
continue;
}
+ else
+ {
+ break;
+ }
}
- while (false);
+
if (convert)
{
diff -up ./tests/expand/mb.sh.orig ./tests/expand/mb.sh
--- ./tests/expand/mb.sh.orig 2016-05-11 14:13:53.095289000 +0200
+++ ./tests/expand/mb.sh 2016-06-07 14:38:48.259033445 +0200
@@ -44,6 +44,20 @@ EOF
expand < in > out || fail=1
compare exp out > /dev/null 2>&1 || fail=1
+#multiple files as an input
+cat <<\EOF >> exp || framework_failure_
+1234567812345678123456781
+. . . .
+a b c d
+. . . .
+ä ö ü ß
+. . . .
+ äöü . öüä. ä xx
+EOF
+
+expand ./in ./in > out || fail=1
+compare exp out > /dev/null 2>&1 || fail=1
+
#test characters with display widths != 1
env printf '12345678
e\t|ascii(1)
diff -up ./tests/unexpand/mb.sh.orig ./tests/unexpand/mb.sh
--- ./tests/unexpand/mb.sh.orig 2016-06-07 14:41:44.210106466 +0200
+++ ./tests/unexpand/mb.sh 2016-06-07 14:52:28.848639772 +0200
@@ -44,6 +44,22 @@ EOF
unexpand -a < in > out || fail=1
compare exp out > /dev/null 2>&1 || fail=1
+
+#multiple files as an input
+cat >> exp <<\EOF
+1234567812345678123456781
+. . . .
+a b c d
+. . . .
+ä ö ü ß
+. . . .
+ äöü . öüä. ä xx
+EOF
+
+
+unexpand -a ./in ./in > out || fail=1
+compare exp out > /dev/null 2>&1 || fail=1
+
#test characters with a display width larger than 1
env printf '12345678

View File

@ -596,201 +596,6 @@ diff -urNp coreutils-8.24-orig/src/cut.c coreutils-8.24/src/cut.c
}
if (optind == argc)
diff -urNp coreutils-8.24-orig/src/expand.c coreutils-8.24/src/expand.c
--- coreutils-8.24-orig/src/expand.c 2015-06-26 19:05:22.000000000 +0200
+++ coreutils-8.24/src/expand.c 2015-07-05 09:04:33.028546950 +0200
@@ -37,12 +37,34 @@
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+
+/* Get mbstate_t, mbrtowc(), wcwidth(). */
+#if HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+
+/* Get iswblank(). */
+#if HAVE_WCTYPE_H
+# include <wctype.h>
+#endif
+
#include "system.h"
#include "error.h"
#include "fadvise.h"
#include "quote.h"
#include "xstrndup.h"
+/* MB_LEN_MAX is incorrectly defined to be 1 in at least one GCC
+ installation; work around this configuration error. */
+#if !defined MB_LEN_MAX || MB_LEN_MAX < 2
+# define MB_LEN_MAX 16
+#endif
+
+/* Some systems, like BeOS, have multibyte encodings but lack mbstate_t. */
+#if HAVE_MBRTOWC && defined mbstate_t
+# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0)
+#endif
+
/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "expand"
@@ -357,6 +379,142 @@ expand (void)
}
}
+#if HAVE_MBRTOWC
+static void
+expand_multibyte (void)
+{
+ FILE *fp; /* Input strem. */
+ mbstate_t i_state; /* Current shift state of the input stream. */
+ mbstate_t i_state_bak; /* Back up the I_STATE. */
+ mbstate_t o_state; /* Current shift state of the output stream. */
+ char buf[MB_LEN_MAX + BUFSIZ]; /* For spooling a read byte sequence. */
+ char *bufpos = buf; /* Next read position of BUF. */
+ size_t buflen = 0; /* The length of the byte sequence in buf. */
+ wchar_t wc; /* A gotten wide character. */
+ size_t mblength; /* The byte size of a multibyte character
+ which shows as same character as WC. */
+ int tab_index = 0; /* Index in `tab_list' of next tabstop. */
+ int column = 0; /* Column on screen of the next char. */
+ int next_tab_column; /* Column the next tab stop is on. */
+ int convert = 1; /* If nonzero, perform translations. */
+
+ fp = next_file ((FILE *) NULL);
+ if (fp == NULL)
+ return;
+
+ memset (&o_state, '\0', sizeof(mbstate_t));
+ memset (&i_state, '\0', sizeof(mbstate_t));
+
+ for (;;)
+ {
+ /* Refill the buffer BUF. */
+ if (buflen < MB_LEN_MAX && !feof(fp) && !ferror(fp))
+ {
+ memmove (buf, bufpos, buflen);
+ buflen += fread (buf + buflen, sizeof(char), BUFSIZ, fp);
+ bufpos = buf;
+ }
+
+ /* No character is left in BUF. */
+ if (buflen < 1)
+ {
+ fp = next_file (fp);
+
+ if (fp == NULL)
+ break; /* No more files. */
+ else
+ {
+ memset (&i_state, '\0', sizeof(mbstate_t));
+ continue;
+ }
+ }
+
+ /* Get a wide character. */
+ i_state_bak = i_state;
+ mblength = mbrtowc (&wc, bufpos, buflen, &i_state);
+
+ switch (mblength)
+ {
+ case (size_t)-1: /* illegal byte sequence. */
+ case (size_t)-2:
+ mblength = 1;
+ i_state = i_state_bak;
+ if (convert)
+ {
+ ++column;
+ if (convert_entire_line == 0 && !isblank(*bufpos))
+ convert = 0;
+ }
+ putchar (*bufpos);
+ break;
+
+ case 0: /* null. */
+ mblength = 1;
+ if (convert && convert_entire_line == 0)
+ convert = 0;
+ putchar ('\0');
+ break;
+
+ default:
+ if (wc == L'\n') /* LF. */
+ {
+ tab_index = 0;
+ column = 0;
+ convert = 1;
+ putchar ('\n');
+ }
+ else if (wc == L'\t' && convert) /* Tab. */
+ {
+ if (tab_size == 0)
+ {
+ /* Do not let tab_index == first_free_tab;
+ stop when it is 1 less. */
+ while (tab_index < first_free_tab - 1
+ && column >= tab_list[tab_index])
+ tab_index++;
+ next_tab_column = tab_list[tab_index];
+ if (tab_index < first_free_tab - 1)
+ tab_index++;
+ if (column >= next_tab_column)
+ next_tab_column = column + 1;
+ }
+ else
+ next_tab_column = column + tab_size - column % tab_size;
+
+ while (column < next_tab_column)
+ {
+ putchar (' ');
+ ++column;
+ }
+ }
+ else /* Others. */
+ {
+ if (convert)
+ {
+ if (wc == L'\b')
+ {
+ if (column > 0)
+ --column;
+ }
+ else
+ {
+ int width; /* The width of WC. */
+
+ width = wcwidth (wc);
+ column += (width > 0) ? width : 0;
+ if (convert_entire_line == 0 && !iswblank(wc))
+ convert = 0;
+ }
+ }
+ fwrite (bufpos, sizeof(char), mblength, stdout);
+ }
+ }
+ buflen -= mblength;
+ bufpos += mblength;
+ }
+}
+#endif
+
int
main (int argc, char **argv)
{
@@ -421,7 +579,12 @@ main (int argc, char **argv)
file_list = (optind < argc ? &argv[optind] : stdin_argv);
- expand ();
+#if HAVE_MBRTOWC
+ if (MB_CUR_MAX > 1)
+ expand_multibyte ();
+ else
+#endif
+ expand ();
if (have_read_stdin && fclose (stdin) != 0)
error (EXIT_FAILURE, errno, "-");
diff -urNp coreutils-8.24-orig/src/fold.c coreutils-8.24/src/fold.c
--- coreutils-8.24-orig/src/fold.c 2015-06-26 19:05:22.000000000 +0200
+++ coreutils-8.24/src/fold.c 2015-07-05 09:04:33.029546958 +0200
@ -3480,264 +3285,6 @@ diff -urNp coreutils-8.24-orig/src/sort.c coreutils-8.24/src/sort.c
if (have_read_stdin && fclose (stdin) == EOF)
die (_("close failed"), "-");
diff -urNp coreutils-8.24-orig/src/unexpand.c coreutils-8.24/src/unexpand.c
--- coreutils-8.24-orig/src/unexpand.c 2015-06-26 19:05:22.000000000 +0200
+++ coreutils-8.24/src/unexpand.c 2015-07-05 09:04:33.032546980 +0200
@@ -38,12 +38,29 @@
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+
+/* Get mbstate_t, mbrtowc(), wcwidth(). */
+#if HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+
#include "system.h"
#include "error.h"
#include "fadvise.h"
#include "quote.h"
#include "xstrndup.h"
+/* MB_LEN_MAX is incorrectly defined to be 1 in at least one GCC
+ installation; work around this configuration error. */
+#if !defined MB_LEN_MAX || MB_LEN_MAX < 2
+# define MB_LEN_MAX 16
+#endif
+
+/* Some systems, like BeOS, have multibyte encodings but lack mbstate_t. */
+#if HAVE_MBRTOWC && defined mbstate_t
+# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0)
+#endif
+
/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "unexpand"
@@ -103,6 +120,210 @@ static struct option const longopts[] =
{NULL, 0, NULL, 0}
};
+static FILE *next_file (FILE *fp);
+
+#if HAVE_MBRTOWC
+static void
+unexpand_multibyte (void)
+{
+ FILE *fp; /* Input stream. */
+ mbstate_t i_state; /* Current shift state of the input stream. */
+ mbstate_t i_state_bak; /* Back up the I_STATE. */
+ mbstate_t o_state; /* Current shift state of the output stream. */
+ char buf[MB_LEN_MAX + BUFSIZ]; /* For spooling a read byte sequence. */
+ char *bufpos = buf; /* Next read position of BUF. */
+ size_t buflen = 0; /* The length of the byte sequence in buf. */
+ wint_t wc; /* A gotten wide character. */
+ size_t mblength; /* The byte size of a multibyte character
+ which shows as same character as WC. */
+ bool prev_tab = false;
+
+ /* Index in `tab_list' of next tabstop: */
+ int tab_index = 0; /* For calculating width of pending tabs. */
+ int print_tab_index = 0; /* For printing as many tabs as possible. */
+ unsigned int column = 0; /* Column on screen of next char. */
+ int next_tab_column; /* Column the next tab stop is on. */
+ int convert = 1; /* If nonzero, perform translations. */
+ unsigned int pending = 0; /* Pending columns of blanks. */
+
+ fp = next_file ((FILE *) NULL);
+ if (fp == NULL)
+ return;
+
+ memset (&o_state, '\0', sizeof(mbstate_t));
+ memset (&i_state, '\0', sizeof(mbstate_t));
+
+ for (;;)
+ {
+ if (buflen < MB_LEN_MAX && !feof(fp) && !ferror(fp))
+ {
+ memmove (buf, bufpos, buflen);
+ buflen += fread (buf + buflen, sizeof(char), BUFSIZ, fp);
+ bufpos = buf;
+ }
+
+ /* Get a wide character. */
+ if (buflen < 1)
+ {
+ mblength = 1;
+ wc = WEOF;
+ }
+ else
+ {
+ i_state_bak = i_state;
+ mblength = mbrtowc ((wchar_t *)&wc, bufpos, buflen, &i_state);
+ }
+
+ if (mblength == (size_t)-1 || mblength == (size_t)-2)
+ {
+ i_state = i_state_bak;
+ wc = L'\0';
+ }
+
+ if (wc == L' ' && convert && column < INT_MAX)
+ {
+ ++pending;
+ ++column;
+ }
+ else if (wc == L'\t' && convert)
+ {
+ if (tab_size == 0)
+ {
+ /* Do not let tab_index == first_free_tab;
+ stop when it is 1 less. */
+ while (tab_index < first_free_tab - 1
+ && column >= tab_list[tab_index])
+ tab_index++;
+ next_tab_column = tab_list[tab_index];
+ if (tab_index < first_free_tab - 1)
+ tab_index++;
+ if (column >= next_tab_column)
+ {
+ convert = 0; /* Ran out of tab stops. */
+ goto flush_pend_mb;
+ }
+ }
+ else
+ {
+ next_tab_column = column + tab_size - column % tab_size;
+ }
+ pending += next_tab_column - column;
+ column = next_tab_column;
+ }
+ else
+ {
+flush_pend_mb:
+ /* Flush pending spaces. Print as many tabs as possible,
+ then print the rest as spaces. */
+ if (pending == 1 && column != 1 && !prev_tab)
+ {
+ putchar (' ');
+ pending = 0;
+ }
+ column -= pending;
+ while (pending > 0)
+ {
+ if (tab_size == 0)
+ {
+ /* Do not let print_tab_index == first_free_tab;
+ stop when it is 1 less. */
+ while (print_tab_index < first_free_tab - 1
+ && column >= tab_list[print_tab_index])
+ print_tab_index++;
+ next_tab_column = tab_list[print_tab_index];
+ if (print_tab_index < first_free_tab - 1)
+ print_tab_index++;
+ }
+ else
+ {
+ next_tab_column =
+ column + tab_size - column % tab_size;
+ }
+ if (next_tab_column - column <= pending)
+ {
+ putchar ('\t');
+ pending -= next_tab_column - column;
+ column = next_tab_column;
+ }
+ else
+ {
+ --print_tab_index;
+ column += pending;
+ while (pending != 0)
+ {
+ putchar (' ');
+ pending--;
+ }
+ }
+ }
+
+ if (wc == WEOF)
+ {
+ fp = next_file (fp);
+ if (fp == NULL)
+ break; /* No more files. */
+ else
+ {
+ memset (&i_state, '\0', sizeof(mbstate_t));
+ continue;
+ }
+ }
+
+ if (mblength == (size_t)-1 || mblength == (size_t)-2)
+ {
+ if (convert)
+ {
+ ++column;
+ if (convert_entire_line == 0)
+ convert = 0;
+ }
+ mblength = 1;
+ putchar (buf[0]);
+ }
+ else if (mblength == 0)
+ {
+ if (convert && convert_entire_line == 0)
+ convert = 0;
+ mblength = 1;
+ putchar ('\0');
+ }
+ else
+ {
+ if (convert)
+ {
+ if (wc == L'\b')
+ {
+ if (column > 0)
+ --column;
+ }
+ else
+ {
+ int width; /* The width of WC. */
+
+ width = wcwidth (wc);
+ column += (width > 0) ? width : 0;
+ if (convert_entire_line == 0)
+ convert = 0;
+ }
+ }
+
+ if (wc == L'\n')
+ {
+ tab_index = print_tab_index = 0;
+ column = pending = 0;
+ convert = 1;
+ }
+ fwrite (bufpos, sizeof(char), mblength, stdout);
+ }
+ }
+ prev_tab = wc == L'\t';
+ buflen -= mblength;
+ bufpos += mblength;
+ }
+}
+#endif
+
+
void
usage (int status)
{
@@ -523,7 +744,12 @@ main (int argc, char **argv)
file_list = (optind < argc ? &argv[optind] : stdin_argv);
- unexpand ();
+#if HAVE_MBRTOWC
+ if (MB_CUR_MAX > 1)
+ unexpand_multibyte ();
+ else
+#endif
+ unexpand ();
if (have_read_stdin && fclose (stdin) != 0)
error (EXIT_FAILURE, errno, "-");
diff -urNp coreutils-8.24-orig/src/uniq.c coreutils-8.24/src/uniq.c
--- coreutils-8.24-orig/src/uniq.c 2015-06-26 19:04:19.000000000 +0200
+++ coreutils-8.24/src/uniq.c 2015-07-05 09:04:33.032546980 +0200

View File

@ -1,7 +1,7 @@
Summary: A set of basic GNU tools commonly used in shell scripts
Name: coreutils
Version: 8.24
Release: 4%{?dist}
Release: 8%{?dist}
License: GPLv3+
Group: System Environment/Base
Url: http://www.gnu.org/software/coreutils/
@ -14,6 +14,11 @@ Source105: coreutils-colorls.sh
Source106: coreutils-colorls.csh
# From upstream
#mv: prevent dataloss when source directory is specified multiple t imes
Patch1: coreutils-8.24-mv-duplicate-sources.patch
# df: prioritize mounts nearer the device root (#1001092)
Patch2: coreutils-8.24-df-bind-mount.patch
# Our patches
#general patch to workaround koji build system issues
@ -40,6 +45,12 @@ Patch713: coreutils-4.5.3-langinfo.patch
# (sb) lin18nux/lsb compliance - multibyte functionality patch
Patch800: coreutils-i18n.patch
# (sb) lin18nux/lsb compliance - expand/unexpand
Patch801: coreutils-i18n-expand-unexpand.patch
# The unexpand patch above is not correct. Sent to the patch authors
Patch803: coreutils-i18n-fix-unexpand.patch
#(un)expand - allow multiple files on input - broken by patch 801
Patch804: coreutils-i18n-fix2-expand-unexpand.patch
#getgrouplist() patch from Ulrich Drepper.
Patch908: coreutils-getgrouplist.patch
@ -142,11 +153,16 @@ the old GNU fileutils, sh-utils, and textutils packages.
# li18nux/lsb
%patch800 -p1 -b .i18n
%patch801 -p1 -b .i18n-expand
%patch803 -p1 -b .i18n-fix-expand
%patch804 -p1 -b .i18n-fix2-expand-unexpand
# Coreutils
%patch908 -p1 -b .getgrouplist
%patch912 -p1 -b .overflow
%patch913 -p1 -b .testoff
%patch1 -p1 -b .dupl
%patch2 -p1
#SELinux
%patch950 -p1 -b .selinux
@ -376,6 +392,21 @@ fi
%{_sbindir}/chroot
%changelog
* Tue Jul 12 2016 Jakub Martisko <jamartis@redhat.com> - 8.24-8
- (un)expand fix a regression in handling of input files, where only
the first file was procesed.
* Thu May 19 2016 Kamil Dudka <kdudka@redhat.com> - 8.24-7
- df: prioritize mounts nearer the device root (#1001092)
* Thu Feb 11 2016 Lubomir Rintel <lkundrak@v3.sk> - 8.24-6
- Fix a regression in unexpand empty line handling
* Wed Jan 13 2016 Ondrej Vasik <ovasik@redhat.com> - 8.24-5
- mv: prevent dataloss when source dir is specified multiple
times (#1297464, by P.Brady)
- Use the new i18n implementation for expand/unexpand
* Wed Sep 16 2015 Kamil Dudka <kdudka@redhat.com> - 8.24-4
- fix memory leak in sort/I18N (patches written by Pádraig, #1259942)