From: Cormac Parle Date: Thu, 30 Nov 2017 17:29:36 +0000 (+0000) Subject: Warn for uploads with new name but same content as local file X-Git-Tag: 1.31.0-rc.0~1290^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=bfe05136098f37a63a9cb3010b394480c94c8510;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index c335e2b813..f5c8ee0941 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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] ); } }