Skip to content

Commit 0289688

Browse files
committed
std.tar: chore - update to zig 0.11.0-dev.3910+689f3163a
1 parent dd21d6a commit 0289688

File tree

2 files changed

+33
-38
lines changed

2 files changed

+33
-38
lines changed

Diff for: lib/std/compress/tar/reader_test.zig

+10-10
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test "std.tar validate testdata headers" {
7272
.gid = 1000,
7373
.size = 200,
7474
.mtime = try unixTime(1392395740, 0),
75-
.type = @enumFromInt(FileType, 0x53),
75+
.type = @as(FileType, @enumFromInt(0x53)),
7676
.linkname = "",
7777
.uname = "david",
7878
.gname = "david",
@@ -86,7 +86,7 @@ test "std.tar validate testdata headers" {
8686
.gid = 1000,
8787
.size = 200,
8888
.mtime = try unixTime(1392342187, 0),
89-
.type = @enumFromInt(FileType, 0x30),
89+
.type = @as(FileType, @enumFromInt(0x30)),
9090
.linkname = "",
9191
.uname = "david",
9292
.gname = "david",
@@ -105,7 +105,7 @@ test "std.tar validate testdata headers" {
105105
.gid = 1000,
106106
.size = 200,
107107
.mtime = try unixTime(1392340456, 0),
108-
.type = @enumFromInt(FileType, 0x30),
108+
.type = @as(FileType, @enumFromInt(0x30)),
109109
.linkname = "",
110110
.uname = "david",
111111
.gname = "david",
@@ -125,7 +125,7 @@ test "std.tar validate testdata headers" {
125125
.gid = 1000,
126126
.size = 200,
127127
.mtime = try unixTime(1392337404, 0),
128-
.type = @enumFromInt(FileType, 0x30),
128+
.type = @as(FileType, @enumFromInt(0x30)),
129129
.linkname = "",
130130
.uname = "david",
131131
.gname = "david",
@@ -145,7 +145,7 @@ test "std.tar validate testdata headers" {
145145
.gid = 1000,
146146
.size = 4,
147147
.mtime = try unixTime(1392398319, 0),
148-
.type = @enumFromInt(FileType, 0x30),
148+
.type = @as(FileType, @enumFromInt(0x30)),
149149
.linkname = "",
150150
.uname = "david",
151151
.gname = "david",
@@ -426,7 +426,7 @@ test "std.tar validate testdata headers" {
426426
.gid = 1000,
427427
.size = 14,
428428
.mtime = try unixTime(1441973427, 0),
429-
.type = @enumFromInt(FileType, 'D'),
429+
.type = @as(FileType, @enumFromInt('D')),
430430
.uname = "rawr",
431431
.gname = "dsnet",
432432
.atime = try unixTime(1441974501, 0),
@@ -452,7 +452,7 @@ test "std.tar validate testdata headers" {
452452
.gid = 1000,
453453
.size = 536870912,
454454
.mtime = try unixTime(1441973427, 0),
455-
.type = @enumFromInt(FileType, 'S'),
455+
.type = @as(FileType, @enumFromInt('S')),
456456
.uname = "rawr",
457457
.gname = "dsnet",
458458
.atime = try unixTime(1441991948, 0),
@@ -467,7 +467,7 @@ test "std.tar validate testdata headers" {
467467
.name = "bar",
468468
.linkname = "PAX4/PAX4/long-linkpath-name",
469469
.mtime = try unixTime(0, 0),
470-
.type = @enumFromInt(tar.FileType, '2'),
470+
.type = @as(tar.FileType, @enumFromInt('2')),
471471
.pax_recs = &.{
472472
"linkpath", "PAX4/PAX4/long-linkpath-name",
473473
},
@@ -715,14 +715,14 @@ test "std.tar validate testdata headers" {
715715
}
716716

717717
if (actual.size == -1) continue;
718-
const block_size = std.mem.alignForward(usize, @intCast(usize, actual.size), 512);
718+
const block_size = std.mem.alignForward(usize, @as(usize, @intCast(actual.size)), 512);
719719
// validate checksums if exist or skip over file contents
720720
if (test_case.chksums.len > i) {
721721
var h = std.crypto.hash.Md5.init(.{});
722722
const content = try talloc.alloc(u8, block_size);
723723
defer talloc.free(content);
724724
_ = try reader.read(content);
725-
h.update(content[0..@intCast(usize, actual.size)]);
725+
h.update(content[0..@intCast(actual.size)]);
726726
var hbuf: [16]u8 = undefined;
727727
h.final(&hbuf);
728728
const hex = std.fmt.bytesToHex(hbuf, .lower);

Diff for: lib/std/tar.zig

+23-28
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub const FileType = enum(u8) {
2424
gnu_long_link = 'K',
2525
_,
2626

27-
pub const sentinel = @enumFromInt(FileType, 0xff);
27+
pub const sentinel: FileType = @enumFromInt(0xff);
2828

2929
pub const NamedTypesBitset = std.StaticBitSet(128);
3030

@@ -89,9 +89,9 @@ fn parseNumeric(b: []const u8) !i64 {
8989
if (x >= 0x8000_0000_0000_0000) return error.Overflow;
9090

9191
return if (inv == 0)
92-
@bitCast(i64, x)
92+
@as(i64, @bitCast(x))
9393
else
94-
~@bitCast(i64, x);
94+
~@as(i64, @bitCast(x));
9595
}
9696

9797
return try parseOctal(b);
@@ -303,8 +303,8 @@ pub fn mergePax(kv: [2][]const u8, hdr: *Header) !void {
303303
.linkname => hdr.linkname = v,
304304
.uname => hdr.uname = v,
305305
.gname => hdr.gname = v,
306-
.uid => hdr.uid = @truncate(i32, try fmt.parseInt(i64, v, 10)),
307-
.gid => hdr.gid = @truncate(i32, try fmt.parseInt(i64, v, 10)),
306+
.uid => hdr.uid = @truncate(try fmt.parseInt(i64, v, 10)),
307+
.gid => hdr.gid = @truncate(try fmt.parseInt(i64, v, 10)),
308308
.atime => hdr.atime = try parsePaxTime(v),
309309
.ctime => hdr.ctime = try parsePaxTime(v),
310310
.mtime => hdr.mtime = try parsePaxTime(v),
@@ -453,10 +453,9 @@ pub const Header = struct {
453453
}
454454

455455
fn fieldDefault(comptime field: std.builtin.Type.StructField) field.type {
456-
return @ptrCast(
457-
*const field.type,
458-
@alignCast(@alignOf(field.type), field.default_value),
459-
).*;
456+
return @as(*const field.type, @ptrCast(
457+
@alignCast(field.default_value),
458+
)).*;
460459
}
461460

462461
/// copy all fields from `new_hdr` to `hdr`, but skipping any fields that
@@ -505,11 +504,7 @@ pub const Header = struct {
505504
};
506505

507506
pub fn unixTime(tv_sec: i64, tv_nsec: i64) !i128 {
508-
const result = @bitCast(i128, [_]i64{
509-
try math.mul(i64, tv_sec, time.ns_per_s),
510-
tv_nsec,
511-
});
512-
return result;
507+
return @bitCast([_]i64{ try math.mul(i64, tv_sec, time.ns_per_s), tv_nsec });
513508
}
514509

515510
pub const block_len = 512;
@@ -545,29 +540,29 @@ const V7Header = extern struct {
545540
else
546541
bytes_[i];
547542
unsigned += c;
548-
signed += @bitCast(i8, c);
543+
signed += @as(i8, @bitCast(c));
549544
}
550545
return .{ unsigned, signed };
551546
}
552547

553548
inline fn ustar(h: *const V7Header) *const UstarHeader {
554-
return @ptrCast(*const UstarHeader, h);
549+
return @ptrCast(h);
555550
}
556551
inline fn star(h: *const V7Header) *const StarHeader {
557-
return @ptrCast(*const StarHeader, h);
552+
return @ptrCast(h);
558553
}
559554
inline fn gnu(h: *const V7Header) *const GnuHeader {
560-
return @ptrCast(*const GnuHeader, h);
555+
return @ptrCast(h);
561556
}
562557
inline fn bytes(h: *const V7Header) *const [block_len]u8 {
563-
return @ptrCast(*const [block_len]u8, h);
558+
return @ptrCast(h);
564559
}
565560

566561
// Magics used to identify various formats.
567562
const magic_gnu = "ustar ";
568563
const version_gnu = " \x00";
569564
const magic_version_gnu = mem.readIntBig(u64, magic_gnu ++ version_gnu);
570-
const magic_ustar = @truncate(u48, mem.readIntBig(u64, "ustar\x00\x00\x00") >> 16);
565+
const magic_ustar: u48 = @truncate(mem.readIntBig(u64, "ustar\x00\x00\x00") >> 16);
571566
const version_ustar = "00"; // unused. left only for documentation
572567
const trailer_star = mem.readIntBig(u32, "tar\x00");
573568

@@ -578,7 +573,7 @@ const V7Header = extern struct {
578573
return fmt_unknown;
579574

580575
const magic_version = h.ustar().magicVersion();
581-
const magic = @truncate(u48, magic_version >> 16);
576+
const magic: u48 = @truncate(magic_version >> 16);
582577

583578
return if (magic == magic_ustar and
584579
mem.readIntBig(u32, &h.star().trailer) == trailer_star)
@@ -607,7 +602,7 @@ const UstarHeader = extern struct {
607602
__padding: [12]u8,
608603

609604
pub fn magicVersion(ustar: *const UstarHeader) u64 {
610-
return mem.readIntBig(u64, @ptrCast([*]const u8, &ustar.magic)[0..8]);
605+
return mem.readIntBig(u64, @as([*]const u8, @ptrCast(&ustar.magic))[0..8]);
611606
}
612607

613608
comptime {
@@ -722,14 +717,14 @@ pub fn HeaderIterator(comptime Reader: type) type {
722717
.gnu_long_name => {
723718
format.setIntersection(fmt_gnu);
724719
gnu_long_name = mem.sliceTo(try self.readBlocks(
725-
@intCast(usize, hdr.size),
720+
@intCast(hdr.size),
726721
&self.name_buf,
727722
), 0);
728723
},
729724
.gnu_long_link => {
730725
format.setIntersection(fmt_gnu);
731726
gnu_long_link = mem.sliceTo(try self.readBlocks(
732-
@intCast(usize, hdr.size),
727+
@intCast(hdr.size),
733728
&self.linkname_buf,
734729
), 0);
735730
},
@@ -779,11 +774,11 @@ pub fn HeaderIterator(comptime Reader: type) type {
779774
want -= block_len;
780775
}
781776
if (want != 0) return error.UnexpectedEndOfStream;
782-
return outbuf.items[0..@intCast(usize, size)];
777+
return outbuf.items[0..@intCast(size)];
783778
}
784779

785780
inline fn v7Header(self: Self) *const V7Header {
786-
return @ptrCast(*const V7Header, self.buf);
781+
return @ptrCast(self.buf);
787782
}
788783

789784
/// Reads n bytes from reader. Returns the following depending on n:
@@ -1011,7 +1006,7 @@ const Pax = struct {
10111006

10121007
/// return the most significant, 'top' half of the time as an i64
10131008
fn truncateTime(t: i128) i64 {
1014-
return @truncate(i64, t >> 64);
1009+
return @truncate(t >> 64);
10151010
}
10161011

10171012
const is_windows = builtin.os.tag == .windows;
@@ -1036,7 +1031,7 @@ fn setFileProperties(file: fs.File, header: Header, options: Options) !void {
10361031
// match gnu tar behavior on linux while using
10371032
// header.mode does not
10381033
const mode = try file.mode(); // header.mode
1039-
var modebits = std.StaticBitSet(32){ .mask = @intCast(u32, mode) };
1034+
var modebits = std.StaticBitSet(32){ .mask = @intCast(mode) };
10401035
// copy the user exe bit to the group and other exe bits
10411036
// these bit indices count from the right:
10421037
// u g o

0 commit comments

Comments
 (0)