From nobody Tue Jul 18 17:04:03 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R54zm0nXzz4nKJN; Tue, 18 Jul 2023 17:04:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R54zm0JDfz3nKk; Tue, 18 Jul 2023 17:04:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689699844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mQGbv65GJmk8xaxfPdc+OpJNkBGgK6TNxJAb5GJUVeA=; b=cTmie3NpbKFAyLYe9y3OkIUaesEep9HIY+CCraq212yRkr8dQ3eFr0XIP2cAYc3wg9FVDO bw4ZAC0SIq+jtN8qktUnamplYFQCoOn0Tz68K7bODQWi67WhURZP7vs0rYn1sFdLv2tSry 7uS1J97qS0FqBUEap3+OORArRaJXnnhjmG4ycT2IpNm82QAnTPDCKvwbF0y164vqfosDCw h6WPd/KlzYpsOAfIOGz+/LU1lmo7DVYZWhwm4JGBGo1kt74FhuLAp/nIaDId4fb23n2n7V tE6K6EaAi02Zuav0PkJW+eDaYD/qK3cO4pvDc7N8g1ZGYrzZgh0zFzLVor9jsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689699844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mQGbv65GJmk8xaxfPdc+OpJNkBGgK6TNxJAb5GJUVeA=; b=vubP5exbx/v6bQDZjvkNlY5efXPUGiFuTAFTd02ejl20mQaVdlLg4wWMmCnHlEuEX05M+n 8CnbiDDrRuhy5LwvVXfKRruE/296V8RGAWE+OTQLczJp/aDdBf5H6TQe0GNbrOzfA5JInq H7EVxykr6wq7iJg2J06N+Gzwt/Q0vHWZ3TCDCSfr2tXRdu58vGhCiBbSLadBQTZfRTrcnZ Gjh3/aF3jhGCPqosuXf6zAaQTx6eXClSco+tP1xvyo/uCuJT1JcrrvQMmhy3e1cpLnIZyn /mJFFmgfhAtQAEwdmwfJSu5AQ9k9QUMxzI5lr+r6dgMYaIKkhknUE+D1C5UFFw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689699844; a=rsa-sha256; cv=none; b=S+qoZQK6fB/zv15q6O0LSSSk6kM6C6BGgKhKy6tbMtJ+OjSMWvUHOKL5l1VR9B3RyDHAki uU2N+dT+sMDFpRg7320Eb0Abm7pYHDftKDLdL0W3hZLDqvHlL4dKfySrFhq8evLECWi035 stEkFu+MD6qWJCu51qb7S6rzVcDxwUuCVBhfLQvoqtBYM51EEQGJqN49//w/MqYasHWiJf U5ng0Kn95THligvF7DoCHAj8vO/dJVoWz25v2VijjwpS1od9HW7y1WagXnnXjawQUJ2xJz nTjtF0lumuxXtgb7vM+9a4CuwkNNhYTY0i/Wpw768R9pTYftwl57gt2TLFTxEg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4R54zl6BfVz1Ctg; Tue, 18 Jul 2023 17:04:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 36IH43Rk097909; Tue, 18 Jul 2023 17:04:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36IH43FZ097908; Tue, 18 Jul 2023 17:04:03 GMT (envelope-from git) Date: Tue, 18 Jul 2023 17:04:03 GMT Message-Id: <202307181704.36IH43FZ097908@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 3bfbb521fef5 - main - ls: Improve POSIX compatibility for -g and -n. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3bfbb521fef5764ecabc2bf3fdc76f47258171f8 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=3bfbb521fef5764ecabc2bf3fdc76f47258171f8 commit 3bfbb521fef5764ecabc2bf3fdc76f47258171f8 Author: Minsoo Choo AuthorDate: 2023-07-18 16:49:59 +0000 Commit: John Baldwin CommitDate: 2023-07-18 17:03:09 +0000 ls: Improve POSIX compatibility for -g and -n. - Change -g (ignored for BSD 4.3 compatibility since BSD 4.4) to use POSIX semantics of implying -l but omitting the owner's name. - Change -n to imply -l. The -o option remains unchanged (POSIX defines -o as a complement to -g that implies -l but omits group names whereas BSD defines -o to add file flags to -l). This compromise is the same used by both NetBSD and OpenBSD. PR: 70813 Reviewed by: jhb, Pau Amma Co-authored-by: John Baldwin Differential Revision: https://reviews.freebsd.org/D34747 --- bin/ls/ls.1 | 11 +++-------- bin/ls/ls.c | 10 +++++++++- bin/ls/ls.h | 1 + bin/ls/print.c | 8 +++++--- bin/ls/tests/ls_tests.sh | 19 ++++++++++--------- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/bin/ls/ls.1 b/bin/ls/ls.1 index fb1b4f6ba606..b3563eb38921 100644 --- a/bin/ls/ls.1 +++ b/bin/ls/ls.1 @@ -32,7 +32,7 @@ .\" @(#)ls.1 8.7 (Berkeley) 7/29/94 .\" $FreeBSD$ .\" -.Dd October 31, 2022 +.Dd July 18, 2023 .Dt LS 1 .Os .Sh NAME @@ -301,14 +301,9 @@ and .Fl s options. .It Fl g -This option has no effect. -It is only available for compatibility with -.Bx 4.3 , -where it was used to display the group name in the long +Display the long .Pq Fl l -format output. -This option is incompatible with -.St -p1003.1-2008 . +format output without the file owner's name or number. .It Fl h When used with the .Fl l diff --git a/bin/ls/ls.c b/bin/ls/ls.c index bd7bd283c317..b027e34afc2c 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -144,6 +144,7 @@ static int f_singlecol; /* use single column output */ static int f_sizesort; int f_slash; /* similar to f_type, but only for dirs */ int f_sortacross; /* sort across rows, not down columns */ + int f_sowner; /* disable showing owner's name */ int f_statustime; /* use time of last mode change */ static int f_stream; /* stream the output, separate with commas */ int f_thousands; /* show file sizes with thousands separators */ @@ -402,7 +403,11 @@ main(int argc, char *argv[]) f_listdir = 1; f_recursive = 0; break; - case 'g': /* Compatibility with 4.3BSD. */ + case 'g': + f_longform = 1; + f_singlecol = 0; + f_stream = 0; + f_sowner = 1; break; case 'h': f_humanval = 1; @@ -421,6 +426,9 @@ main(int argc, char *argv[]) break; case 'n': f_numericonly = 1; + f_longform = 1; + f_singlecol = 0; + f_stream = 0; break; case 'o': f_flags = 1; diff --git a/bin/ls/ls.h b/bin/ls/ls.h index 410246ec9903..1f19858720bf 100644 --- a/bin/ls/ls.h +++ b/bin/ls/ls.h @@ -56,6 +56,7 @@ extern int f_sectime; /* print the real time for all files */ extern int f_size; /* list size in short listing */ extern int f_slash; /* append a '/' if the file is a directory */ extern int f_sortacross; /* sort across rows, not down columns */ +extern int f_sowner; /* disable showing the owner's name */ extern int f_statustime; /* use time of last mode change */ extern int f_thousands; /* show file sizes with thousands separators */ extern char *f_timeformat; /* user-specified time format */ diff --git a/bin/ls/print.c b/bin/ls/print.c index 5e8a54ca0620..b01b2e1e61db 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -234,9 +234,11 @@ printlong(const DISPLAY *dp) strmode(sp->st_mode, buf); aclmode(buf, p); np = p->fts_pointer; - (void)printf("%s %*ju %-*s %-*s ", buf, dp->s_nlink, - (uintmax_t)sp->st_nlink, dp->s_user, np->user, dp->s_group, - np->group); + (void)printf("%s %*ju ", buf, dp->s_nlink, + (uintmax_t)sp->st_nlink); + if (!f_sowner) + (void)printf("%-*s ", dp->s_user, np->user); + (void)printf("%-*s ", dp->s_group, np->group); if (f_flags) (void)printf("%-*s ", dp->s_flags, np->flags); if (f_label) diff --git a/bin/ls/tests/ls_tests.sh b/bin/ls/tests/ls_tests.sh index 117156b5cb0e..a85e43ecb938 100755 --- a/bin/ls/tests/ls_tests.sh +++ b/bin/ls/tests/ls_tests.sh @@ -525,18 +525,19 @@ f_flag_body() atf_test_case g_flag g_flag_head() { - atf_set "descr" "Verify that -g does nothing (compatibility flag)" + atf_set "descr" "Verify that -g implies -l but omits the owner name field" } g_flag_body() { - create_test_inputs2 - for file in $files; do - atf_check -e empty -o match:"$(ls -a $file)" -s exit:0 \ - ls -ag $file - atf_check -e empty -o match:"$(ls -la $file)" -s exit:0 \ - ls -alg $file - done + atf_check -e empty -o empty -s exit:0 touch a.file + + mtime_in_secs=$(stat -f "%m" -t "%s" a.file) + mtime=$(date -j -f "%s" $mtime_in_secs +"%b[[:space:]]+%e[[:space:]]+%H:%M") + + expected_output=$(stat -f "%Sp[[:space:]]+%l[[:space:]]+%Sg[[:space:]]+%z[[:space:]]+$mtime[[:space:]]+a\\.file" a.file) + + atf_check -e empty -o match:"$expected_output" -s exit:0 ls -g a.file } atf_test_case h_flag @@ -689,7 +690,7 @@ n_flag_body() atf_check -e empty \ -o match:'\-rw\-r\-\-r\-\-[[:space:]]+1[[:space:]]+'"$nobody_uid[[:space:]]+$daemon_gid"'[[:space:]]+.+a\.file' \ - ls -ln a.file + ls -n a.file }