summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2012-03-14 13:42:59 -0600
committerEric Blake <eblake@redhat.com>2012-03-15 12:24:05 -0600
commit9f5aa4850133976eee22dcc0b506d7b632cd674c (patch)
tree868db0dba0e6b8dee1769deefe0417eae641571c
parent61167bae9f27269724dc577a19d2bd48a437bafb (diff)
downloadcoreutils-9f5aa4850133976eee22dcc0b506d7b632cd674c.tar.xz
realpath: let --relative-to default to --relative-base
Most of the time, if someone wants to filter which paths are relative while leaving all others absolute, they also want to to the filtering based on the same --relative-to directory. Make this easier to specify. * src/realpath.c (main): Convert error to default. * doc/coreutils.texi (realpath invocation): Document this. * tests/misc/realpath: Adjust test to match. * NEWS: Document it.
-rw-r--r--NEWS3
-rw-r--r--doc/coreutils.texi6
-rw-r--r--src/realpath.c5
-rwxr-xr-xtests/misc/realpath10
4 files changed, 14 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index e9b3d2056..5b53eb8a0 100644
--- a/NEWS
+++ b/NEWS
@@ -68,6 +68,9 @@ GNU coreutils NEWS -*- outline -*-
systems for which getfilecon-, ACL-check- and XATTR-check-induced syscalls
fail with ENOTSUP or similar.
+ 'realpath --relative-base=dir' in isolation now implies '--relative-to=dir'
+ instead of causing a usage failure.
+
split now supports an unlimited number of split files as default behavior.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 39c9bbf67..835c245d4 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -12904,14 +12904,16 @@ pertaining to file existence.
This option is valid when used with @option{--relative-to}, and will restrict
the output of @option{--relative-to} so that relative names are output,
only when @var{file}s are descendants of @var{base}. Otherwise output the
-absolute file name. Note: this option honors the @option{-m} and @option{-e}
+absolute file name. If @option{--relative-to} was not specified, then
+the descendants of @var{base} are printed relative to @var{base}.
+Note: this option honors the @option{-m} and @option{-e}
options pertaining to file existence. For example:
@example
realpath --relative-to=/usr /tmp /usr/bin
@result{} ../tmp
@result{} bin
-realpath --relative-base=/usr --relative-to=/usr /tmp /usr/bin
+realpath --relative-base=/usr /tmp /usr/bin
@result{} /tmp
@result{} bin
@end example
diff --git a/src/realpath.c b/src/realpath.c
index 19727641a..f95535b12 100644
--- a/src/realpath.c
+++ b/src/realpath.c
@@ -330,10 +330,7 @@ main (int argc, char **argv)
}
if (relative_base && !relative_to)
- {
- error (0, 0, _("--relative-base requires --relative-to"));
- usage (EXIT_FAILURE);
- }
+ relative_to = relative_base;
bool need_dir = (can_mode & CAN_MODE_MASK) == CAN_EXISTING;
if (relative_to)
diff --git a/tests/misc/realpath b/tests/misc/realpath
index 1b83a0496..9484ac4c8 100755
--- a/tests/misc/realpath
+++ b/tests/misc/realpath
@@ -43,11 +43,8 @@ ln -s /// three || framework_failure_
realpath -Pqz . >/dev/null || fail=1
# Operand is required
realpath >/dev/null && fail=1
-# --relative-base and --relative-to require params
realpath --relative-base . --relative-to . && fail=1
-# --relative-base requires --relative-to
-realpath --relative-base=dir1 . && fail=1
-realpath --relative-base --relative-to=dir1 . && fail=1
+realpath --relative-base . && fail=1
# -e --relative-* require directories
realpath -e --relative-to=dir1/f --relative-base=. . && fail=1
@@ -78,6 +75,11 @@ out=$(realpath -sm --relative-base=/usr --relative-to=/usr /tmp /usr) || fail=1
test "$out" = "/tmp$nl." || fail=1
out=$(realpath -sm --relative-base=/ --relative-to=/ / /usr) || fail=1
test "$out" = ".${nl}usr" || fail=1
+# --relative-to defaults to the value of --relative-base
+out=$(realpath -sm --relative-base=/usr /tmp /usr) || fail=1
+test "$out" = "/tmp$nl." || fail=1
+out=$(realpath -sm --relative-base=/ / /usr) || fail=1
+test "$out" = ".${nl}usr" || fail=1
# For now, --relative-base must be a prefix of --relative-to, or all output
# will be absolute (compare to MacOS 'relpath -d dir start end').
out=$(realpath -sm --relative-base=/usr/local --relative-to=/usr \