Index: branches/FileBackend/phase3/includes/upload/UploadBase.php |
— | — | @@ -239,8 +239,11 @@ |
240 | 240 | function getRealPath( $srcPath ) { |
241 | 241 | $repo = RepoGroup::singleton()->getLocalRepo(); |
242 | 242 | if ( $repo->isVirtualUrl( $srcPath ) ) { |
| 243 | + // @TODO: just make uploads work with storage paths |
243 | 244 | // UploadFromStash loads files via virtuals URLs |
244 | | - return $repo->getLocalCopy( $srcPath )->getPath(); |
| 245 | + $tmpFile = $repo->getLocalCopy( $srcPath ); |
| 246 | + $tmpFile->bind( $this ); // keep alive with $thumb |
| 247 | + return $tmpFile->getPath(); |
245 | 248 | } |
246 | 249 | return $srcPath; |
247 | 250 | } |
Index: branches/FileBackend/phase3/includes/filerepo/file/TempFSFile.php |
— | — | @@ -19,7 +19,8 @@ |
20 | 20 | protected static $instances = array(); |
21 | 21 | |
22 | 22 | /** |
23 | | - * Make a new temporary file on the file system |
| 23 | + * Make a new temporary file on the file system. |
| 24 | + * Temporary files may be purged when the file object falls out of scope. |
24 | 25 | * |
25 | 26 | * @param $prefix string |
26 | 27 | * @param $extension string |
— | — | @@ -42,7 +43,9 @@ |
43 | 44 | } |
44 | 45 | } |
45 | 46 | $tmpFile = new self( $path ); |
46 | | - self::$instances[] = $tmpFile; // defer purge till shutdown |
| 47 | + if ( php_sapi_name() != 'cli' ) { |
| 48 | + self::$instances[] = $tmpFile; // defer purge till shutdown |
| 49 | + } |
47 | 50 | return $tmpFile; |
48 | 51 | } |
49 | 52 | |
— | — | @@ -60,17 +63,28 @@ |
61 | 64 | } |
62 | 65 | |
63 | 66 | /** |
64 | | - * Flag to not clean up after the temporary file |
| 67 | + * Clean up the temporary file only after an object goes out of scope |
65 | 68 | * |
| 69 | + * @param $object Object |
66 | 70 | * @return void |
67 | 71 | */ |
| 72 | + public function bind( $object ) { |
| 73 | + if ( is_object( $object ) ) { |
| 74 | + $object->tempFSFileReferences[] = $this; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Set flag to not clean up after the temporary file |
| 80 | + * |
| 81 | + * @return void |
| 82 | + */ |
68 | 83 | public function preserve() { |
69 | 84 | $this->canDelete = false; |
70 | 85 | } |
71 | 86 | |
72 | 87 | /** |
73 | | - * Cleans up after the temporary file by deleting it. |
74 | | - * This is done on shutdown after PHP kills self::$instances. |
| 88 | + * Cleans up after the temporary file by deleting it |
75 | 89 | */ |
76 | 90 | function __destruct() { |
77 | 91 | if ( $this->canDelete ) { |
Index: branches/FileBackend/phase3/includes/filerepo/file/File.php |
— | — | @@ -783,6 +783,7 @@ |
784 | 784 | |
785 | 785 | // Actually render the thumbnail |
786 | 786 | $thumb = $this->handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $params ); |
| 787 | + $tmpFile->bind( $thumb ); // keep alive with $thumb |
787 | 788 | |
788 | 789 | // Ignore errors if requested |
789 | 790 | if ( !$thumb ) { |
Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php |
— | — | @@ -274,10 +274,11 @@ |
275 | 275 | |
276 | 276 | /** |
277 | 277 | * Returns a file system file, identical to the file at a storage path. |
278 | | - * The file return is either: |
| 278 | + * The file returned is either: |
279 | 279 | * a) A local copy of the file at a storage path in the backend. |
280 | 280 | * The temporary copy will have the same extension as the source. |
281 | 281 | * b) An original of the file at a storage path in the backend. |
| 282 | + * Temporary files may be purged when the file object falls out of scope. |
282 | 283 | * |
283 | 284 | * Write operations should *never* be done on this file as some backends |
284 | 285 | * may do internal tracking or may be instances of FileBackendMultiWrite. |
— | — | @@ -294,6 +295,7 @@ |
295 | 296 | /** |
296 | 297 | * Get a local copy on disk of the file at a storage path in the backend. |
297 | 298 | * The temporary copy will have the same file extension as the source. |
| 299 | + * Temporary files may be purged when the file object falls out of scope. |
298 | 300 | * |
299 | 301 | * $params include: |
300 | 302 | * src : source storage path |
Index: branches/FileBackend/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -1142,10 +1142,10 @@ |
1143 | 1143 | |
1144 | 1144 | /** |
1145 | 1145 | * Get a local FS copy of a file with a given virtual URL/storage path. |
1146 | | - * Returns null on failure. |
| 1146 | + * Temporary files may be purged when the file object falls out of scope. |
1147 | 1147 | * |
1148 | 1148 | * @param $virtualUrl string |
1149 | | - * @return TempFSFile|null |
| 1149 | + * @return TempFSFile|null Returns null on failure |
1150 | 1150 | */ |
1151 | 1151 | public function getLocalCopy( $virtualUrl ) { |
1152 | 1152 | $path = $this->resolveToStoragePath( $virtualUrl ); |
— | — | @@ -1155,10 +1155,10 @@ |
1156 | 1156 | /** |
1157 | 1157 | * Get a local FS file with a given virtual URL/storage path. |
1158 | 1158 | * The file is either an original or a copy. It should not be changed. |
1159 | | - * Returns null on failure. |
| 1159 | + * Temporary files may be purged when the file object falls out of scope. |
1160 | 1160 | * |
1161 | 1161 | * @param $virtualUrl string |
1162 | | - * @return FSFile|null |
| 1162 | + * @return FSFile|null Returns null on failure. |
1163 | 1163 | */ |
1164 | 1164 | public function getLocalReference( $virtualUrl ) { |
1165 | 1165 | $path = $this->resolveToStoragePath( $virtualUrl ); |