Index: trunk/extensions/SwiftMedia/SwiftMedia.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | $wgAutoloadClasses['SwiftForeignDBFile'] = |
14 | 14 | $wgAutoloadClasses['SwiftForeignDBRepo'] = |
15 | 15 | $wgAutoloadClasses['SwiftForeignDBviaLBRepo'] = |
16 | | - $wgAutoloadClasses['SwiftRepo'] = dirname(__FILE__) . '/SwiftMedia.body.php'; |
| 16 | + $wgAutoloadClasses['SwiftRepo'] = dirname( __FILE__ ) . '/SwiftMedia.body.php'; |
17 | 17 | $wgAutoloadClasses['CF_Authentication'] = |
18 | 18 | $wgAutoloadClasses['CF_Connection'] = |
19 | 19 | $wgAutoloadClasses['CF_Container'] = |
Index: trunk/extensions/SwiftMedia/wmf/rewrite.py |
— | — | @@ -15,13 +15,25 @@ |
16 | 16 | # the account remains valid forever, but the token times out. |
17 | 17 | account = 'AUTH_dea4a45c-a80b-43b5-8e8b-e452f0dc778f' |
18 | 18 | |
| 19 | +# Copy2 is hairy. If we were only opening a URL, and returning it, we could |
| 20 | +# just return the open file handle, and webob would take care of reading from |
| 21 | +# the socket and returning the data to the client machine. If we were only |
| 22 | +# opening a URL and writing its contents out to Swift, we could call |
| 23 | +# put_object with the file handle and it would read take care of reading from |
| 24 | +# the socket and writing the data to the Swift proxy. |
| 25 | +# We have to do both at the same time. This requires that we hand over a class which |
| 26 | +# is an iterable which reads, writes one copy to Swift (using put_object_chunked), and |
| 27 | +# returns a copy to webob. This is controlled by writethumb in /etc/swift/proxy.conf, |
| 28 | + |
19 | 29 | class Copy2(object): |
20 | 30 | """ |
21 | | - Given an open file and a Swift object, we hand back an iterator which reads from the file, |
22 | | - writes a copy into a Swift object, and returns what it read. |
| 31 | + Given an open file and a Swift object, we hand back an iterator which |
| 32 | + reads from the file, writes a copy into a Swift object, and returns |
| 33 | + what it read. |
23 | 34 | """ |
24 | 35 | token = None |
25 | 36 | |
| 37 | + |
26 | 38 | def __init__(self, conn, app, url, container, obj, authurl, login, key, content_type=None, modified=None): |
27 | 39 | self.app = app |
28 | 40 | self.conn = conn |
— | — | @@ -77,6 +89,7 @@ |
78 | 90 | self.login = conf['login'].strip() |
79 | 91 | self.key = conf['key'].strip() |
80 | 92 | self.thumbhost = conf['thumbhost'].strip() |
| 93 | + self.writethumb = conf.has_key('writethumb') |
81 | 94 | self.user_agent = conf['user_agent'].strip() |
82 | 95 | |
83 | 96 | def handle404(self, reqorig, url, container, obj): |
— | — | @@ -104,13 +117,13 @@ |
105 | 118 | uinfo = upcopy.info() |
106 | 119 | c_t = uinfo.gettype() |
107 | 120 | last_modified = time.mktime(uinfo.getdate('Last-Modified')) |
108 | | - # Fetch from upload, write into the cluster, and return it |
109 | | - app_iter = Copy2(upcopy, self.app, url, |
110 | | - urllib2.quote(container), obj, self.authurl, self.login, |
111 | | - self.key, content_type=c_t, modified=last_modified) |
| 121 | + if self.writethumb: |
| 122 | + # Fetch from upload, write into the cluster, and return it |
| 123 | + upcopy = Copy2(upcopy, self.app, url, |
| 124 | + urllib2.quote(container), obj, self.authurl, self.login, |
| 125 | + self.key, content_type=c_t, modified=last_modified) |
112 | 126 | |
113 | | - resp = webob.Response(app_iter=app_iter, content_type=c_t) |
114 | | - resp.headers.add('Things', "%s %s %s %s %s %s %s %s" % (url, urllib2.quote(container), obj, self.authurl, self.login, self.key, c_t, last_modified)) |
| 127 | + resp = webob.Response(app_iter=upcopy, content_type=c_t) |
115 | 128 | resp.headers.add('Last-Modified', uinfo.getheader('Last-Modified')) |
116 | 129 | return resp |
117 | 130 | |
— | — | @@ -171,7 +184,7 @@ |
172 | 185 | return webob.Response(status=status, headers=headers , |
173 | 186 | app_iter=app_iter)(env, start_response) #01a |
174 | 187 | elif status == 404: #4 |
175 | | - resp = self.handle404(reqorig) |
| 188 | + resp = self.handle404(reqorig, url, container, obj) |
176 | 189 | return resp(env, start_response) |
177 | 190 | elif status == 401: |
178 | 191 | # if the Storage URL is invalid or has expired we'll get this error. |
Index: trunk/extensions/SwiftMedia/SwiftMedia.body.php |
— | — | @@ -414,15 +414,15 @@ |
415 | 415 | |
416 | 416 | // Point to the container. |
417 | 417 | $dstContainer = $this->getZoneContainer( $dstZone ); |
418 | | - $dstc = $this->get_container($conn, $dstContainer); |
| 418 | + $dstc = $this->get_container( $conn, $dstContainer ); |
419 | 419 | |
420 | 420 | $good = true; |
421 | 421 | |
422 | 422 | // Where are we copying this from? |
423 | | - if (self::isVirtualUrl( $srcPath )) { |
| 423 | + if ( self::isVirtualUrl( $srcPath ) ) { |
424 | 424 | $src = $this->getContainerRel( $srcPath ); |
425 | | - list ($srcContainer, $srcRel) = $src; |
426 | | - $srcc = $this->get_container($conn, $srcContainer); |
| 425 | + list ( $srcContainer, $srcRel ) = $src; |
| 426 | + $srcc = $this->get_container( $conn, $srcContainer ); |
427 | 427 | |
428 | 428 | // See if we're not supposed to overwrite an existing file. |
429 | 429 | if ( !( $flags & self::OVERWRITE ) ) { |
— | — | @@ -431,7 +431,7 @@ |
432 | 432 | $objd = $dstc->get_object($dstRel); |
433 | 433 | // and if it does, are we allowed to overwrite it? |
434 | 434 | if ( $flags & self::OVERWRITE_SAME ) { |
435 | | - $objs = $srcc->get_object($srcRel); |
| 435 | + $objs = $srcc->get_object( $srcRel ); |
436 | 436 | if ( $objd->getETag() != $objs->getETag() ) { |
437 | 437 | $status->fatal( 'fileexistserror', $dstRel ); |
438 | 438 | $good = false; |
— | — | @@ -446,11 +446,11 @@ |
447 | 447 | } |
448 | 448 | } |
449 | 449 | |
450 | | - if ($good) { |
| 450 | + if ( $good ) { |
451 | 451 | try { |
452 | | - $this->swiftcopy($srcc, $srcRel, $dstc, $dstRel); |
| 452 | + $this->swiftcopy( $srcc, $srcRel, $dstc, $dstRel ); |
453 | 453 | } catch (InvalidResponseException $e ) { |
454 | | - $status->error( 'filecopyerror', $srcPath, "{$dstc->name}/$dstRel"); |
| 454 | + $status->error( 'filecopyerror', $srcPath, "{$dstc->name}/$dstRel" ); |
455 | 455 | $good = false; |
456 | 456 | } |
457 | 457 | if ( $flags & self::DELETE_SOURCE ) { |
— | — | @@ -462,7 +462,7 @@ |
463 | 463 | if ( !( $flags & self::OVERWRITE ) ) { |
464 | 464 | // does it exist? |
465 | 465 | try { |
466 | | - $objd = $dstc->get_object($dstRel); |
| 466 | + $objd = $dstc->get_object( $dstRel ); |
467 | 467 | // and if it does, are we allowed to overwrite it? |
468 | 468 | if ( $flags & self::OVERWRITE_SAME ) { |
469 | 469 | if ( $objd->getETag() != md5_file($srcPath) ) { |
— | — | @@ -478,12 +478,12 @@ |
479 | 479 | $exists = false; |
480 | 480 | } |
481 | 481 | } |
482 | | - if ($good) { |
| 482 | + if ( $good ) { |
483 | 483 | wfDebug( __METHOD__ . ": Writing $srcPath to {$dstc->name}/$dstRel\n"); |
484 | 484 | try { |
485 | | - $this->write_swift_object( $srcPath, $dstc, $dstRel); |
| 485 | + $this->write_swift_object( $srcPath, $dstc, $dstRel ); |
486 | 486 | } catch (InvalidResponseException $e ) { |
487 | | - $status->error( 'filecopyerror', $srcPath, "{$dstc->name}/$dstRel"); |
| 487 | + $status->error( 'filecopyerror', $srcPath, "{$dstc->name}/$dstRel" ); |
488 | 488 | $good = false; |
489 | 489 | } |
490 | 490 | if ( $flags & self::DELETE_SOURCE ) { |