Skip to content

Commit

Permalink
dl_ref better logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lacanoid committed May 29, 2021
1 parent 49ff1fd commit 736e4a8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions datalink.sql
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,13 @@ begin
if link_options > 0 then
lco = datalink.link_control_options(link_options);
if lco.integrity <> 'NONE' then
if lco.integrity = 'ALL' and dlurlscheme($1)<>'file' then
raise exception 'INTEGRITY ALL can only be used with file URLs'
using errcode = 'HW005',
detail = url,
hint = 'make sure you are using a file: URL scheme';
end if;

-- check if reference exists
has_token := 1;
r := datalink.curl_get(url,true);
Expand All @@ -854,15 +861,8 @@ begin

link := dlpreviouscopy(link,has_token);

if lco.integrity = 'ALL' then
if dlurlscheme($1)='file' then
if lco.integrity = 'ALL' and dlurlscheme($1)='file' then
perform datalink.file_link(dlurlpathonly(link),(link->>'token')::datalink.dl_token,link_options,regclass,column_name);
else
raise exception 'INTEGRITY ALL can only be used with file URLs'
using errcode = 'HW005',
detail = url,
hint = 'make sure you are using a file: URL scheme';
end if;
end if; -- integrity all

end if; -- link options
Expand Down
4 changes: 2 additions & 2 deletions test/expected/link.out
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ values (dlvalue('/etc/issue1','FS','Sample file datalink 3'));
ERROR: datalink exception - referenced file does not exit
DETAIL: file:///etc/issue1
HINT: make sure referenced file actually exists
CONTEXT: PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 19 at RAISE
CONTEXT: PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 26 at RAISE
PL/pgSQL function dl_trigger_table() line 49 at assignment
insert into sample_datalinks4 (link)
values (dlvalue('/etc/hosts','FS','Sample file datalink 4'));
Expand Down Expand Up @@ -69,7 +69,7 @@ ERROR: datalink exception - external file already linked
DETAIL: from sample_datalinks4.link as '/etc/issue'
CONTEXT: PL/pgSQL function file_link(file_path,dl_token,dl_lco,regclass,name) line 36 at RAISE
SQL statement "SELECT datalink.file_link(dlurlpathonly(link),(link->>'token')::datalink.dl_token,link_options,regclass,column_name)"
PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 30 at PERFORM
PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 36 at PERFORM
PL/pgSQL function dl_trigger_table() line 49 at assignment
select state,regclass,attname,path
from datalink.linked_files;
Expand Down
4 changes: 2 additions & 2 deletions test/expected/linker.out
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ERROR: datalink exception - external file already linked
DETAIL: from sample_datalinks6.link as '/tmp/CHANGELOG.md'
CONTEXT: PL/pgSQL function file_link(file_path,dl_token,dl_lco,regclass,name) line 36 at RAISE
SQL statement "SELECT datalink.file_link(dlurlpathonly(link),(link->>'token')::datalink.dl_token,link_options,regclass,column_name)"
PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 30 at PERFORM
PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 36 at PERFORM
PL/pgSQL function dl_trigger_table() line 49 at assignment
update sample_datalinks6 set link = link2;
NOTICE: DATALINK UNLINK:/tmp/CHANGELOG.md
Expand All @@ -38,7 +38,7 @@ values (dlvalue('http://www.debian.org/tmp/CHANGELOG.md',null,'Weblink'));
ERROR: INTEGRITY ALL can only be used with file URLs
DETAIL: http://www.debian.org/tmp/CHANGELOG.md
HINT: make sure you are using a file: URL scheme
CONTEXT: PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 32 at RAISE
CONTEXT: PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 16 at RAISE
PL/pgSQL function dl_trigger_table() line 49 at assignment
select regexp_replace(dlurlpath(link),'[a-z0-9\-]{10,}','xxx','g') as dlurlpath1
from sample_datalinks6;
Expand Down
4 changes: 2 additions & 2 deletions test/expected/other.out
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ values (dlvalue('file:///foo+bar/no_file','URL','Sample file datalink 2'));
ERROR: datalink exception - referenced file does not exit
DETAIL: file:///foo+bar/no_file
HINT: make sure referenced file actually exists
CONTEXT: PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 19 at RAISE
CONTEXT: PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 26 at RAISE
PL/pgSQL function dl_trigger_table() line 49 at assignment
update datalink.column_options
set link_control='FILE', integrity='SELECTIVE'
Expand All @@ -37,7 +37,7 @@ values (dlvalue('http://blah','URL','Broken datalink'));
ERROR: datalink exception - referenced file does not exit
DETAIL: http://blah
HINT: make sure referenced file actually exists
CONTEXT: PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 19 at RAISE
CONTEXT: PL/pgSQL function dl_ref(datalink,dl_lco,regclass,name) line 26 at RAISE
PL/pgSQL function dl_trigger_table() line 49 at assignment
select dlurlcomplete(link), (link)->>'token' is not null as has_token from sample_datalinks2;
dlurlcomplete | has_token
Expand Down

0 comments on commit 736e4a8

Please sign in to comment.