Cleanups to WikiRevision
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 4 Mar 2016 19:58:20 +0000 (11:58 -0800)
committerOri.livneh <ori@wikimedia.org>
Wed, 23 Mar 2016 17:27:23 +0000 (17:27 +0000)
* 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
includes/import/WikiRevision.php

index f76b38b..31e62ec 100644 (file)
@@ -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 ) ) {
index d4db765..356a79f 100644 (file)
@@ -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 );
                }