mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-11-03 21:49:42 -09:00
Zig 0.16: fix stat with symlinks
This commit is contained in:
parent
87317504c9
commit
6ae03876bc
1 changed files with 30 additions and 26 deletions
56
src/scan.zig
56
src/scan.zig
|
|
@ -53,46 +53,50 @@ pub fn statAt(parent: std.Io.Dir, name: [:0]const u8, follow: bool, symlink: ?*b
|
|||
// https://ziglang.org/download/0.16.0/release-notes.html#FileStat-Make-Access-Time-Optional
|
||||
.linux => {
|
||||
var stat: std.os.linux.Statx = undefined;
|
||||
var flags: u32 = std.os.linux.AT.EMPTY_PATH;
|
||||
if (follow) flags |= std.os.linux.AT.SYMLINK_NOFOLLOW;
|
||||
return switch (std.os.linux.errno(std.os.linux.statx(
|
||||
parent.handle,
|
||||
name,
|
||||
std.os.linux.AT.EMPTY_PATH,
|
||||
flags,
|
||||
std.os.linux.STATX{
|
||||
.TYPE = true,
|
||||
.TYPE = true, // mutually exclusive with .MODE (implies .mode to include type)
|
||||
.BLOCKS = true,
|
||||
.SIZE = true,
|
||||
.INO = true,
|
||||
.NLINK = true,
|
||||
.UID = true,
|
||||
.GID = true,
|
||||
.MODE = true,
|
||||
.MTIME = true,
|
||||
},
|
||||
&stat,
|
||||
))) {
|
||||
.SUCCESS => sink.Stat{
|
||||
.etype =
|
||||
if (std.os.linux.S.ISDIR(stat.mode)) .dir
|
||||
else if (stat.nlink > 1) .link
|
||||
else if (!std.os.linux.S.ISREG(stat.mode)) .nonreg
|
||||
else .reg,
|
||||
.blocks = @truncate(stat.blocks),
|
||||
.size = stat.size,
|
||||
.dev = stat.dev_major,
|
||||
.ino = stat.ino,
|
||||
.nlink = @truncate(stat.nlink),
|
||||
.ext = .{
|
||||
.pack = .{
|
||||
.hasmtime = true,
|
||||
.hasuid = true,
|
||||
.hasgid = true,
|
||||
.hasmode = true,
|
||||
},
|
||||
.mtime = @intCast(stat.mtime.sec),
|
||||
.uid = stat.uid,
|
||||
.gid = stat.gid,
|
||||
.mode = stat.mode,
|
||||
},
|
||||
.SUCCESS => {
|
||||
if (symlink) |s| s.* = std.c.S.ISLNK(stat.mode);
|
||||
return sink.Stat{
|
||||
.etype =
|
||||
if (std.os.linux.S.ISDIR(stat.mode)) .dir
|
||||
else if (stat.nlink > 1) .link
|
||||
else if (!std.os.linux.S.ISREG(stat.mode)) .nonreg
|
||||
else .reg,
|
||||
.blocks = @truncate(stat.blocks),
|
||||
.size = stat.size,
|
||||
.dev = stat.dev_major,
|
||||
.ino = stat.ino,
|
||||
.nlink = @truncate(stat.nlink),
|
||||
.ext = .{
|
||||
.pack = .{
|
||||
.hasmtime = true,
|
||||
.hasuid = true,
|
||||
.hasgid = true,
|
||||
.hasmode = true,
|
||||
},
|
||||
.mtime = @intCast(stat.mtime.sec),
|
||||
.uid = stat.uid,
|
||||
.gid = stat.gid,
|
||||
.mode = stat.mode,
|
||||
}
|
||||
};
|
||||
},
|
||||
.NOENT => error.FileNotFound,
|
||||
.NAMETOOLONG => error.NameTooLong,
|
||||
|
|
|
|||
Loading…
Reference in a new issue