Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-file
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-file
Commits
d735accc
Commit
d735accc
authored
Sep 22, 2019
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reader.mtime().
parent
e254a2f4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
0 deletions
+80
-0
README.rst
README.rst
+10
-0
info.vtc
src/tests/info.vtc
+44
-0
vmod_file.c
src/vmod_file.c
+19
-0
vmod_file.vcc
src/vmod_file.vcc
+7
-0
No files found.
README.rst
View file @
d735accc
...
...
@@ -107,6 +107,16 @@ Returns the size of the file when it was most recently checked.
XXX ...
.. _xreader.mtime():
TIME xreader.mtime()
--------------------
Returns the modification time of the file determined when it was mostly
recently checked.
XXX ...
.. _file.version():
STRING version()
...
...
src/tests/info.vtc
View file @
d735accc
...
...
@@ -14,11 +14,15 @@ varnish v1 -vcl {
sub vcl_recv {
set req.http.Size = rdr.size();
set req.http.Mtime = rdr.mtime();
set req.http.Delta-Mtime = now - rdr.mtime();
return (synth(200));
}
sub vcl_synth {
set resp.http.Size = req.http.Size;
set resp.http.Mtime = req.http.Mtime;
set resp.http.Delta-Mtime = req.http.Delta-Mtime;
return (deliver);
}
} -start
...
...
@@ -29,6 +33,9 @@ client c1 {
expect resp.status == 200
# Oddly, the BYTES to string conversion results in "16.000".
expect resp.http.Size ~ {^16\D}
expect resp.http.Mtime ~ "GMT$"
expect resp.http.Delta-Mtime > 0
expect resp.http.Delta-Mtime < 1
} -run
shell {echo -n "foo" > ${tmpdir}/sz}
...
...
@@ -39,6 +46,9 @@ client c1 {
rxresp
expect resp.status == 200
expect resp.http.Size ~ {^3\D}
expect resp.http.Mtime ~ "GMT$"
expect resp.http.Delta-Mtime > 0
expect resp.http.Delta-Mtime < 1
} -run
shell {rm -f ${tmpdir}/sz}
...
...
@@ -56,3 +66,37 @@ logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect * = VCL_Error {^rdr\.size\(\): vmod file failure: rdr: cannot read info about}
expect * = End
} -run
shell {touch ${tmpdir}/mtime}
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("${tmpdir}/mtime", ttl=0.1s);
}
sub vcl_recv {
set req.http.Mtime = rdr.mtime();
return (synth(200));
}
sub vcl_synth {
set resp.http.Mtime = req.http.Mtime;
return (deliver);
}
}
shell {rm -f ${tmpdir}/mtime}
delay .1
logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^rdr\.mtime\(\): vmod file failure: rdr: cannot read info about}
expect * = End
} -start
client c1 -run
logexpect l1 -wait
src/vmod_file.c
View file @
d735accc
...
...
@@ -541,6 +541,25 @@ vmod_reader_size(VRT_CTX, struct VPFX(file_reader) *rdr)
return
(
sz
);
}
VCL_TIME
vmod_reader_mtime
(
VRT_CTX
,
struct
VPFX
(
file_reader
)
*
rdr
)
{
time_t
secs
;
long
nsecs
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
rdr
,
FILE_READER_MAGIC
);
CHECK_OBJ_NOTNULL
(
rdr
->
info
,
FILE_INFO_MAGIC
);
AZ
(
pthread_rwlock_rdlock
(
&
rdr
->
lock
));
ERRCHK
(
ctx
,
rdr
,
"mtime"
,
0
.);
secs
=
rdr
->
info
->
mtime
.
tv_sec
;
nsecs
=
rdr
->
info
->
mtime
.
tv_nsec
;
AZ
(
pthread_rwlock_unlock
(
&
rdr
->
lock
));
return
(
secs
+
nsecs
*
1e-9
);
}
VCL_STRING
vmod_version
(
VRT_CTX
)
{
...
...
src/vmod_file.vcc
View file @
d735accc
...
...
@@ -78,6 +78,13 @@ Returns the size of the file when it was most recently checked.
XXX ...
$Method TIME .mtime()
Returns the modification time of the file determined when it was mostly
recently checked.
XXX ...
$Function STRING version()
Return the version string for this VMOD.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment