diff options
-rw-r--r-- | conf/general.yml-example | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Model/PhotoSet.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/Zurich.pm | 8 |
4 files changed, 13 insertions, 12 deletions
diff --git a/conf/general.yml-example b/conf/general.yml-example index 4c89cfba2..54bbd6a7f 100644 --- a/conf/general.yml-example +++ b/conf/general.yml-example @@ -61,6 +61,7 @@ LANGUAGES: TIME_ZONE: "" # File locations for uploaded photos and cached geocoding results. +# Absolute paths, or relative to the project's root directory UPLOAD_DIR: '../upload/' GEO_CACHE: '../cache/' diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm index 487786a3b..46e1fb630 100644 --- a/perllib/FixMyStreet/App/Model/PhotoSet.pm +++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm @@ -68,7 +68,7 @@ has upload_dir => ( lazy => 1, default => sub { my $self = shift; - my $cache_dir = path( FixMyStreet->config('UPLOAD_DIR') ); + my $cache_dir = path(FixMyStreet->config('UPLOAD_DIR'))->absolute(FixMyStreet->path_to()); $cache_dir->mkpath; unless ( -d $cache_dir && -w $cache_dir ) { warn "Can't find/write to photo cache directory '$cache_dir'"; diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 257a8d4a3..b5bb7249c 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -9,10 +9,9 @@ package FixMyStreet::Geocode; use strict; use Digest::MD5 qw(md5_hex); use Encode; -use File::Slurp; -use File::Path (); use JSON::MaybeXS; use LWP::Simple qw($ua); +use Path::Tiny; use URI::Escape; use FixMyStreet::Geocode::Bing; use FixMyStreet::Geocode::Google; @@ -69,19 +68,20 @@ sub escape { sub cache { my ($type, $url, $args, $re) = @_; - my $cache_dir = FixMyStreet->config('GEO_CACHE') . $type . '/'; - my $cache_file = $cache_dir . md5_hex($url); + + my $cache_dir = path(FixMyStreet->config('GEO_CACHE'), $type)->absolute(FixMyStreet->path_to()); + my $cache_file = $cache_dir->child(md5_hex($url)); my $js; if (-s $cache_file && -M $cache_file <= 7 && !FixMyStreet->config('STAGING_SITE')) { - $js = File::Slurp::read_file($cache_file); + $js = $cache_file->slurp; } else { $url .= '&' . $args if $args; $ua->timeout(15); $js = LWP::Simple::get($url); $js = encode_utf8($js) if utf8::is_utf8($js); - File::Path::mkpath($cache_dir); + $cache_dir->mkpath; if ($js && (!$re || $js !~ $re) && !FixMyStreet->config('STAGING_SITE')) { - File::Slurp::write_file($cache_file, $js); + $cache_file->spew($js); } } $js = JSON->new->utf8->allow_nonref->decode($js) if $js; diff --git a/perllib/FixMyStreet/Geocode/Zurich.pm b/perllib/FixMyStreet/Geocode/Zurich.pm index 671da9722..c7bd9e9d9 100644 --- a/perllib/FixMyStreet/Geocode/Zurich.pm +++ b/perllib/FixMyStreet/Geocode/Zurich.pm @@ -12,8 +12,8 @@ package FixMyStreet::Geocode::Zurich; use strict; use Digest::MD5 qw(md5_hex); -use File::Path (); use Geo::Coordinates::CH1903Plus; +use Path::Tiny; use Storable; use Utils; @@ -64,8 +64,8 @@ sub string { setup_soap(); - my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'zurich/'; - my $cache_file = $cache_dir . md5_hex($s); + my $cache_dir = path(FixMyStreet->config('GEO_CACHE'), 'zurich')->absolute(FixMyStreet->path_to()); + my $cache_file = $cache_dir->child(md5_hex($s)); my $result; if (-s $cache_file && -M $cache_file <= 7 && !FixMyStreet->config('STAGING_SITE')) { $result = retrieve($cache_file); @@ -80,7 +80,7 @@ sub string { return { error => 'The geocoder appears to be down.' }; } $result = $result->result; - File::Path::mkpath($cache_dir); + $cache_dir->mkpath; store $result, $cache_file if $result && !FixMyStreet->config('STAGING_SITE'); } |