@@ -79,9 +79,11 @@ public function handle(): int
7979 '{libc} ' => getenv ('SPC_LIBC ' ) ?: 'default ' ,
8080 '{libcver} ' => PHP_OS_FAMILY === 'Linux ' ? (SystemUtil::getLibcVersionIfExists () ?? 'default ' ) : 'default ' ,
8181 ];
82+ // detect suffix, for proper tar option
83+ $ tar_option = $ this ->getTarOptionFromSuffix (Config::getPreBuilt ('match-pattern ' ));
8284 $ filename = str_replace (array_keys ($ replace ), array_values ($ replace ), $ filename );
8385 $ filename = WORKING_DIR . '/dist/ ' . $ filename ;
84- f_passthru (' tar -czf ' . $ filename . ' -T ' . WORKING_DIR . '/packlib_files.txt ' );
86+ f_passthru (" tar { $ tar_option } { $ filename} -T " . WORKING_DIR . '/packlib_files.txt ' );
8587 logger ()->info ('Pack library ' . $ lib ->getName () . ' to ' . $ filename . ' complete. ' );
8688 }
8789 }
@@ -115,4 +117,30 @@ private function sanityCheckLib(LibraryBase $lib): void
115117 }
116118 }
117119 }
120+
121+ /**
122+ * Get tar compress options from suffix
123+ *
124+ * @param string $name Package file name
125+ * @return string Tar options for packaging libs
126+ */
127+ private function getTarOptionFromSuffix (string $ name ): string
128+ {
129+ if (str_ends_with ($ name , '.tar ' )) {
130+ return '-cf ' ;
131+ }
132+ if (str_ends_with ($ name , '.tar.gz ' ) || str_ends_with ($ name , '.tgz ' )) {
133+ return '-czf ' ;
134+ }
135+ if (str_ends_with ($ name , '.tar.bz2 ' ) || str_ends_with ($ name , '.tbz2 ' )) {
136+ return '-cjf ' ;
137+ }
138+ if (str_ends_with ($ name , '.tar.xz ' ) || str_ends_with ($ name , '.txz ' )) {
139+ return '-cJf ' ;
140+ }
141+ if (str_ends_with ($ name , '.tar.lz ' ) || str_ends_with ($ name , '.tlz ' )) {
142+ return '-c --lzma -f ' ;
143+ }
144+ return '-cf ' ;
145+ }
118146}
0 commit comments