| ... | ... | @@ -2010,6 +2010,58 @@ test "tarball without root folder" { |
| 2010 | 2010 | try fb.expectPackageFiles(expected_files); |
| 2011 | 2011 | } |
| 2012 | 2012 | |
| 2013 | test "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 | |
| 2013 | 2065 | fn saveEmbedFile(comptime tarball_name: []const u8, dir: fs.Dir) !void { |
| 2014 | 2066 | //const tarball_name = "duplicate_paths_excluded.tar.gz"; |
| 2015 | 2067 | const tarball_content = @embedFile("Fetch/testdata/" ++ tarball_name); |