[Rt-commit] rt branch, 4.4/external-storage, updated. rt-4.2.11-38-gfe32673

Shawn Moore shawn at bestpractical.com
Fri May 22 14:51:20 EDT 2015


The branch, 4.4/external-storage has been updated
       via  fe32673b48223d61241f61a7b7873d2e65984d53 (commit)
      from  f2a97277f0c5610462ed8cf03de68ccc0c217919 (commit)

Summary of changes:
 lib/RT/Config.pm                   |  6 +-----
 lib/RT/ExternalStorage.pm          |  2 --
 lib/RT/ExternalStorage/Disk.pm     | 13 ++++++++++---
 sbin/rt-externalize-attachments.in | 12 +++++++++---
 4 files changed, 20 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit fe32673b48223d61241f61a7b7873d2e65984d53
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 18:44:26 2015 +0000

    Use a method call to confirm writeability rather than a global

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 0144e22..47ef2da 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -994,11 +994,7 @@ our %META;
 
             require RT::ExternalStorage;
 
-            my $backend = RT::ExternalStorage::Backend->new(
-                %hash,
-                Write => $RT::ExternalStorage::WRITE,
-            );
-
+            my $backend = RT::ExternalStorage::Backend->new(%hash);
             RT->System->ExternalStorage($backend);
         },
     },
diff --git a/lib/RT/ExternalStorage.pm b/lib/RT/ExternalStorage.pm
index 0045467..5c4a9f1 100644
--- a/lib/RT/ExternalStorage.pm
+++ b/lib/RT/ExternalStorage.pm
@@ -131,6 +131,4 @@ storage.
 
 =cut
 
-our $WRITE;
-
 1;
diff --git a/lib/RT/ExternalStorage/Disk.pm b/lib/RT/ExternalStorage/Disk.pm
index 238d586..d01e28a 100644
--- a/lib/RT/ExternalStorage/Disk.pm
+++ b/lib/RT/ExternalStorage/Disk.pm
@@ -70,14 +70,21 @@ sub Init {
     } elsif (not -e $self->Path) {
         RT->Logger->error("Path provided for local storage (".$self->Path.") does not exist");
         return;
-    } elsif ($self->{Write} and not -w $self->Path) {
-        RT->Logger->error("Path provided for local storage (".$self->Path.") is not writable");
-        return;
     }
 
     return $self;
 }
 
+sub IsWriteable {
+    my $self = shift;
+
+    if (not -w $self->Path) {
+        return (undef, "Path provided for local storage (".$self->Path.") is not writable");
+    }
+
+    return (1);
+}
+
 sub Get {
     my $self = shift;
     my ($sha) = @_;
diff --git a/sbin/rt-externalize-attachments.in b/sbin/rt-externalize-attachments.in
index 3b9c17f..9a462ef 100755
--- a/sbin/rt-externalize-attachments.in
+++ b/sbin/rt-externalize-attachments.in
@@ -66,15 +66,21 @@ BEGIN { # BEGIN RT CMD BOILERPLATE
 
 }
 
-BEGIN { $RT::ExternalStorage::WRITE = 1 };
 use RT -init;
 
 # Ensure we only run one of these processes at once
 use Fcntl ':flock';
 exit unless flock main::DATA, LOCK_EX | LOCK_NB;
 
+my $ExternalStorage = RT->System->ExternalStorage;
+
 die "\%ExternalStorage is not configured\n"
-    unless RT->System->ExternalStorage;
+    unless $ExternalStorage;
+
+if ($ExternalStorage->Can('IsWriteable')) {
+    my ($ok, $msg) = $ExternalStorage->IsWriteable;
+    die $msg if !$ok;
+}
 
 # pull out the previous high-water mark for each object type
 my $last = RT->System->FirstAttribute("ExternalStorage");
@@ -180,7 +186,7 @@ sub Store {
     my $content = shift;
 
     my $key = Digest::SHA::sha256_hex( $content );
-    my ($ok, $msg) = RT->System->ExternalStorage->Store( $key => $content );
+    my ($ok, $msg) = $ExternalStorage->Store( $key => $content );
     return ($ok, $msg) unless defined $ok;
 
     return ($key);

-----------------------------------------------------------------------


More information about the rt-commit mailing list