]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: don't enable hyperlinks for deleted files
authorMasatake YAMATO <yamato@redhat.com>
Fri, 13 Dec 2024 16:16:25 +0000 (01:16 +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-deleted-file [new file with mode: 0644]
tests/ts/lsfd/option-hyperlink

index abd1f07efa5083fbc505519de3fc0c3a837d1958..32b08693db20b4c1c491d8afb5560f381ce0195f 100644 (file)
@@ -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 (file)
index 0000000..6e9fa73
--- /dev/null
@@ -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
index d8503b6a29b06bdc4b6577f5ca279ec870881570..4529d2f005527eb4320eb85c5cc5efff92607d5a 100755 (executable)
@@ -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