From 3261508d4d0ee9f8edc04b0ede53882e47029b1a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 4 Mar 2016 11:58:20 -0800 Subject: [PATCH] Cleanups to WikiRevision * Check for blank $source variable more properly. * Avoid use of ugly File::DELETE_SOURCE flag. * Remove now-unused $flags parameter to uploadOld(). Change-Id: I6bc610cfead0036700b4f9a82e13f2bd9ab10f32 --- includes/filerepo/file/OldLocalFile.php | 7 ++----- includes/import/WikiRevision.php | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/includes/filerepo/file/OldLocalFile.php b/includes/filerepo/file/OldLocalFile.php index f76b38bc11..31e62ecbe9 100644 --- a/includes/filerepo/file/OldLocalFile.php +++ b/includes/filerepo/file/OldLocalFile.php @@ -332,16 +332,13 @@ class OldLocalFile extends LocalFile { * @param string $timestamp * @param string $comment * @param User $user - * @param int $flags * @return FileRepoStatus */ - function uploadOld( $srcPath, $archiveName, $timestamp, $comment, $user, $flags = 0 ) { + function uploadOld( $srcPath, $archiveName, $timestamp, $comment, $user ) { $this->lock(); $dstRel = 'archive/' . $this->getHashPath() . $archiveName; - $status = $this->publishTo( $srcPath, $dstRel, - $flags & File::DELETE_SOURCE ? FileRepo::DELETE_SOURCE : 0 - ); + $status = $this->publishTo( $srcPath, $dstRel ); if ( $status->isGood() ) { if ( !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) ) { diff --git a/includes/import/WikiRevision.php b/includes/import/WikiRevision.php index d4db7658fd..356a79f82d 100644 --- a/includes/import/WikiRevision.php +++ b/includes/import/WikiRevision.php @@ -640,22 +640,24 @@ class WikiRevision { # Get the file source or download if necessary $source = $this->getFileSrc(); - $flags = $this->isTempSrc() ? File::DELETE_SOURCE : 0; - if ( !$source ) { + $autoDeleteSource = $this->isTempSrc(); + if ( !strlen( $source ) ) { $source = $this->downloadSource(); - $flags |= File::DELETE_SOURCE; + $autoDeleteSource = true; } - if ( !$source ) { + if ( !strlen( $source ) ) { wfDebug( __METHOD__ . ": Could not fetch remote file.\n" ); return false; } + + $tmpFile = new TempFSFile( $source ); + if ( $autoDeleteSource ) { + $tmpFile->autocollect(); + } + $sha1File = ltrim( sha1_file( $source ), '0' ); $sha1 = $this->getSha1(); if ( $sha1 && ( $sha1 !== $sha1File ) ) { - if ( $flags & File::DELETE_SOURCE ) { - # Broken file; delete it if it is a temporary file - unlink( $source ); - } wfDebug( __METHOD__ . ": Corrupt file $source.\n" ); return false; } @@ -665,8 +667,9 @@ class WikiRevision { # Do the actual upload if ( $archiveName ) { $status = $file->uploadOld( $source, $archiveName, - $this->getTimestamp(), $this->getComment(), $user, $flags ); + $this->getTimestamp(), $this->getComment(), $user ); } else { + $flags = 0; $status = $file->upload( $source, $this->getComment(), $this->getComment(), $flags, false, $this->getTimestamp(), $user ); } -- 2.20.1