Skip to content

Commit 877c4e9

Browse files
committed
Merge pull request quattor#52 from stdweird/profiles_from_future
CCM Fetch warn when dealing with "profiles from future" due to timesync issues
2 parents d27b717 + 59cf2f2 commit 877c4e9

File tree

3 files changed

+14
-62
lines changed

3 files changed

+14
-62
lines changed

src/main/perl/CacheManager.pm

-56
Original file line numberDiff line numberDiff line change
@@ -257,62 +257,6 @@ sub isLocked
257257
}
258258
}
259259

260-
#
261-
# public info?
262-
# cacheFile ($url)
263-
#
264-
265-
sub cacheFile
266-
{ #T
267-
my ($self, $url) = @_;
268-
my $eu = _encodeUrl($url);
269-
unless ($eu) {
270-
throw_error("_encodeUrl($url)", $!);
271-
return ();
272-
}
273-
274-
my $fn = $self->{"cache_path"} . "/data/$eu";
275-
my $ua = LWP::UserAgent->new();
276-
277-
#TODO retries/wait
278-
279-
$ua->timeout($self->{"get_timeout"});
280-
my $req = HTTP::Request->new(GET => $url);
281-
282-
my $mtime;
283-
if (-f $fn) {
284-
$mtime = (stat($fn))[9];
285-
unless (defined($mtime)) {
286-
throw_error("stat($fn)", $!);
287-
return ();
288-
}
289-
$req->headers->if_modified_since($mtime);
290-
}
291-
my $success = 0;
292-
my $i = 0;
293-
my $res;
294-
while (!$success && ($i < $self->{"retrieve_retries"})) {
295-
$res = $ua->request($req, $fn);
296-
if ($res->is_success) {
297-
$success = 1; #was downloaded
298-
$mtime = $res->last_modified;
299-
unless (utime($mtime, $mtime, $fn)) {
300-
throw_error("utime($mtime, $mtime, $fn)", $!);
301-
return ();
302-
}
303-
} elsif ($res->code == RC_NOT_MODIFIED) {
304-
$success = 1; #was not downloaded, becasue it is cache and unmodified
305-
} else {
306-
sleep($self->{"retrieve_wait"});
307-
$i++;
308-
}
309-
}
310-
unless ($success) {
311-
throw_error("http request failed", $res->code);
312-
return ();
313-
}
314-
return $fn;
315-
}
316260

317261
#
318262
# _encodeUrl ($url)

src/main/perl/Fetch.pm

+14-2
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,20 @@ sub retrieve
269269
$fh->close();
270270

271271
my $modified = $rs->last_modified();
272-
if (!(defined($modified) && utime($modified, $modified, $cache))) {
273-
$self->warn("Unable to set mtime for $cache: $!");
272+
273+
if ($modified) {
274+
my $now = time();
275+
if ($time < $modified) {
276+
$self->warn("Profile has last_modified timestamp ",
277+
$modified - $now,
278+
" seconds in future (timestamp $modified)");
279+
}
280+
281+
if (! utime($modified, $modified, $cache)) {
282+
$self->warn("Unable to set mtime for $cache: $!");
283+
}
284+
} else {
285+
$self->warn("Unable to set mtime for $cache: last_modified is undefined");
274286
}
275287

276288
$fh = CAF::FileReader->new($cache, log => $self);

src/test/perl/test-cachemanager.t

-4
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,4 @@ ok ($lcidf->read() == 4 && $ccidf->read() == 4,
168168
make_file("$cp/td.txt", "1\n");
169169
my $url = "file:///$cp/td.txt";
170170

171-
my $file;
172-
ok ($file = $cm -> cacheFile ($url),
173-
"cm->cacheFile ($url)");
174-
175171
done_testing();

0 commit comments

Comments
 (0)