Fixed metadata-loss bug from b80bd6159bdf946c1d4fa1e143fea221937d848a.
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 21 Nov 2012 02:16:15 +0000 (18:16 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 21 Nov 2012 02:17:19 +0000 (18:17 -0800)
* Contrary to Swift docs, doing a POST seems to kill all the old metadata
  headers. I noticed this in testing due to addMissingMetadata() notices.

Change-Id: I988d7a8d38569823c9d66605b02705ee15a8bbe7

includes/filebackend/SwiftFileBackend.php

index 6a27e9b..5a9b062 100644 (file)
@@ -583,9 +583,11 @@ class SwiftFileBackend extends FileBackendStore {
 
                try {
                        $sContObj = $this->getContainer( $srcCont );
-                       $srcObj = new CF_Object( $sContObj, $srcRel, false, false ); // skip HEAD
-                       // Merge in the new metadata and header values...
-                       $srcObj->headers = $hdrs;
+                       // Get the latest version of the current metadata
+                       $srcObj = $sContObj->get_object( $srcRel,
+                               $this->headersFromParams( array( 'latest' => true ) ) );
+                       // Merge in the metadata updates...
+                       $srcObj->headers = $hdrs + $srcObj->headers;
                        $srcObj->sync_metadata(); // save to Swift
                        $this->purgeCDNCache( array( $srcObj ) );
                } catch ( CDNNotEnabledException $e ) {
@@ -816,6 +818,7 @@ class SwiftFileBackend extends FileBackendStore {
                                }
                        }
                }
+               trigger_error( "Unable to set SHA-1 metadata for $path", E_USER_WARNING );
                $obj->setMetadataValues( array( 'Sha1base36' => false ) );
                wfProfileOut( __METHOD__ );
                return false; // failed