Warn for uploads with new name but same content as local file
Previously warnings about the sha1 of an uploaded file being the same as an existing file were stripped if the existing file was in local storage - this was to avoid duplicate warnings if a file with the same name had already been found and had the same content. Now the warning is only stripped for local files with the same name as the uploaded file. Bug: T180691 Change-Id: I455df30085c05320dca976b9f7f8fb711a083271
This commit is contained in:
parent
2a05b74684
commit
bfe0513609
1 changed files with 11 additions and 4 deletions
|
|
@ -674,7 +674,10 @@ abstract class UploadBase {
|
|||
$warnings['was-deleted'] = $filename;
|
||||
}
|
||||
|
||||
$dupes = $this->checkAgainstExistingDupes( $hash );
|
||||
// If a file with the same name exists locally then the local file has already been tested
|
||||
// for duplication of content
|
||||
$ignoreLocalDupes = isset( $warnings[ 'exists '] );
|
||||
$dupes = $this->checkAgainstExistingDupes( $hash, $ignoreLocalDupes );
|
||||
if ( $dupes ) {
|
||||
$warnings['duplicate'] = $dupes;
|
||||
}
|
||||
|
|
@ -789,15 +792,19 @@ abstract class UploadBase {
|
|||
|
||||
/**
|
||||
* @param string $hash sha1 hash of the file to check
|
||||
* @param bool $ignoreLocalDupes True to ignore local duplicates
|
||||
*
|
||||
* @return File[] Duplicate files, if found.
|
||||
*/
|
||||
private function checkAgainstExistingDupes( $hash ) {
|
||||
private function checkAgainstExistingDupes( $hash, $ignoreLocalDupes ) {
|
||||
$dupes = RepoGroup::singleton()->findBySha1( $hash );
|
||||
$title = $this->getTitle();
|
||||
// Remove all matches against self
|
||||
foreach ( $dupes as $key => $dupe ) {
|
||||
if ( $title->equals( $dupe->getTitle() ) ) {
|
||||
if (
|
||||
( $dupe instanceof LocalFile ) &&
|
||||
$ignoreLocalDupes &&
|
||||
$title->equals( $dupe->getTitle() )
|
||||
) {
|
||||
unset( $dupes[$key] );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue