File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -499,6 +499,20 @@ public function isWritable($path)
499
499
return is_writable ($ path );
500
500
}
501
501
502
+ /**
503
+ * Determine if two files are the same by comparing their hashes.
504
+ *
505
+ * @param string $firstFile
506
+ * @param string $secondFile
507
+ * @return bool
508
+ */
509
+ public function hasSameHash ($ firstFile , $ secondFile )
510
+ {
511
+ $ hash = @md5_file ($ firstFile );
512
+
513
+ return $ hash && $ hash === @md5_file ($ secondFile );
514
+ }
515
+
502
516
/**
503
517
* Determine if the given path is a file.
504
518
*
Original file line number Diff line number Diff line change 15
15
* @method static bool deleteDirectory(string $directory, bool $preserve = false)
16
16
* @method static bool exists(string $path)
17
17
* @method static bool isDirectory(string $directory)
18
+ * @method static bool isEqual(string $file, string $compared)
18
19
* @method static bool isFile(string $file)
19
20
* @method static bool isReadable(string $path)
20
21
* @method static bool isWritable(string $path)
Original file line number Diff line number Diff line change @@ -544,6 +544,21 @@ public function testCopyCopiesFileProperly()
544
544
$ this ->assertEquals ($ data , file_get_contents (self ::$ tempDir .'/text/foo2.txt ' ));
545
545
}
546
546
547
+ public function testHasSameHashChecksFileHashes ()
548
+ {
549
+ $ filesystem = new Filesystem ;
550
+
551
+ mkdir (self ::$ tempDir .'/text ' );
552
+ file_put_contents (self ::$ tempDir .'/text/foo.txt ' , 'contents ' );
553
+ file_put_contents (self ::$ tempDir .'/text/foo2.txt ' , 'contents ' );
554
+ file_put_contents (self ::$ tempDir .'/text/foo3.txt ' , 'invalid ' );
555
+
556
+ $ this ->assertTrue ($ filesystem ->hasSameHash (self ::$ tempDir .'/text/foo.txt ' , self ::$ tempDir .'/text/foo2.txt ' ));
557
+ $ this ->assertFalse ($ filesystem ->hasSameHash (self ::$ tempDir .'/text/foo.txt ' , self ::$ tempDir .'/text/foo3.txt ' ));
558
+ $ this ->assertFalse ($ filesystem ->hasSameHash (self ::$ tempDir .'/text/foo4.txt ' , self ::$ tempDir .'/text/foo.txt ' ));
559
+ $ this ->assertFalse ($ filesystem ->hasSameHash (self ::$ tempDir .'/text/foo.txt ' , self ::$ tempDir .'/text/foo4.txt ' ));
560
+ }
561
+
547
562
public function testIsFileChecksFilesProperly ()
548
563
{
549
564
$ filesystem = new Filesystem ;
You can’t perform that action at this time.
0 commit comments