jenkins-bot has submitted this change and it was merged.

Change subject: Handle Swift JSON listings with unqualified timestamps
......................................................................


Handle Swift JSON listings with unqualified timestamps

* Throw errors next time invalid timestamps are encountered

Change-Id: Ie5d6c63863cacbf7dc3bc3f408b395bdce859db9
---
M includes/Timestamp.php
M includes/filebackend/SwiftFileBackend.php
2 files changed, 21 insertions(+), 6 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Timestamp.php b/includes/Timestamp.php
index edcd6a8..c1c6455 100644
--- a/includes/Timestamp.php
+++ b/includes/Timestamp.php
@@ -93,9 +93,9 @@
                        # TS_ORACLE // session altered to DD-MM-YYYY 
HH24:MI:SS.FF6
                        $strtime = preg_replace( 
'/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3",
                                        str_replace( '+00:00', 'UTC', $ts ) );
-               } elseif ( preg_match( 
'/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) 
{
+               } elseif ( preg_match( 
'/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z?$/', $ts, $da ) 
) {
                        # TS_ISO_8601
-               } elseif ( preg_match( 
'/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
+               } elseif ( preg_match( 
'/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z?$/', $ts, $da ) ) {
                        #TS_ISO_8601_BASIC
                } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) 
(\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) {
                        # TS_POSTGRES
diff --git a/includes/filebackend/SwiftFileBackend.php 
b/includes/filebackend/SwiftFileBackend.php
index db090a9..fc598db 100644
--- a/includes/filebackend/SwiftFileBackend.php
+++ b/includes/filebackend/SwiftFileBackend.php
@@ -759,8 +759,8 @@
                        $srcObj = $contObj->get_object( $srcRel, 
$this->headersFromParams( $params ) );
                        $this->addMissingMetadata( $srcObj, $params['src'] );
                        $stat = array(
-                               // Convert dates like "Tue, 03 Jan 2012 
22:01:04 GMT" to TS_MW
-                               'mtime' => wfTimestamp( TS_MW, 
$srcObj->last_modified ),
+                               // Convert various random Swift dates to TS_MW
+                               'mtime' => $this->convertSwiftDate( 
$srcObj->last_modified, TS_MW ),
                                'size' => (int)$srcObj->content_length,
                                'sha1' => $srcObj->getMetadataValue( 
'Sha1base36' )
                        );
@@ -772,6 +772,21 @@
                }
 
                return $stat;
+       }
+
+       /**
+        * Convert dates like "Tue, 03 Jan 2012 22:01:04 
GMT"/"2013-05-11T07:37:27.678360Z".
+        * Dates might also come in like "2013-05-11T07:37:27.678360" from 
Swift listings,
+        * missing the timezone suffix (though Ceph RGW does not appear to have 
this bug).
+        *
+        * @param string $ts
+        * @param int $format Output format (TS_* constant)
+        * @return string
+        * @throws MWException
+        */
+       protected function convertSwiftDate( $ts, $format = TS_MW ) {
+               $timestamp = new MWTimestamp( $ts );
+               return $timestamp->getTimestamp( $format );
        }
 
        /**
@@ -1070,8 +1085,8 @@
                        $object = current( $cfObjects );
                        $path = "{$storageDir}/" . substr( $object->name, 
$suffixStart );
                        $val = array(
-                               // Convert dates like "Tue, 03 Jan 2012 
22:01:04 GMT" to TS_MW
-                               'mtime'  => wfTimestamp( TS_MW, 
$object->last_modified ),
+                               // Convert various random Swift dates to TS_MW
+                               'mtime'  => $this->convertSwiftDate( 
$object->last_modified, TS_MW ),
                                'size'   => (int)$object->content_length,
                                'latest' => false // eventually consistent
                        );

-- 
To view, visit https://gerrit.wikimedia.org/r/94081
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie5d6c63863cacbf7dc3bc3f408b395bdce859db9
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Faidon Liambotis <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to