--- loncom/lonnet/perl/lonnet.pm 2017/08/23 22:46:38 1.1351 +++ loncom/lonnet/perl/lonnet.pm 2017/08/27 02:36:58 1.1352 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1351 2017/08/23 22:46:38 raeburn Exp $ +# $Id: lonnet.pm,v 1.1352 2017/08/27 02:36:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -3171,6 +3171,45 @@ sub externalssi { } } +sub remove_stale_resfile { + my ($url) = @_; + my $stale; + if ($url=~m{^/res/($match_domain)/($match_username)/}) { + my $audom = $1; + my $auname = $2; + unless (($url =~ /\.\d+\.\w+$/) || ($url !~ m{^/res/lib/templates/})) { + my $homeserver = &homeserver($auname,$audom); + unless (($homeserver eq 'no_host') || + (grep { $_ eq $homeserver } ¤t_machine_ids())) { + my $fname = &filelocation('',$url); + if (-e $fname) { + my $protocol = $protocol{$homeserver}; + $protocol = 'http' if ($protocol ne 'https'); + my $hostname = &hostname($homeserver); + if ($hostname) { + my $uri = &declutter($url); + my $request=new HTTP::Request('HEAD',$protocol.'://'.$hostname.'/raw/'.$uri); + my $response = &LONCAPA::LWPReq::makerequest($homeserver,$request,'',\%perlvar,5,0,1); + if ($response->is_success()) { + my $remmodtime = &HTTP::Date::str2time( $response->header('Last-modified') ); + my $locmodtime = (stat($fname))[9]; + if ($locmodtime < $remmodtime) { + unlink($fname); + if ($uri!~/\.meta$/) { + unlink($fname.'.meta'); + } + &reply("unsub:$fname",$homeserver); + $stale = 1; + } + } + } + } + } + } + } + return $stale; +} + # -------------------------------- Allow a /uploaded/ URI to be vouched for sub allowuploaded {