From: Masatake YAMATO Date: Fri, 13 Dec 2024 16:16:25 +0000 (+0900) Subject: lsfd: don't enable hyperlinks for deleted files X-Git-Tag: v2.42-start~111^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd00741c05a3d026975499412c0b5fb7243acb48;p=thirdparty%2Futil-linux.git lsfd: don't enable hyperlinks for deleted files Signed-off-by: Masatake YAMATO --- diff --git a/lsfd-cmd/file.c b/lsfd-cmd/file.c index abd1f07ef..32b08693d 100644 --- a/lsfd-cmd/file.c +++ b/lsfd-cmd/file.c @@ -424,6 +424,11 @@ static bool file_fill_column(struct proc *proc __attribute__((__unused__)), *d = '('; if (r) err(EXIT_FAILURE, _("failed to add output data")); + if (uri) { + struct libscols_cell *ce = scols_line_get_cell(ln, column_index); + if (ce) + scols_cell_disable_uri(ce, 1); + } return true; } } @@ -435,7 +440,8 @@ static bool file_fill_column(struct proc *proc __attribute__((__unused__)), ftype = file->stat.st_mode & S_IFMT; if (uri && (!file->name || *file->name != '/' - || (ftype != S_IFREG && ftype != S_IFDIR))) { + || (ftype != S_IFREG && ftype != S_IFDIR) + || file->stat.st_nlink == 0)) { struct libscols_cell *ce = scols_line_get_cell(ln, column_index); if (ce) scols_cell_disable_uri(ce, 1); diff --git a/tests/expected/lsfd/option-hyperlink-deleted-file b/tests/expected/lsfd/option-hyperlink-deleted-file new file mode 100644 index 000000000..6e9fa7384 --- /dev/null +++ b/tests/expected/lsfd/option-hyperlink-deleted-file @@ -0,0 +1,9 @@ +# NAME +00000000 2e 2f 74 6d 70 2d 6f 70 74 69 6f 6e 2d 68 79 70 |./tmp-option-hyp| +00000010 65 72 6c 69 6e 6b 20 0a |erlink .| +00000018 +# KNAME +00000000 2e 2f 74 6d 70 2d 6f 70 74 69 6f 6e 2d 68 79 70 |./tmp-option-hyp| +00000010 65 72 6c 69 6e 6b 20 28 64 65 6c 65 74 65 64 29 |erlink (deleted)| +00000020 0a |.| +00000021 diff --git a/tests/ts/lsfd/option-hyperlink b/tests/ts/lsfd/option-hyperlink index d8503b6a2..4529d2f00 100755 --- a/tests/ts/lsfd/option-hyperlink +++ b/tests/ts/lsfd/option-hyperlink @@ -39,6 +39,12 @@ replace_hostname() sed -e 's@file://'"${HOSTNAME_PATTERN}"'/@file:///@' } +replace_filename() +{ + # Make the output PWD independent: + sed -e 's@'"$TS_OUTDIR"'@.@g' +} + ts_cd "$TS_OUTDIR" PID= FD=3 @@ -72,4 +78,21 @@ ts_init_subtest "character-device" wait "${MKFDS_PID}" ts_finalize_subtest +ts_init_subtest "deleted-file" +{ + coproc MKFDS { "$TS_HELPER_MKFDS" make-regular-file $FD file=tmp-option-hyperlink delete=true; } + if read -r -u "${MKFDS[0]}" PID; then + for o in NAME KNAME; do + echo "# $o" + "${TS_CMD_LSFD}" -n --hyperlink=always -o "$o" -p "${PID}" -Q "$EXPR" \ + | replace_hostname \ + | replace_filename \ + | "$TS_CMD_HEXDUMP" -C + done + echo DONE >&"${MKFDS[1]}" + fi +} > "$TS_OUTPUT" 2>&1 +wait "${MKFDS_PID}" +ts_finalize_subtest + ts_finalize