authorgravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-04-07 01:21:10+02:00
committergravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-04-09 15:00:22+02:00
logf8dd2a1064154e5e8223c4d52e123b582497a40d
tree8dd981517fa05234b9657fd952c3eb63c045da57
parent8c58b8fe0107fe3e06ec8bac2b2c25f706406c82

fetch: add executable bit test


2 files changed, 52 insertions(+), 0 deletions(-)

src/Package/Fetch.zig+52
......@@ -2010,6 +2010,58 @@ test "tarball without root folder" {
20102010 try fb.expectPackageFiles(expected_files);
20112011}
20122012
2013test "set executable bit based on file content" {
2014 if (!std.fs.has_executable_bit) return error.SkipZigTest;
2015 const gpa = std.testing.allocator;
2016 var tmp = std.testing.tmpDir(.{});
2017 defer tmp.cleanup();
2018
2019 const tarball_name = "executables.tar.gz";
2020 try saveEmbedFile(tarball_name, tmp.dir);
2021 const tarball_path = try std.fmt.allocPrint(gpa, "zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
2022 defer gpa.free(tarball_path);
2023
2024 // $ tar -tvf executables.tar.gz
2025 // drwxrwxr-x 0 executables/
2026 // -rwxrwxr-x 170 executables/hello
2027 // lrwxrwxrwx 0 executables/hello_ln -> hello
2028 // -rw-rw-r-- 0 executables/file1
2029 // -rw-rw-r-- 17 executables/script_with_shebang_without_exec_bit
2030 // -rwxrwxr-x 7 executables/script_without_shebang
2031 // -rwxrwxr-x 17 executables/script
2032
2033 var fb: TestFetchBuilder = undefined;
2034 var fetch = try fb.build(gpa, tmp.dir, tarball_path);
2035 defer fb.deinit();
2036
2037 try fetch.run();
2038 try std.testing.expectEqualStrings(
2039 "1220fecb4c06a9da8673c87fe8810e15785f1699212f01728eadce094d21effeeef3",
2040 &Manifest.hexDigest(fetch.actual_hash),
2041 );
2042
2043 var out = try fb.packageDir();
2044 defer out.close();
2045 const S = std.posix.S;
2046 // expect executable bit not set
2047 try std.testing.expect((try out.statFile("file1")).mode & S.IXUSR == 0);
2048 try std.testing.expect((try out.statFile("script_without_shebang")).mode & S.IXUSR == 0);
2049 // expect executable bit set
2050 try std.testing.expect((try out.statFile("hello")).mode & S.IXUSR != 0);
2051 try std.testing.expect((try out.statFile("script")).mode & S.IXUSR != 0);
2052 try std.testing.expect((try out.statFile("script_with_shebang_without_exec_bit")).mode & S.IXUSR != 0);
2053 try std.testing.expect((try out.statFile("hello_ln")).mode & S.IXUSR != 0);
2054
2055 //
2056 // $ ls -al zig-cache/tmp/OCz9ovUcstDjTC_U/zig-global-cache/p/1220fecb4c06a9da8673c87fe8810e15785f1699212f01728eadce094d21effeeef3
2057 // -rw-rw-r-- 1 0 Apr file1
2058 // -rwxrwxr-x 1 170 Apr hello
2059 // lrwxrwxrwx 1 5 Apr hello_ln -> hello
2060 // -rwxrwxr-x 1 17 Apr script
2061 // -rw-rw-r-- 1 7 Apr script_without_shebang
2062 // -rwxrwxr-x 1 17 Apr script_with_shebang_without_exec_bit
2063}
2064
20132065fn saveEmbedFile(comptime tarball_name: []const u8, dir: fs.Dir) !void {
20142066 //const tarball_name = "duplicate_paths_excluded.tar.gz";
20152067 const tarball_content = @embedFile("Fetch/testdata/" ++ tarball_name);
src/Package/Fetch/testdata/executables.tar.gz created
Binary files /dev/null and b/src/Package/Fetch/testdata/executables.tar.gz differ