diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/find/find.c | 6 | ||||
-rw-r--r-- | usr/src/man/man1/find.1 | 20 | ||||
-rw-r--r-- | usr/src/pkg/manifests/system-test-utiltest.mf | 2 | ||||
-rw-r--r-- | usr/src/test/util-tests/tests/Makefile | 2 | ||||
-rw-r--r-- | usr/src/test/util-tests/tests/find/Makefile | 41 | ||||
-rw-r--r-- | usr/src/test/util-tests/tests/find/findtest.ksh | 72 |
6 files changed, 125 insertions, 18 deletions
diff --git a/usr/src/cmd/find/find.c b/usr/src/cmd/find/find.c index 5b5811ea6a..8860e9b711 100644 --- a/usr/src/cmd/find/find.c +++ b/usr/src/cmd/find/find.c @@ -22,6 +22,7 @@ * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2012 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2013 Andrew Stormont. All rights reserved. + * Copyright 2020 Joyent, Inc. */ @@ -1027,9 +1028,12 @@ execute(const char *name, const struct stat *statb, int type, struct FTW *state) * /usr/bin/find will not pattern match a leading * '.' in a filename, unless '.' is explicitly * specified. + * + * The legacy behavior makes no sense for PATH. */ #ifndef XPG4 - fnmflags |= FNM_PERIOD; + if (np->action == NAME || np->action == INAME) + fnmflags |= FNM_PERIOD; #endif val = !fnmatch(np->first.cp, diff --git a/usr/src/man/man1/find.1 b/usr/src/man/man1/find.1 index 47f3870d12..d393a3197d 100644 --- a/usr/src/man/man1/find.1 +++ b/usr/src/man/man1/find.1 @@ -45,12 +45,12 @@ .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved .\" Copyright 2011 Nexenta Systems, Inc. All rights reserved. .\" Copyright (c) 2013 Andrew Stormont. All rights reserved. +.\" Copyright 2020 Joyent, Inc. .\" -.TH FIND 1 "Sep 5, 2011" +.TH FIND 1 "Feb 20, 2020" .SH NAME find \- find files .SH SYNOPSIS -.LP .nf \fB/usr/bin/find\fR [\fB-E\fR] [\fB-H\fR | \fB-L\fR] \fIpath\fR... \fIexpression\fR .fi @@ -61,7 +61,6 @@ find \- find files .fi .SH DESCRIPTION -.LP The \fBfind\fR utility recursively descends the directory hierarchy for each \fIpath\fR seeking files that match a Boolean \fIexpression\fR written in the primaries specified below. @@ -75,7 +74,6 @@ by the application exceeds \fIPATH_MAX\fR requirements). \fBfind\fR detects infinite loops; that is, entering a previously visited directory that is an ancestor of the last file encountered. .SH OPTIONS -.LP The following options are supported: .sp .ne 2 @@ -117,7 +115,6 @@ Specifying more than one of the mutually-exclusive options \fB-H\fR and \fB-L\fR is not considered an error. The last option specified determines the behavior of the utility. .SH OPERANDS -.LP The following operands are supported: .sp .ne 2 @@ -169,7 +166,6 @@ less than \fIn\fR .RE .SS "Expressions" -.LP Valid expressions are: .sp .ne 2 @@ -549,7 +545,8 @@ question mark first, and is executed only if the response is affirmative. \fB\fB-path\fR\fR .ad .RS 17n -Like \fB-name\fR, but matches the entire file path and not just basename. +Like \fB-name\fR, but matches the entire file path and not just basename, and +without any special treatment of leading periods. .RE .sp @@ -717,7 +714,6 @@ True if the file has extended attributes. .RE .SS "Complex Expressions" -.LP The primaries can be combined using the following operators (in order of decreasing precedence): .sp @@ -783,11 +779,9 @@ The \fB-user\fR, \fB-group\fR, and \fB-newer\fR primaries each evaluate their respective arguments only once. Invocation of \fIcommand\fR specified by \fB-exec\fR or \fB-ok\fR does not affect subsequent primaries on the same file. .SH USAGE -.LP See \fBlargefile\fR(5) for the description of the behavior of \fBfind\fR when encountering files greater than or equal to 2 Gbyte (2^31 bytes). .SH EXAMPLES -.LP \fBExample 1 \fRWriting Out the Hierarchy Directory .sp .LP @@ -957,7 +951,6 @@ example% \fBfind . -xattr\fR .sp .SH ENVIRONMENT VARIABLES -.LP See \fBenviron\fR(5) for descriptions of the following environment variables that affect the execution of \fBfind\fR: \fBLANG\fR, \fBLC_ALL\fR, \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR. @@ -982,7 +975,6 @@ in \fBLC_CTYPE\fR determines the locale for interpretation of sequences of bytes of text data a characters, the behavior of character classes used in the expression defined for the \fByesexpr\fR. See \fBlocale\fR(5). .SH EXIT STATUS -.LP The following exit values are returned: .sp .ne 2 @@ -1030,7 +1022,6 @@ File that registers distributed file system packages .RE .SH ATTRIBUTES -.LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -1049,13 +1040,11 @@ Standard See \fBstandards\fR(5). .TE .SH SEE ALSO -.LP \fBchmod\fR(1), \fBcpio\fR(1), \fBsh\fR(1), \fBtest\fR(1), \fBls\fR(1B), \fBacl\fR(5), \fBregex\fR(5), \fBstat\fR(2), \fBumask\fR(2), \fBattributes\fR(5), \fBenviron\fR(5), \fBfsattr\fR(5), \fBlargefile\fR(5), \fBlocale\fR(5), \fBstandards\fR(5) .SH WARNINGS -.LP The following options are obsolete and will not be supported in future releases: .sp @@ -1079,7 +1068,6 @@ format (5120-byte records). .RE .SH NOTES -.LP When using \fBfind\fR to determine files modified within a range of time, use the \fB-mtime\fR argument \fBbefore\fR the \fB-print\fR argument. Otherwise, \fBfind\fR gives all files. diff --git a/usr/src/pkg/manifests/system-test-utiltest.mf b/usr/src/pkg/manifests/system-test-utiltest.mf index 7ebc02a0b1..848daeac78 100644 --- a/usr/src/pkg/manifests/system-test-utiltest.mf +++ b/usr/src/pkg/manifests/system-test-utiltest.mf @@ -55,6 +55,7 @@ dir path=opt/util-tests/tests/files/make_a/a dir path=opt/util-tests/tests/files/make_a/b dir path=opt/util-tests/tests/files/make_a/c dir path=opt/util-tests/tests/files/make_l +dir path=opt/util-tests/tests/find dir path=opt/util-tests/tests/libcustr dir path=opt/util-tests/tests/libnvpair_json dir path=opt/util-tests/tests/libsff @@ -1421,6 +1422,7 @@ file path=opt/util-tests/tests/files/test5 mode=0444 file path=opt/util-tests/tests/files/test6 mode=0444 file path=opt/util-tests/tests/files/test7 mode=0444 file path=opt/util-tests/tests/files/testnl mode=0444 +file path=opt/util-tests/tests/find/findtest mode=0555 file path=opt/util-tests/tests/grep_test mode=0555 file path=opt/util-tests/tests/iconv_test mode=0555 file path=opt/util-tests/tests/libcustr/custr_remove mode=0555 diff --git a/usr/src/test/util-tests/tests/Makefile b/usr/src/test/util-tests/tests/Makefile index 35fd953518..6ccf391395 100644 --- a/usr/src/test/util-tests/tests/Makefile +++ b/usr/src/test/util-tests/tests/Makefile @@ -20,6 +20,6 @@ SUBDIRS = date dis dladm iconv libnvpair_json libsff printf xargs grep_xpg4 SUBDIRS += demangle mergeq workq chown ctf smbios libjedec awk make sleep -SUBDIRS += libcustr +SUBDIRS += libcustr find include $(SRC)/test/Makefile.com diff --git a/usr/src/test/util-tests/tests/find/Makefile b/usr/src/test/util-tests/tests/find/Makefile new file mode 100644 index 0000000000..66e2bab009 --- /dev/null +++ b/usr/src/test/util-tests/tests/find/Makefile @@ -0,0 +1,41 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2020 Joyent, Inc. +# + +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/test/Makefile.com + +ROOTOPTPKG = $(ROOT)/opt/util-tests/tests/find +PROG = findtest + +ROOTPROG = $(PROG:%=$(ROOTOPTPKG)/%) + +all: + +install: $(ROOTPROG) + +clobber: clean + +clean: + +$(CMDS): $(TESTDIR) + +$(ROOTOPTPKG): + $(INS.dir) + +$(ROOTOPTPKG)/%: %.ksh $(ROOTOPTPKG) + $(INS.rename) + +$(ROOTOPTPKG)/%: % $(ROOTOPTPKG) + $(INS.file) diff --git a/usr/src/test/util-tests/tests/find/findtest.ksh b/usr/src/test/util-tests/tests/find/findtest.ksh new file mode 100644 index 0000000000..9e321fb664 --- /dev/null +++ b/usr/src/test/util-tests/tests/find/findtest.ksh @@ -0,0 +1,72 @@ +#!/bin/ksh +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2020 Joyent, Inc. +# + +# +# Clearly, grossly incomplete. +# + +export LC_ALL=C.UTF-8 + +set -o pipefail +unalias -a + +find_prog=/usr/bin/find +find_prog_xpg4=/usr/xpg4/bin/find +find_dir="$(mktemp -d -p /tmp/)" +find_exit=0 + +testfind() +{ + exp=$1 + shift + cmd="$@" + + echo "TEST: $cmd" + + out=$(eval $cmd | tr '\n' ',') + + [[ "$exp" = "$out" ]] || { + echo "TEST FAILED: $cmd" >&2 + echo "expected: $exp" >&2 + echo "got: $out" >&2 + find_exit=1 + } +} + +mkdir -p $find_dir/1 +mkdir -p $find_dir/.2 +touch $find_dir/.2/1 +touch $find_dir/.2/c + +testfind "$find_dir/1,$find_dir/.2/1," \ + $find_prog $find_dir -name \"1\" +testfind "$find_dir/1,$find_dir/.2/1," \ + $find_prog $find_dir -path \"*1\" + +cd $find_dir + +testfind "" $find_prog . -name \"*2\" +testfind "./.2," $find_prog_xpg4 . -name \"*2\" +testfind "./.2," $find_prog . -name \".*2\" +testfind "./.2," $find_prog_xpg4 . -name \".*2\" +testfind "./1,./.2/1," $find_prog . -path \"*1\" +testfind "./.2," $find_prog . -path \"*2\" +testfind "./.2,./.2/1,./.2/c," $find_prog . -path \"*2*\" + +cd - +rm -rf $find_dir + +exit $find_exit |