@@ -16,7 +16,7 @@ class TarTestCase extends TestCase
1616 protected $ extensions = array ('tar ' );
1717
1818 /** @inheritdoc */
19- protected function setUp () : void
19+ protected function setUp (): void
2020 {
2121 parent ::setUp ();
2222 if (extension_loaded ('zlib ' )) {
@@ -31,7 +31,7 @@ protected function setUp() : void
3131 }
3232
3333 /** @inheritdoc */
34- protected function tearDown () : void
34+ protected function tearDown (): void
3535 {
3636 parent ::tearDown ();
3737 $ this ->extensions [] = null ;
@@ -53,7 +53,8 @@ protected function getDir()
5353 * Callback check function
5454 * @param FileInfo $fileinfo
5555 */
56- public function increaseCounter ($ fileinfo ) {
56+ public function increaseCounter ($ fileinfo )
57+ {
5758 $ this ->assertInstanceOf ('\\splitbrain \\PHPArchive \\FileInfo ' , $ fileinfo );
5859 $ this ->counter ++;
5960 }
@@ -560,7 +561,8 @@ public function testZeroData()
560561 /**
561562 * Add a zero byte file to a tar and extract it again
562563 */
563- public function testZeroByteFile () {
564+ public function testZeroByteFile ()
565+ {
564566 $ archive = sys_get_temp_dir () . '/dwziptest ' . md5 (time ()) . '.zip ' ;
565567 $ extract = sys_get_temp_dir () . '/dwziptest ' . md5 (time () + 1 );
566568
@@ -814,7 +816,7 @@ public function testReadCurrentEntry()
814816 $ tar = new Tar ();
815817 $ tar ->open (__DIR__ . '/tar/test.tar ' );
816818 $ pathsRead = array ();
817- foreach ($ tar ->yieldContents () as $ i ) {
819+ foreach ($ tar ->yieldContents () as $ i ) {
818820 $ this ->assertFileExists ($ out . '/ ' . $ i ->getPath ());
819821 if ($ i ->getIsdir ()) {
820822 $ this ->assertEquals ('' , $ tar ->readCurrentEntry ());
@@ -829,6 +831,67 @@ public function testReadCurrentEntry()
829831 self ::RDelete ($ out );
830832 }
831833
834+ /**
835+ * Create an archive, extract it, and compare file properties
836+ */
837+ public function testFilePropertiesPreservation ()
838+ {
839+ $ input = glob ($ this ->getDir () . '/../src/* ' );
840+ $ archive = sys_get_temp_dir () . '/dwtartest ' . md5 (time ()) . '.tar ' ;
841+ $ extract = sys_get_temp_dir () . '/dwtartest ' . md5 (time () + 1 );
842+
843+ // Create archive
844+ $ tar = new Tar ();
845+ $ tar ->create ($ archive );
846+ foreach ($ input as $ path ) {
847+ $ file = basename ($ path );
848+ $ tar ->addFile ($ path , $ file );
849+ }
850+ $ tar ->close ();
851+ $ this ->assertFileExists ($ archive );
852+
853+ // Extract archive
854+ $ tar = new Tar ();
855+ $ tar ->open ($ archive );
856+ $ tar ->extract ($ extract );
857+ $ tar ->close ();
858+
859+ // Compare file properties
860+ foreach ($ input as $ originalPath ) {
861+ $ filename = basename ($ originalPath );
862+ $ extractedPath = $ extract . '/ ' . $ filename ;
863+
864+ $ this ->assertFileExists ($ extractedPath , "Extracted file should exist: $ filename " );
865+
866+ // Compare file sizes
867+ $ originalSize = filesize ($ originalPath );
868+ $ extractedSize = filesize ($ extractedPath );
869+ $ this ->assertEquals ($ originalSize , $ extractedSize , "File size should match for: $ filename " );
870+
871+ // Compare file contents
872+ $ originalContent = file_get_contents ($ originalPath );
873+ $ extractedContent = file_get_contents ($ extractedPath );
874+ $ this ->assertEquals ($ originalContent , $ extractedContent , "File content should match for: $ filename " );
875+
876+ // Compare modification times (allow small difference due to tar format limitations)
877+ $ originalMtime = filemtime ($ originalPath );
878+ $ extractedMtime = filemtime ($ extractedPath );
879+ $ this ->assertLessThanOrEqual (1 , abs ($ originalMtime - $ extractedMtime ),
880+ "Modification time should be preserved (within 1 second) for: $ filename " );
881+
882+ // Compare file permissions (only on Unix-like systems)
883+ if (DIRECTORY_SEPARATOR === '/ ' ) {
884+ $ originalPerms = fileperms ($ originalPath ) & 0777 ;
885+ $ extractedPerms = fileperms ($ extractedPath ) & 0777 ;
886+ $ this ->assertEquals ($ originalPerms , $ extractedPerms ,
887+ "File permissions should match for: $ filename " );
888+ }
889+ }
890+
891+ self ::RDelete ($ extract );
892+ unlink ($ archive );
893+ }
894+
832895 /**
833896 * recursive rmdir()/unlink()
834897 *
0 commit comments