Commit 613201e9 authored by Geoff Simmons's avatar Geoff Simmons

Add reader.deleted().

parent ba5ecac5
...@@ -306,6 +306,28 @@ Example:: ...@@ -306,6 +306,28 @@ Example::
call do_file_error_handling; call do_file_error_handling;
} }
.. _.deleted():
.. _xreader.deleted():
BOOL xreader.deleted()
----------------------
Return true if and only if the file was found to have been deleted the
last time the file was checked.
As discussed in `File deletion and file updates`_ above, this is not
an error condition, if the file had been previously mapped. Then the
previously cached contents continue to be valid.
Example::
import std;
if (rdr.deleted()) {
std.log("file deleted, continuing with the current cached contents");
}
.. _xreader.size(): .. _xreader.size():
BYTES xreader.size() BYTES xreader.size()
......
...@@ -17,6 +17,7 @@ varnish v1 -vcl { ...@@ -17,6 +17,7 @@ varnish v1 -vcl {
set req.http.Mtime = rdr.mtime(); set req.http.Mtime = rdr.mtime();
set req.http.Delta-Mtime = now - rdr.mtime(); set req.http.Delta-Mtime = now - rdr.mtime();
set req.http.Next-Check = rdr.next_check(); set req.http.Next-Check = rdr.next_check();
set req.http.Deleted = rdr.deleted();
return (synth(200)); return (synth(200));
} }
...@@ -25,6 +26,7 @@ varnish v1 -vcl { ...@@ -25,6 +26,7 @@ varnish v1 -vcl {
set resp.http.Mtime = req.http.Mtime; set resp.http.Mtime = req.http.Mtime;
set resp.http.Delta-Mtime = req.http.Delta-Mtime; set resp.http.Delta-Mtime = req.http.Delta-Mtime;
set resp.http.Next-Check = req.http.Next-Check; set resp.http.Next-Check = req.http.Next-Check;
set resp.http.Deleted = req.http.Deleted;
return (deliver); return (deliver);
} }
} -start } -start
...@@ -40,6 +42,7 @@ client c1 { ...@@ -40,6 +42,7 @@ client c1 {
expect resp.http.Delta-Mtime < 1 expect resp.http.Delta-Mtime < 1
expect resp.http.Next-Check >= 0 expect resp.http.Next-Check >= 0
expect resp.http.Next-Check <= 0.1 expect resp.http.Next-Check <= 0.1
expect resp.http.Deleted == "false"
} -run } -run
shell {echo -n "foo" > ${tmpdir}/sz} shell {echo -n "foo" > ${tmpdir}/sz}
...@@ -55,6 +58,7 @@ client c1 { ...@@ -55,6 +58,7 @@ client c1 {
expect resp.http.Delta-Mtime < 1 expect resp.http.Delta-Mtime < 1
expect resp.http.Next-Check >= 0 expect resp.http.Next-Check >= 0
expect resp.http.Next-Check <= 0.1 expect resp.http.Next-Check <= 0.1
expect resp.http.Deleted == "false"
} -run } -run
shell {chmod a-r ${tmpdir}/sz} shell {chmod a-r ${tmpdir}/sz}
...@@ -141,3 +145,36 @@ client c1 { ...@@ -141,3 +145,36 @@ client c1 {
expect resp.http.Next-Check >= 0 expect resp.http.Next-Check >= 0
expect resp.http.Next-Check <= 0.1 expect resp.http.Next-Check <= 0.1
} -run } -run
shell {touch ${tmpdir}/deleteme}
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("${tmpdir}/deleteme", ttl=0.1s);
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.Error = rdr.error();
set resp.http.Deleted = rdr.deleted();
return (deliver);
}
}
shell {rm -f ${tmpdir}/deleteme}
delay .1
# .error() == false, since deleted files are not considered in error.
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Error == "false"
expect resp.http.Deleted == "true"
} -run
...@@ -565,6 +565,15 @@ vmod_reader_errmsg(VRT_CTX, struct VPFX(file_reader) *rdr) ...@@ -565,6 +565,15 @@ vmod_reader_errmsg(VRT_CTX, struct VPFX(file_reader) *rdr)
return (rdr->errbuf); return (rdr->errbuf);
} }
VCL_BOOL
vmod_reader_deleted(VRT_CTX, struct VPFX(file_reader) *rdr)
{
CHECK_OBJ_NOTNULL(rdr, FILE_READER_MAGIC);
(void)ctx;
return (rdr->flags & RDR_DELETED);
}
VCL_BYTES VCL_BYTES
vmod_reader_size(VRT_CTX, struct VPFX(file_reader) *rdr) vmod_reader_size(VRT_CTX, struct VPFX(file_reader) *rdr)
{ {
......
...@@ -280,6 +280,25 @@ Example:: ...@@ -280,6 +280,25 @@ Example::
call do_file_error_handling; call do_file_error_handling;
} }
.. _.deleted():
$Method BOOL .deleted()
Return true if and only if the file was found to have been deleted the
last time the file was checked.
As discussed in `File deletion and file updates`_ above, this is not
an error condition, if the file had been previously mapped. Then the
previously cached contents continue to be valid.
Example::
import std;
if (rdr.deleted()) {
std.log("file deleted, continuing with the current cached contents");
}
$Method BYTES .size() $Method BYTES .size()
Return the size of the file as currently cached. Invokes VCL failure Return the size of the file as currently cached. Invokes VCL failure
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment