summaryrefslogtreecommitdiff
path: root/plugins/OStatus/classes/Ostatus_profile.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-10-13 11:04:41 -0700
committerBrion Vibber <brion@pobox.com>2010-10-13 11:10:04 -0700
commitbca215563ff7aaee5c253b3a55cadc3b02116ef9 (patch)
tree9368ba6a3a4c350180b8dcf798367a1b1f9f13d7 /plugins/OStatus/classes/Ostatus_profile.php
parent2291d68e7019d04ae57f8cb408c42fc775a9a9ff (diff)
Clean up remote avatar temporary files if we fail before saving them into avatars directory (OMB core, OStatus, WikiHowProfile, YammerImport)
Diffstat (limited to 'plugins/OStatus/classes/Ostatus_profile.php')
-rw-r--r--plugins/OStatus/classes/Ostatus_profile.php35
1 files changed, 20 insertions, 15 deletions
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 47aee15f8..03fcb71df 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -1053,22 +1053,27 @@ class Ostatus_profile extends Memcached_DataObject
// @fixme this should be better encapsulated
// ripped from oauthstore.php (for old OMB client)
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
- if (!copy($url, $temp_filename)) {
- throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
- }
+ try {
+ if (!copy($url, $temp_filename)) {
+ throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
+ }
- if ($this->isGroup()) {
- $id = $this->group_id;
- } else {
- $id = $this->profile_id;
- }
- // @fixme should we be using different ids?
- $imagefile = new ImageFile($id, $temp_filename);
- $filename = Avatar::filename($id,
- image_type_to_extension($imagefile->type),
- null,
- common_timestamp());
- rename($temp_filename, Avatar::path($filename));
+ if ($this->isGroup()) {
+ $id = $this->group_id;
+ } else {
+ $id = $this->profile_id;
+ }
+ // @fixme should we be using different ids?
+ $imagefile = new ImageFile($id, $temp_filename);
+ $filename = Avatar::filename($id,
+ image_type_to_extension($imagefile->type),
+ null,
+ common_timestamp());
+ rename($temp_filename, Avatar::path($filename));
+ } catch (Exception $e) {
+ unlink($temp_filename);
+ throw $e;
+ }
// @fixme hardcoded chmod is lame, but seems to be necessary to
// keep from accidentally saving images from command-line (queues)
// that can't be read from web server, which causes hard-to-notice