@@ -16,7 +16,7 @@ class TarTestCase extends TestCase
16
16
protected $ extensions = array ('tar ' );
17
17
18
18
/** @inheritdoc */
19
- protected function setUp () : void
19
+ protected function setUp (): void
20
20
{
21
21
parent ::setUp ();
22
22
if (extension_loaded ('zlib ' )) {
@@ -31,7 +31,7 @@ protected function setUp() : void
31
31
}
32
32
33
33
/** @inheritdoc */
34
- protected function tearDown () : void
34
+ protected function tearDown (): void
35
35
{
36
36
parent ::tearDown ();
37
37
$ this ->extensions [] = null ;
@@ -53,7 +53,8 @@ protected function getDir()
53
53
* Callback check function
54
54
* @param FileInfo $fileinfo
55
55
*/
56
- public function increaseCounter ($ fileinfo ) {
56
+ public function increaseCounter ($ fileinfo )
57
+ {
57
58
$ this ->assertInstanceOf ('\\splitbrain \\PHPArchive \\FileInfo ' , $ fileinfo );
58
59
$ this ->counter ++;
59
60
}
@@ -560,7 +561,8 @@ public function testZeroData()
560
561
/**
561
562
* Add a zero byte file to a tar and extract it again
562
563
*/
563
- public function testZeroByteFile () {
564
+ public function testZeroByteFile ()
565
+ {
564
566
$ archive = sys_get_temp_dir () . '/dwziptest ' . md5 (time ()) . '.zip ' ;
565
567
$ extract = sys_get_temp_dir () . '/dwziptest ' . md5 (time () + 1 );
566
568
@@ -814,7 +816,7 @@ public function testReadCurrentEntry()
814
816
$ tar = new Tar ();
815
817
$ tar ->open (__DIR__ . '/tar/test.tar ' );
816
818
$ pathsRead = array ();
817
- foreach ($ tar ->yieldContents () as $ i ) {
819
+ foreach ($ tar ->yieldContents () as $ i ) {
818
820
$ this ->assertFileExists ($ out . '/ ' . $ i ->getPath ());
819
821
if ($ i ->getIsdir ()) {
820
822
$ this ->assertEquals ('' , $ tar ->readCurrentEntry ());
@@ -829,6 +831,67 @@ public function testReadCurrentEntry()
829
831
self ::RDelete ($ out );
830
832
}
831
833
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
+
832
895
/**
833
896
* recursive rmdir()/unlink()
834
897
*
0 commit comments