Sat, 14 May 2022 15:21:59 +0200
check cgi exit code
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2022 Olaf Wintermann. All rights reserved. |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "vfs.h" |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
31 | #include <inttypes.h> |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
32 | |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
33 | #include "../../util/util.h" |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
34 | |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | static VFS pg_vfs_class = { |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | pg_vfs_open, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | pg_vfs_stat, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | pg_vfs_fstat, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | pg_vfs_opendir, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | pg_vfs_fdopendir, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | pg_vfs_mkdir, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | pg_vfs_unlink, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | pg_vfs_rmdir |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | }; |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | static VFS_IO pg_vfs_io_class = { |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | pg_vfs_io_read, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | pg_vfs_io_write, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | pg_vfs_io_pread, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | pg_vfs_io_pwrite, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | pg_vfs_io_seek, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | pg_vfs_io_close, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | NULL, // no pg aio implementation yet |
345
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
54 | NULL, |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
55 | pg_vfs_io_getetag |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | }; |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | static VFS_DIRIO pg_vfs_dirio_class = { |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | pg_vfs_dirio_readdir, |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | pg_vfs_dirio_close |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | }; |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
63 | |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
64 | /* |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
65 | * SQL Queries |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
66 | */ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
67 | |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
68 | // Resolves a path into resource_id and parent_id |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
69 | // params: $1: path string |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
70 | static const char *sql_resolve_path = |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
71 | "with recursive resolvepath as (\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
72 | select\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
73 | resource_id,\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
74 | parent_id,\n\ |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
75 | '' as fullpath,\n\ |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
76 | resoid,\n\ |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
77 | iscollection,\n\ |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
78 | lastmodified,\n\ |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
79 | creationdate,\n\ |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
80 | contentlength,\n\ |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
81 | etag,\n\ |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
82 | regexp_split_to_array($1, '/') as pathelm,\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
83 | 1 as pathdepth\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
84 | from Resource\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
85 | where parent_id is null\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
86 | union\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
87 | select\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
88 | r.resource_id,\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
89 | r.parent_id,\n\ |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
90 | p.fullpath || '/' || r.nodename,\n\ |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
91 | r.resoid,\n\ |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
92 | r.iscollection,\n\ |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
93 | r.lastmodified,\n\ |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
94 | r.creationdate,\n\ |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
95 | r.contentlength,\n\ |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
96 | r.etag,\n\ |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
97 | p.pathelm,\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
98 | p.pathdepth + 1\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
99 | from Resource r\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
100 | inner join resolvepath p on r.parent_id = p.resource_id\n\ |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
101 | where p.pathelm[p.pathdepth+1] = r.nodename\n\ |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
102 | )\n\ |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
103 | select resource_id, parent_id, fullpath, resoid, iscollection, lastmodified, creationdate, contentlength, etag from resolvepath\n\ |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
104 | where fullpath = $1 ;"; |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
105 | |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
106 | // Same as sql_resolve_path, but it returns the root collection |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
107 | // params: $1: path string (should be '/') |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
108 | static const char *sql_get_root = "select resource_id, parent_id, $1 as fullpath, resoid, true as iscollection, lastmodified, creationdate, contentlength, etag from Resource where parent_id is null;"; |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
109 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
110 | // Get all children of a specific collection |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
111 | // params: $1: parent resource_id |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
112 | static const char *sql_get_children = "select resource_id, nodename, iscollection, lastmodified, creationdate, contentlength, etag from Resource where parent_id = $1;"; |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
113 | |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
114 | // Get resource |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
115 | // params: $1: resource_id |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
116 | static const char *sql_get_resource = "select resource_id, nodename, iscollection, lastmodified, creationdate, contentlength, etag from Resource where resource_id = $1;"; |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
117 | |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
118 | // Create resource |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
119 | // params: $1: parent_id |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
120 | // $2: node name |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
121 | static const char *sql_create_resource = |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
122 | "insert into Resource (parent_id, nodename, iscollection, lastmodified, creationdate, contentlength, resoid) values\n\ |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
123 | ($1, $2, false, now(), now(), 0, lo_creat(-1))\n\ |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
124 | returning resource_id, resoid, lastmodified, creationdate;"; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
125 | |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
126 | // Create collection |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
127 | // params: $1: parent_id |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
128 | // $2: node name |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
129 | static const char *sql_create_collection = |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
130 | "insert into Resource (parent_id, nodename, iscollection, lastmodified, creationdate, contentlength) values\n\ |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
131 | ($1, $2, true, now(), now(), 0)\n\ |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
132 | returning resource_id, lastmodified, creationdate;"; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
133 | |
292
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
134 | // Update resource metadata |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
135 | // params: $1: resource_id |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
136 | // $2: contentlength |
347
b6d71e504294
update etag when a postgresql file is updated
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
137 | static const char *sql_update_resource = "update Resource set contentlength = $2, lastmodified = now(), etag = gen_random_uuid() where resource_id = $1;"; |
292
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
138 | |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
139 | // Delete a resource |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
140 | // params: $1: resource_id |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
141 | static const char *sql_delete_res = "delete from Resource where parent_id is not null and resource_id = $1;"; |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
142 | |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
143 | VFS* pg_vfs_create(Session *sn, Request *rq, pblock *pb) { |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
144 | // resourcepool is required |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
145 | char *resource_pool = pblock_findval("resourcepool", pb); |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
146 | if(!resource_pool) { |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
147 | log_ereport(LOG_MISCONFIG, "pg_vfs_create: missing resourcepool parameter"); |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
148 | return NULL; |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
149 | } |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
150 | |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
151 | // get the resource first (most likely to fail due to misconfig) |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
152 | ResourceData *resdata = resourcepool_lookup(sn, rq, resource_pool, 0); |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
153 | if(!resdata) { |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
154 | log_ereport(LOG_MISCONFIG, "postgresql vfs: resource pool %s not found", resource_pool); |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
155 | return NULL; |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
156 | } |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
157 | // resdata will be freed automatically when the request is finished |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
158 | |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
159 | return pg_vfs_create_from_resourcedata(sn, rq, resdata); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
160 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
161 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
162 | VFS* pg_vfs_create_from_resourcedata(Session *sn, Request *rq, ResourceData *resdata) { |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
163 | // Create a new VFS object and a separate instance object |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
164 | // VFS contains fptrs that can be copied from pg_vfs_class |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
165 | // instance contains request specific data (PGconn) |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
166 | VFS *vfs = pool_malloc(sn->pool, sizeof(VFS)); |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
167 | if(!vfs) { |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
168 | return NULL; |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
169 | } |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
170 | |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
171 | PgVFS *vfs_priv = pool_malloc(sn->pool, sizeof(PgVFS)); |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
172 | if(!vfs_priv) { |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
173 | pool_free(sn->pool, vfs); |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
174 | return NULL; |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
175 | } |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
176 | vfs_priv->connection = resdata->data; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
177 | vfs_priv->pg_resource = resdata; |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
178 | |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
179 | memcpy(vfs, &pg_vfs_class, sizeof(VFS)); |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
180 | vfs->flags = 0; |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
181 | vfs->instance = vfs_priv; |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
182 | |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
183 | return vfs; |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
184 | } |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
185 | |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
186 | |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
187 | int pg_resolve_path( |
305
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
188 | PGconn *connection, |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
189 | const char *path, |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
190 | int64_t *parent_id, |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
191 | int64_t *resource_id, |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
192 | Oid *oid, |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
193 | const char **resource_name, |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
194 | WSBool *iscollection, |
305
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
195 | struct stat *s, |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
196 | char *etag, |
305
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
197 | int *res_errno) |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
198 | { |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
199 | // basic path validation |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
200 | if(!path) return 1; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
201 | size_t pathlen = strlen(path); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
202 | if(pathlen == 0) return 1; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
203 | if(path[0] != '/') { |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
204 | return 1; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
205 | } |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
206 | |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
207 | char *pathf = NULL; |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
208 | if(pathlen > 1 && path[pathlen-1] == '/') { |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
209 | pathf = malloc(pathlen); |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
210 | memcpy(pathf, path, pathlen); |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
211 | pathf[pathlen-1] = 0; // remove trailing '/' |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
212 | path = pathf; |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
213 | } |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
214 | |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
215 | // get last node of path |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
216 | *resource_name = util_resource_name(path); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
217 | |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
218 | const char *sql = pathlen == 1 ? sql_get_root : sql_resolve_path; |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
219 | PGresult *result = PQexecParams( |
305
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
220 | connection, |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
221 | sql, |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
222 | 1, // number of parameters |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
223 | NULL, |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
224 | &path, // parameter value |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
225 | NULL, |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
226 | NULL, |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
227 | 0); // 0: result in text format |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
228 | |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
229 | if(pathf) { |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
230 | free(pathf); |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
231 | } |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
232 | |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
233 | if(!result) return 1; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
234 | |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
235 | int ret = 1; |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
236 | //int nfields = PQnfields(result); |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
237 | int nrows = PQntuples(result); |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
238 | if(nrows == 1) { |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
239 | char *resource_id_str = PQgetvalue(result, 0, 0); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
240 | char *parent_id_str = PQgetvalue(result, 0, 1); |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
241 | char *iscol = PQgetvalue(result, 0, 4); |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
242 | char *lastmodified = PQgetvalue(result, 0, 5); |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
243 | char *creationdate = PQgetvalue(result, 0, 6); |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
244 | char *contentlength = PQgetvalue(result, 0, 7); |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
245 | char *res_etag = PQgetvalue(result, 0, 8); |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
246 | if(resource_id_str && parent_id_str) { |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
247 | if(util_strtoint(resource_id_str, resource_id)) { |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
248 | ret = 0; // success |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
249 | } |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
250 | // optionally get parent_id |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
251 | util_strtoint(parent_id_str, parent_id); |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
252 | } |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
253 | |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
254 | if(oid) { |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
255 | char *resoid = PQgetvalue(result, 0, 3); |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
256 | int64_t roid; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
257 | if(resoid && util_strtoint(resoid, &roid)) { |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
258 | *oid = roid; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
259 | } |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
260 | } |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
261 | |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
262 | if(iscollection && iscol) { |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
263 | *iscollection = iscol[0] == 't' ? TRUE : FALSE; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
264 | } |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
265 | |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
266 | if(s) { |
282
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
267 | pg_set_stat(s, iscol, lastmodified, creationdate, contentlength); |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
268 | } |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
269 | |
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
270 | if(etag) { |
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
271 | size_t etag_len = strlen(res_etag); |
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
272 | if(etag_len < PG_ETAG_MAXLEN) |
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
273 | memcpy(etag, res_etag, etag_len+1); |
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
274 | } |
305
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
275 | } else if(res_errno) { |
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
276 | *res_errno = ENOENT; |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
277 | } |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
278 | |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
279 | PQclear(result); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
280 | |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
281 | return ret; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
282 | } |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
283 | |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
284 | |
282
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
285 | void pg_set_stat( |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
286 | struct stat *s, |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
287 | const char *iscollection, |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
288 | const char *lastmodified, |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
289 | const char *creationdate, |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
290 | const char *contentlength) |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
291 | { |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
292 | memset(s, 0, sizeof(struct stat)); |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
293 | if(iscollection) { |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
294 | WSBool iscol = iscollection[0] == 't' ? TRUE : FALSE; |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
295 | if(iscol) { |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
296 | s->st_mode |= 0x4000; |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
297 | } |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
298 | } |
304
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
299 | s->st_mtime = pg_convert_timestamp(lastmodified); |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
300 | |
282
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
301 | if(contentlength) { |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
302 | int64_t len; |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
303 | if(util_strtoint(contentlength, &len)) { |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
304 | s->st_size = len; |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
305 | } |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
306 | } |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
307 | } |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
308 | |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
309 | static int pg_create_res( |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
310 | PgVFS *pg, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
311 | const char *resparentid_str, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
312 | const char *nodename, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
313 | int64_t *new_resource_id, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
314 | Oid *oid, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
315 | const char **resource_name, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
316 | struct stat *s) |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
317 | { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
318 | const char* params[2] = { resparentid_str, nodename }; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
319 | PGresult *result = PQexecParams( |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
320 | pg->connection, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
321 | sql_create_resource, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
322 | 2, // number of parameters |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
323 | NULL, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
324 | params, // parameter value |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
325 | NULL, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
326 | NULL, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
327 | 0); // 0: result in text format |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
328 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
329 | if(!result) return 1; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
330 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
331 | int ret = 1; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
332 | if(PQntuples(result) == 1) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
333 | // sql insert succesful |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
334 | ret = 0; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
335 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
336 | char *id_str = PQgetvalue(result, 0, 0); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
337 | char *oid_str = PQgetvalue(result, 0, 1); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
338 | char *lastmodified = PQgetvalue(result, 0, 2); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
339 | char *creationdate = PQgetvalue(result, 0, 3); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
340 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
341 | if(new_resource_id) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
342 | if(!id_str || !util_strtoint(id_str, new_resource_id)) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
343 | ret = 1; // shouldn't happen |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
344 | log_ereport(LOG_FAILURE, "Postgresql VFS: sql_create_resource: Could not convert resource_id to int"); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
345 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
346 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
347 | if(oid) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
348 | int64_t i; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
349 | if(!oid_str || !util_strtoint(oid_str, &i)) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
350 | ret = 1; // shouldn't happen |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
351 | log_ereport(LOG_FAILURE, "Postgresql VFS: sql_create_resource: Could not convert oid to int"); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
352 | } else { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
353 | *oid = i; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
354 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
355 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
356 | if(resource_name) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
357 | *resource_name = nodename; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
358 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
359 | if(s) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
360 | pg_set_stat(s, 0, lastmodified, creationdate, NULL); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
361 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
362 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
363 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
364 | PQclear(result); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
365 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
366 | return ret; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
367 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
368 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
369 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
370 | static int pg_create_col( |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
371 | PgVFS *pg, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
372 | const char *resparentid_str, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
373 | const char *nodename, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
374 | int64_t *new_resource_id, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
375 | const char **resource_name, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
376 | struct stat *s) |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
377 | { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
378 | const char* params[2] = { resparentid_str, nodename }; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
379 | PGresult *result = PQexecParams( |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
380 | pg->connection, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
381 | sql_create_collection, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
382 | 2, // number of parameters |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
383 | NULL, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
384 | params, // parameter value |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
385 | NULL, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
386 | NULL, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
387 | 0); // 0: result in text format |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
388 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
389 | if(!result) return 1; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
390 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
391 | int ret = 1; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
392 | if(PQntuples(result) == 1) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
393 | // sql insert succesful |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
394 | ret = 0; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
395 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
396 | char *id_str = PQgetvalue(result, 0, 0); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
397 | char *lastmodified = PQgetvalue(result, 0, 1); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
398 | char *creationdate = PQgetvalue(result, 0, 2); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
399 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
400 | if(new_resource_id) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
401 | if(!id_str || !util_strtoint(id_str, new_resource_id)) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
402 | ret = 1; // shouldn't happen |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
403 | log_ereport(LOG_FAILURE, "Postgresql VFS: sql_create_collection: Could not convert resource_id to int"); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
404 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
405 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
406 | if(resource_name) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
407 | *resource_name = nodename; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
408 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
409 | if(s) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
410 | pg_set_stat(s, 0, lastmodified, creationdate, NULL); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
411 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
412 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
413 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
414 | PQclear(result); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
415 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
416 | return ret; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
417 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
418 | |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
419 | int pg_create_file( |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
420 | VFSContext *ctx, |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
421 | PgVFS *pg, |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
422 | const char *path, |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
423 | int64_t *new_resource_id, |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
424 | int64_t *res_parent_id, |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
425 | Oid *oid, |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
426 | const char **resource_name, |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
427 | struct stat *s, |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
428 | WSBool collection) |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
429 | { |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
430 | char *parent_path = util_parent_path(path); |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
431 | if(!parent_path) return 1; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
432 | |
350
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
433 | size_t pathlen = strlen(path); |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
434 | char *pathf = NULL; |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
435 | if(pathlen > 1 && path[pathlen-1] == '/') { |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
436 | pathf = malloc(pathlen); |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
437 | memcpy(pathf, path, pathlen); |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
438 | pathf[pathlen-1] = 0; // remove trailing '/' |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
439 | path = pathf; |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
440 | } |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
441 | |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
442 | const char *nodename = util_resource_name(path); |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
443 | |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
444 | // resolve the parent path |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
445 | // if the parent path can't be resolved, we are done |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
446 | const char *resname; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
447 | int64_t resource_id, parent_id; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
448 | resource_id = -1; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
449 | parent_id = -1; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
450 | WSBool iscollection; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
451 | Oid unused_oid = 0; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
452 | |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
453 | int err = pg_resolve_path(pg->connection, parent_path, &parent_id, &resource_id, &unused_oid, &resname, &iscollection, NULL, NULL, &ctx->vfs_errno); |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
454 | FREE(parent_path); |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
455 | if(err) { |
344
70a9b945206a
fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
456 | ctx->vfs_errno = ENOENT; |
350
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
457 | if(pathf) free(pathf); |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
458 | return 1; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
459 | } |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
460 | |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
461 | // parent path exists, check if it is a collection |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
462 | if(!iscollection) { |
350
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
463 | if(pathf) free(pathf); |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
464 | return 1; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
465 | } |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
466 | |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
467 | // create new Resource |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
468 | char resid_str[32]; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
469 | snprintf(resid_str, 32, "%" PRId64, resource_id); // convert parent resource_id to string |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
470 | |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
471 | int ret; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
472 | if(collection) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
473 | ret = pg_create_col(pg, resid_str, nodename, new_resource_id, resource_name, s); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
474 | } else { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
475 | ret = pg_create_res(pg, resid_str, nodename, new_resource_id, oid, resource_name, s); |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
476 | } |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
477 | |
350
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
478 | if(pathf) free(pathf); |
abba342112c2
fix that pg mkdir can create directories with trailing path separators in the nodename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
479 | |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
480 | if(res_parent_id) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
481 | // resource_id is still the id of the parent from previous pg_resolve_path call |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
482 | *res_parent_id = resource_id; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
483 | } |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
484 | |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
485 | return ret; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
486 | } |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
487 | |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
488 | int pg_remove_res( |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
489 | VFSContext *ctx, |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
490 | PgVFS *pg, |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
491 | int64_t resource_id, |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
492 | Oid oid) |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
493 | { |
297
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
494 | // create transaction savepoint |
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
495 | PGresult *result = PQexec(pg->connection, "savepoint del_res;"); |
298
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
496 | ExecStatusType execStatus = PQresultStatus(result); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
497 | PQclear(result); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
498 | if(execStatus != PGRES_COMMAND_OK) { |
297
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
499 | return 1; |
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
500 | } |
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
501 | |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
502 | if(oid > 0) { |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
503 | if(lo_unlink(pg->connection, oid) != 1) { |
298
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
504 | // restore savepoint |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
505 | result = PQexec(pg->connection, "rollback to savepoint del_res;"); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
506 | PQclear(result); |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
507 | return 1; // error |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
508 | } |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
509 | } |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
510 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
511 | char resid_str[32]; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
512 | snprintf(resid_str, 32, "%" PRId64, resource_id); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
513 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
514 | const char* params[1] = { resid_str }; |
297
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
515 | result = PQexecParams( |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
516 | pg->connection, |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
517 | sql_delete_res, |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
518 | 1, // number of parameters |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
519 | NULL, |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
520 | params, // parameter value |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
521 | NULL, |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
522 | NULL, |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
523 | 0); // 0: result in text format |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
524 | |
298
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
525 | execStatus = PQresultStatus(result); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
526 | PQclear(result); |
297
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
527 | int ret = 0; |
298
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
528 | |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
529 | if(execStatus != PGRES_COMMAND_OK) { |
297
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
530 | ret = 1; |
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
531 | // restore savepoint |
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
532 | result = PQexec(pg->connection, "rollback to savepoint del_res;"); |
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
533 | PQclear(result); |
298
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
534 | } else { |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
535 | // we don't need the savepoint anymore |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
536 | result = PQexec(pg->connection, "release savepoint del_res;"); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
537 | PQclear(result); |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
538 | } |
298
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
539 | |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
540 | return ret; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
541 | } |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
542 | |
292
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
543 | int pg_update_resource(PgVFS *pg, int64_t resource_id, int64_t contentlength) { |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
544 | char resid_str[32]; |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
545 | char ctlen_str[32]; |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
546 | snprintf(resid_str, 32, "%" PRId64, resource_id); |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
547 | snprintf(ctlen_str, 32, "%" PRId64, contentlength); |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
548 | |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
549 | const char* params[2] = { resid_str, ctlen_str }; |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
550 | PGresult *result = PQexecParams( |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
551 | pg->connection, |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
552 | sql_update_resource, |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
553 | 2, // number of parameters |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
554 | NULL, |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
555 | params, // parameter value |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
556 | NULL, |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
557 | NULL, |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
558 | 0); // 0: result in text format |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
559 | |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
560 | int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1; |
297
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
561 | PQclear(result); |
292
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
562 | return ret; |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
563 | } |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
564 | |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565 | /* -------------------------- VFS functions -------------------------- */ |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567 | SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags) { |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
568 | VFS *vfs = ctx->vfs; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
569 | PgVFS *pg = vfs->instance; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
570 | |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
571 | const char *resname; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
572 | int64_t resource_id, parent_id; |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
573 | resource_id = -1; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
574 | parent_id = -1; |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
575 | WSBool iscollection; |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
576 | struct stat s; |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
577 | char etag[PG_ETAG_MAXLEN]; |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
578 | Oid oid = 0; |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
579 | if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s, etag, &ctx->vfs_errno)) { |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
580 | if((oflags & O_CREAT) == O_CREAT) { |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
581 | if(pg_create_file(ctx, pg, path, &resource_id, &parent_id, &oid, &resname, &s, FALSE)) { |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
582 | return NULL; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
583 | } |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
584 | iscollection = 0; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
585 | } else { |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
586 | return NULL; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
587 | } |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
588 | } |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
590 | VFSFile *file = pool_malloc(ctx->pool, sizeof(VFSFile)); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
591 | if(!file) { |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
592 | return NULL; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
593 | } |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
594 | PgFile *pgfile = pool_malloc(ctx->pool, sizeof(PgFile)); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
595 | if(!pgfile) { |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
596 | pool_free(ctx->pool, file); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
597 | return NULL; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
598 | } |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
599 | |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
600 | int fd = -1; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
601 | if(!iscollection) { |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
602 | if (PQstatus(pg->connection) != CONNECTION_OK) { |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
603 | fd = -2; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
604 | } |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
605 | |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
606 | int lo_mode = INV_READ; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
607 | if((oflags & O_RDWR) == O_RDWR) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
608 | lo_mode = INV_READ|INV_WRITE; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
609 | } else if((oflags & O_WRONLY) == O_WRONLY) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
610 | lo_mode = INV_WRITE; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
285
diff
changeset
|
611 | } |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
612 | fd = lo_open(pg->connection, oid, lo_mode); |
341
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
613 | int err = 0; |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
614 | if(fd < 0) { |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
615 | err = 1; |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
616 | } else if((oflags & O_TRUNC) == O_TRUNC) { |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
617 | if(lo_truncate(pg->connection, fd, 0)) { |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
618 | lo_close(pg->connection, fd); |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
619 | err = 1; |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
620 | } |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
621 | } |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
622 | |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
623 | if(err) { |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
624 | pool_free(ctx->pool, file); |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
625 | pool_free(ctx->pool, pgfile); |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
626 | return NULL; |
52831b82b3fd
add support for O_TRUNC in pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
627 | } |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
628 | } |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
629 | |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
630 | pgfile->iscollection = iscollection; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
631 | pgfile->resource_id = resource_id; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
632 | pgfile->parent_id = parent_id; |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
633 | pgfile->oid = oid; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
634 | pgfile->fd = fd; |
292
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
635 | pgfile->oflags = oflags; |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
636 | pgfile->s = s; |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
637 | memcpy(pgfile->etag, etag, PG_ETAG_MAXLEN); |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
638 | |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
639 | file->ctx = ctx; |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
640 | file->io = iscollection ? &pg_vfs_io_class : &pg_vfs_io_class; |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
641 | file->fd = -1; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
642 | file->data = pgfile; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
643 | |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
644 | return file; |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
645 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
646 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
647 | int pg_vfs_stat(VFSContext *ctx, const char *path, struct stat *buf) { |
305
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
648 | VFS *vfs = ctx->vfs; |
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
649 | PgVFS *pg = vfs->instance; |
4db64fe30588
change pg_resolve_path signature to be useable without VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
304
diff
changeset
|
650 | |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
651 | int64_t parent_id, resource_id; |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
652 | const char *resname; |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
653 | WSBool iscollection; |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
654 | return pg_resolve_path(pg->connection, path, &parent_id, &resource_id, NULL, &resname, &iscollection, buf, NULL, &ctx->vfs_errno); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
655 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
656 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
657 | int pg_vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) { |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
658 | PgFile *pgfile = fd->data; |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
659 | memcpy(buf, &pgfile->s, sizeof(struct stat)); |
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
660 | return 0; |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
661 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
662 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
663 | VFS_DIR pg_vfs_opendir(VFSContext *ctx, const char *path) { |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
664 | VFSFile *file = pg_vfs_open(ctx, path, O_RDONLY); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
665 | if(!file) return NULL; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
666 | return pg_vfs_fdopendir(ctx, file); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
667 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
668 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
669 | VFS_DIR pg_vfs_fdopendir(VFSContext *ctx, SYS_FILE fd) { |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
670 | PgFile *pg = fd->data; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
671 | if(!pg->iscollection) { |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
672 | ctx->vfs_errno = ENOTDIR; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
673 | return NULL; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
674 | } |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675 | |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
676 | VFSDir *dir = pool_malloc(ctx->pool, sizeof(VFSDir)); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
677 | if(!dir) { |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
678 | fd->io->close(fd); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
679 | ctx->vfs_errno = ENOMEM; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
680 | return NULL; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
681 | } |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
682 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
683 | PgDir *pgdir = pool_malloc(ctx->pool, sizeof(PgDir)); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
684 | if(!pgdir) { |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
685 | fd->io->close(fd); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
686 | pool_free(ctx->pool, dir); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
687 | ctx->vfs_errno = ENOMEM; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
688 | return NULL; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
689 | } |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
690 | memset(pgdir, 0, sizeof(PgDir)); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
691 | pgdir->file = fd; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
692 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
693 | dir->ctx = ctx; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
694 | dir->io = &pg_vfs_dirio_class; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
695 | dir->data = pgdir; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
696 | dir->fd = -1; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
697 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
698 | return dir; |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701 | int pg_vfs_mkdir(VFSContext *ctx, const char *path) { |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
702 | VFS *vfs = ctx->vfs; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
703 | PgVFS *pg = vfs->instance; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
704 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
705 | const char *resname; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
706 | int64_t resource_id, parent_id; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
707 | resource_id = -1; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
708 | parent_id = -1; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
709 | WSBool iscollection; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
710 | struct stat s; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
711 | Oid oid = 0; |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
712 | if(!pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s, NULL, &ctx->vfs_errno)) { |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
713 | ctx->vfs_errno = EEXIST; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
714 | return 1; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
715 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
716 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
717 | if(pg_create_file(ctx, pg, path, NULL, NULL, NULL, NULL, NULL, TRUE)) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
718 | return 1; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
719 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
720 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
721 | return 0; |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
722 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724 | int pg_vfs_unlink(VFSContext *ctx, const char *path) { |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
725 | VFS *vfs = ctx->vfs; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
726 | PgVFS *pg = vfs->instance; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
727 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
728 | const char *resname; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
729 | int64_t resource_id, parent_id; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
730 | resource_id = -1; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
731 | parent_id = -1; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
732 | WSBool iscollection; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
733 | Oid oid = 0; |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
734 | if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, NULL, NULL, &ctx->vfs_errno)) { |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
735 | return 1; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
736 | } |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
737 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
738 | if(iscollection) { |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
739 | ctx->vfs_errno = EISDIR; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
740 | return 1; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
741 | } |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
292
diff
changeset
|
742 | |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
743 | return pg_remove_res(ctx, pg, resource_id, oid); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
745 | |
295
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
746 | int pg_vfs_rmdir(VFSContext *ctx, const char *path) { |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
747 | VFS *vfs = ctx->vfs; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
748 | PgVFS *pg = vfs->instance; |
295
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
749 | |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
750 | const char *resname; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
751 | int64_t resource_id, parent_id; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
752 | resource_id = -1; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
753 | parent_id = -1; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
754 | WSBool iscollection; |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
755 | if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, NULL, &resname, &iscollection, NULL, NULL, &ctx->vfs_errno)) { |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
756 | return 1; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
757 | } |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
758 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
759 | if(!iscollection) { |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
760 | ctx->vfs_errno = ENOTDIR; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
761 | return 1; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
762 | } |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
763 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
764 | return pg_remove_res(ctx, pg, resource_id, 0); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
765 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
766 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
767 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
768 | /* -------------------------- VFS_IO functions -------------------------- */ |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | ssize_t pg_vfs_io_read(SYS_FILE fd, void *buf, size_t nbyte) { |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
771 | PgVFS *pgvfs = fd->ctx->vfs->instance; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
772 | PgFile *pg = fd->data; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
773 | return lo_read(pgvfs->connection, pg->fd, buf, nbyte); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | ssize_t pg_vfs_io_write(SYS_FILE fd, const void *buf, size_t nbyte) { |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
777 | PgVFS *pgvfs = fd->ctx->vfs->instance; |
284
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
778 | PgFile *pg = fd->data; |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
779 | return lo_write(pgvfs->connection, pg->fd, buf, nbyte); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
781 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
782 | ssize_t pg_vfs_io_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) { |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
783 | PgVFS *pgvfs = fd->ctx->vfs->instance; |
284
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
784 | PgFile *pg = fd->data; |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
785 | if(lo_lseek64(pgvfs->connection, pg->fd, offset, SEEK_SET) == -1) { |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
786 | return -1; |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
787 | } |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
788 | return lo_read(pgvfs->connection, pg->fd, buf, nbyte); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
789 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | ssize_t pg_vfs_io_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) { |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
792 | PgVFS *pgvfs = fd->ctx->vfs->instance; |
284
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
793 | PgFile *pg = fd->data; |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
794 | if(lo_lseek64(pgvfs->connection, pg->fd, offset, SEEK_SET) == -1) { |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
795 | return -1; |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
796 | } |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
797 | return lo_write(pgvfs->connection, pg->fd, buf, nbyte); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
798 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
799 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
800 | off_t pg_vfs_io_seek(SYS_FILE fd, off_t offset, int whence) { |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
801 | PgVFS *pgvfs = fd->ctx->vfs->instance; |
284
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
802 | PgFile *pg = fd->data; |
eab579b8c80d
add missing postgresql vfs io functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
283
diff
changeset
|
803 | return lo_lseek64(pgvfs->connection, pg->fd, offset, whence); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
804 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
805 | |
291
0f46b645aea4
add pg_vfs_io_tell
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
806 | off_t pg_vfs_io_tell(SYS_FILE fd) { |
0f46b645aea4
add pg_vfs_io_tell
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
807 | PgVFS *pgvfs = fd->ctx->vfs->instance; |
0f46b645aea4
add pg_vfs_io_tell
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
808 | PgFile *pg = fd->data; |
0f46b645aea4
add pg_vfs_io_tell
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
809 | return lo_tell64(pgvfs->connection, pg->fd); |
0f46b645aea4
add pg_vfs_io_tell
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
810 | } |
0f46b645aea4
add pg_vfs_io_tell
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
811 | |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
812 | void pg_vfs_io_close(SYS_FILE fd) { |
282
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
813 | pool_handle_t *pool = fd->ctx->pool; |
292
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
814 | PgVFS *pgvfs = fd->ctx->vfs->instance; |
282
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
815 | PgFile *pg = fd->data; |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
816 | |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
817 | if(pg->fd >= 0) { |
292
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
818 | if((pg->oflags & (O_WRONLY|O_RDWR)) > 0) { |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
819 | // file modified, update length and lastmodified |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
820 | off_t len = pg_vfs_io_seek(fd, 0, SEEK_END); |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
821 | if(len < 0) len = 0; |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
822 | |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
823 | pg_update_resource(pgvfs, pg->resource_id, len); |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
824 | } |
7c31bcd5b4be
update pg resource metadata on close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
291
diff
changeset
|
825 | |
283
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
826 | PgVFS *pgvfs = fd->ctx->vfs->instance; |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
827 | lo_close(pgvfs->connection, pg->fd); |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
828 | } |
25e5b771677d
minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
829 | |
282
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
830 | pool_free(pool, pg); |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
831 | pool_free(pool, fd); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
832 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
833 | |
345
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
834 | const char *pg_vfs_io_getetag(SYS_FILE fd) { |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
835 | PgFile *pg = fd->data; |
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
345
diff
changeset
|
836 | return pg->etag; |
345
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
837 | } |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
838 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
839 | /* -------------------------- VFS_DIRIO functions -------------------------- */ |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
841 | static int load_dir(VFSDir *dir, PgDir *pg) { |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
842 | VFS *vfs = dir->ctx->vfs; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
843 | PgVFS *pgvfs = vfs->instance; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
844 | PgFile *pgfd = pg->file->data; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
845 | PgDir *pgdir = dir->data; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
846 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
847 | char resid_param[32]; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
848 | snprintf(resid_param, 32, "%" PRId64, pgfd->resource_id); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
849 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
850 | const char *param = resid_param; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
851 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
852 | PGresult *result = PQexecParams( |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
853 | pgvfs->connection, |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
854 | sql_get_children, |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
855 | 1, // number of parameters |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
856 | NULL, |
281
e9dc53661df4
add pg vfs stat/fstat implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
280
diff
changeset
|
857 | ¶m, // param: parent resource_id |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
858 | NULL, |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
859 | NULL, |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
860 | 0); // 0: result in text format |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
861 | if(!result) return 1; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
862 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
863 | pgdir->result = result; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
864 | pgdir->nrows = PQntuples(result); |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
865 | return 0; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
866 | } |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
867 | |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
868 | int pg_vfs_dirio_readdir(VFS_DIR dir, VFS_ENTRY *entry, int getstat) { |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
869 | PgDir *pg = dir->data; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
870 | if(!pg->result) { |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
871 | if(load_dir(dir, pg)) { |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
872 | return 0; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
873 | } |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
874 | } |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
875 | |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
876 | if(pg->row >= pg->nrows) { |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
877 | return 0; // EOF |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
878 | } |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
879 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
880 | entry->name = PQgetvalue(pg->result, pg->row, 1); |
353
382d6c221807
fix pg_vfs_dirio_readdir not initializing some VFS_ENTRY fields
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
881 | entry->stat_errno = 0; |
382d6c221807
fix pg_vfs_dirio_readdir not initializing some VFS_ENTRY fields
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
882 | entry->stat_extra = NULL; |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
883 | |
282
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
884 | if(getstat) { |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
885 | memset(&entry->stat, 0, sizeof(struct stat)); |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
886 | |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
887 | char *iscollection = PQgetvalue(pg->result, pg->row, 2); |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
888 | char *lastmodified = PQgetvalue(pg->result, pg->row, 3); |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
889 | char *creationdate = PQgetvalue(pg->result, pg->row, 4); |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
890 | char *contentlength = PQgetvalue(pg->result, pg->row, 5); |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
891 | pg_set_stat(&entry->stat, iscollection, lastmodified, creationdate, contentlength); |
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
281
diff
changeset
|
892 | } |
279
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
893 | |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
894 | pg->row++; |
79029fe26aae
add basic postgresql vfs directory functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
895 | return 1; |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
896 | } |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
897 | |
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
898 | void pg_vfs_dirio_close(VFS_DIR dir) { |
280
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
899 | pool_handle_t *pool = dir->ctx->pool; |
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
900 | PgDir *pg = dir->data; |
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
901 | if(pg->result) { |
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
902 | PQclear(pg->result); |
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
903 | } |
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
904 | PgFile *pgfile = pg->file->data; |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
905 | |
280
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
906 | pool_free(pool, pgfile); |
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
907 | pool_free(pool, pg->file); |
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
908 | pool_free(pool, pg); |
d0d5a970292f
implement pg_vfs_dirio_close
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
279
diff
changeset
|
909 | pool_free(pool, dir); |
275
535004faa1a5
add empty postgresql VFS functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
910 | } |
304
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
911 | |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
912 | time_t pg_convert_timestamp(const char *timestamp) { |
311
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
913 | struct tm tm; |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
914 | if(pg_convert_timestamp_tm(timestamp, &tm)) { |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
915 | return 0; |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
916 | } |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
917 | #ifdef __FreeBSD__ |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
918 | return timelocal(&tm); |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
919 | #else |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
920 | return mktime(&tparts) - timezone; |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
921 | #endif |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
922 | } |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
923 | |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
924 | int pg_convert_timestamp_tm(const char *timestamp, struct tm *tm) { |
304
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
925 | // TODO: this is a very basic implementation that needs some work |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
926 | // format yyyy-mm-dd HH:MM:SS |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
927 | |
311
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
928 | memset(tm, 0, sizeof(struct tm)); |
304
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
929 | size_t len = timestamp ? strlen(timestamp) : 0; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
930 | if(len < 19) { |
311
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
931 | return 1; |
304
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
932 | } else if(len > 63) { |
311
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
933 | return 1; |
304
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
934 | } |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
935 | |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
936 | char buf[64]; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
937 | memcpy(buf, timestamp, len); |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
938 | |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
939 | char *year_str = buf; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
940 | year_str[4] = '\0'; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
941 | |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
942 | char *month_str = buf + 5; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
943 | month_str[2] = '\0'; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
944 | |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
945 | char *day_str = buf + 8; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
946 | day_str[2] = '\0'; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
947 | |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
948 | char *hour_str = buf + 11; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
949 | hour_str[2] = '\0'; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
950 | |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
951 | char *minute_str = buf + 14; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
952 | minute_str[2] = '\0'; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
953 | |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
954 | char *second_str = buf + 17; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
955 | second_str[2] = '\0'; |
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
956 | |
311
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
957 | tm->tm_year = atoi(year_str) - 1900; |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
958 | tm->tm_mon = atoi(month_str) - 1; |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
959 | tm->tm_mday = atoi(day_str); |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
960 | tm->tm_hour = atoi(hour_str); |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
961 | tm->tm_min = atoi(minute_str); |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
962 | tm->tm_sec = atoi(second_str); |
304
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
963 | |
311
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
964 | return 0; |
304
33911d44111d
add basic parser for pg timestamps
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
965 | } |