]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: enable hyperlinks only for regular files and directories
authorMasatake YAMATO <yamato@redhat.com>
Fri, 6 Dec 2024 17:17:36 +0000 (02:17 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Fri, 13 Dec 2024 17:54:41 +0000 (02:54 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
lsfd-cmd/file.c
tests/expected/lsfd/option-hyperlink-character-device [new file with mode: 0644]
tests/ts/lsfd/option-hyperlink

index 7f8ec8780b3759dcc9d5fafcd3371bb72f018747..abd1f07efa5083fbc505519de3fc0c3a837d1958 100644 (file)
@@ -433,7 +433,9 @@ static bool file_fill_column(struct proc *proc __attribute__((__unused__)),
                    && scols_line_set_data(ln, column_index, file->name))
                        err(EXIT_FAILURE, _("failed to add output data"));
 
-               if (uri && (!file->name || *file->name != '/')) {
+               ftype = file->stat.st_mode & S_IFMT;
+               if (uri && (!file->name || *file->name != '/'
+                           || (ftype != S_IFREG && ftype != S_IFDIR))) {
                        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-character-device b/tests/expected/lsfd/option-hyperlink-character-device
new file mode 100644 (file)
index 0000000..3e815d9
--- /dev/null
@@ -0,0 +1,6 @@
+# NAME
+00000000  2f 64 65 76 2f 7a 65 72  6f 0a                    |/dev/zero.|
+0000000a
+# KNAME
+00000000  2f 64 65 76 2f 7a 65 72  6f 0a                    |/dev/zero.|
+0000000a
index a7fe12b87a02bf52b5c133364a480105b2c225bd..d8503b6a29b06bdc4b6577f5ca279ec870881570 100755 (executable)
@@ -58,4 +58,18 @@ ts_init_subtest "regular-file"
 wait "${MKFDS_PID}"
 ts_finalize_subtest
 
+ts_init_subtest "character-device"
+{
+    coproc MKFDS { "$TS_HELPER_MKFDS" rw-character-device $FD; }
+    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 | "$TS_CMD_HEXDUMP" -C
+       done
+       echo DONE >&"${MKFDS[1]}"
+    fi
+} > "$TS_OUTPUT" 2>&1
+wait "${MKFDS_PID}"
+ts_finalize_subtest
+
 ts_finalize