file: append "target" for symbolic links
authorPaul Donald <[email protected]>
Sun, 9 Nov 2025 15:11:46 +0000 (16:11 +0100)
committerRobert Marko <[email protected]>
Mon, 10 Nov 2025 14:14:21 +0000 (15:14 +0100)
commit483263c7b0cd3922b93be2cf9dad5eeccbb9fedb
tree41d13ea01274106cfec07372dfa845b8c4efef2a
parent917000075eb48c934f0a456be3b884758c376e0b
file: append "target" for symbolic links

When list encounters a symbolic link, we add its nested "target" entry, to where
the symbolic link points. Just how `ls -l` reports.

So when calling e.g.: ubus call file list '{"path":"/etc"}'

instead of:

...
"name": "os-release",
"type": "symlink",
"size": 21,
"mode": 41471,
"atime": 1760891865,
"mtime": 1760891865,
"ctime": 1760891865,
"inode": 266,
"uid": 0,
"gid": 0,
"target_type": "file"
...

We get:

...
"name": "os-release",
"type": "symlink",
"size": 21,
"mode": 41471,
"atime": 1760891865,
"mtime": 1760891865,
"ctime": 1760891865,
"inode": 266,
"uid": 0,
"gid": 0,
"target": {
"name": "../usr/lib/os-release",
"type": "file",
"size": 582,
"mode": 33188,
"atime": 1760891865,
"mtime": 1760891865,
"ctime": 1760891865,
"inode": 1744,
"uid": 0,
"gid": 0
}
...

And should a link be broken:

"name": "foo",
"type": "symlink",
"size": 8,
"mode": 41471,
"atime": 1762640365,
"mtime": 1762640365,
"ctime": 1762640365,
"inode": 348,
"uid": 0,
"gid": 0,
"target": {
"name": "/tmp/foo",
"type": "broken"
}

Tested on: OpenWrt 24.10.4 r28959-29397011cc
Signed-off-by: Paul Donald <[email protected]>
Tested-by: Eric Fahlgren <[email protected]>
Link: https://github.com/openwrt/rpcd/pull/21
Signed-off-by: Robert Marko <[email protected]>
file.c