Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file: linkstat to get link stat info #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

systemcrash
Copy link

This augments rpcd to be able to inspect symbolic links, instead of simply returning the linked file info

See openwrt/luci#7300 for inspiration

Usage:

root@OpenWrt:/# ubus call file stat '{"path":"/etc/os-release"}'
{
	"path": "/etc/os-release",
	"type": "file",
	"size": 528,
	"mode": 33188,
	"atime": 1727094886,
	"mtime": 1727094886,
	"ctime": 1727094886,
	"inode": 1124,
	"uid": 0,
	"gid": 0
}
root@OpenWrt:/# ubus call file lstat '{"path":"/etc/os-release"}'
{
	"path": "/etc/os-release",
	"type": "symlink",
	"size": 21,
	"mode": 41471,
	"atime": 1727094886,
	"mtime": 1727094886,
	"ctime": 1727094886,
	"inode": 219,
	"uid": 0,
	"gid": 0
}
root@OpenWrt:/# ubus call file stat '{"path":"/var"}'
{
	"path": "/var",
	"type": "directory",
	"size": 520,
	"mode": 17407,
	"atime": 1730221560,
	"mtime": 1730221753,
	"ctime": 1730221753,
	"inode": 1,
	"uid": 0,
	"gid": 0
}
root@OpenWrt:/# ubus call file lstat '{"path":"/var"}'
{
	"path": "/var",
	"type": "symlink",
	"size": 3,
	"mode": 41471,
	"atime": 1727094886,
	"mtime": 1727094886,
	"ctime": 1727094886,
	"inode": 1264,
	"uid": 0,
	"gid": 0
}
root@OpenWrt:/# ubus call file stat '{"path":"/bin/ash"}'
{
	"path": "/bin/ash",
	"type": "file",
	"size": 405522,
	"mode": 33261,
	"atime": 1727094886,
	"mtime": 1727094886,
	"ctime": 1727094886,
	"inode": 15,
	"uid": 0,
	"gid": 0
}
root@OpenWrt:/# ubus call file lstat '{"path":"/bin/ash"}'
{
	"path": "/bin/ash",
	"type": "symlink",
	"size": 7,
	"mode": 41471,
	"atime": 1727094886,
	"mtime": 1727094886,
	"ctime": 1727094886,
	"inode": 13,
	"uid": 0,
	"gid": 0
}

Tested on: 23.05.5

Tested on: 23.05.5

Signed-off-by: Paul Donald <[email protected]>
@stokito
Copy link

stokito commented Oct 30, 2024

Do we need all the fields for a symlink? The size of the symlink itself is unusable.
As far I know from a practical sense we may need to know only the link target. And even this may not always needed. So maybe just add the "target" field:

root@OpenWrt:/# ubus call file stat '{"path":"/var"}'
{
	"path": "/var",
	"type": "directory",
        "target": "/tmp/"
	"size": 520,
	"mode": 17407,
	"atime": 1730221560,
	"mtime": 1730221753,
	"ctime": 1730221753,
	"inode": 1,
	"uid": 0,
	"gid": 0
}

That may have a performance penalty of additional readlink syscall but I hope this will be negligible for most use cases.

@systemcrash
Copy link
Author

It reuses the same functionality as rpcd stat calls. If you read the manpage, lstat size is the character length of the path or something.

@systemcrash
Copy link
Author

@systemcrash
Copy link
Author

ping @jow-

@stokito
Copy link

stokito commented Dec 6, 2024

@systemcrash #9 (comment)

@stokito
Copy link

stokito commented Dec 6, 2024

To avoid performance penalties we may have it as an option Similarly to the ls -l:

ubus call file stat '{"path":"/var", "link": true}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants