diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-02-24 18:19:09 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-02-24 18:19:09 +0100 |
commit | dae7d843fb19aa6cf4a50ca8987f5e956dc67d79 (patch) | |
tree | e237f0c474b4bdf0cbeec83c238019237b7a2a5c | |
parent | ca8202057d58faaed3e1fa6c57adf0aa003811c4 (diff) | |
download | gnunet-dae7d843fb19aa6cf4a50ca8987f5e956dc67d79.tar.gz gnunet-dae7d843fb19aa6cf4a50ca8987f5e956dc67d79.zip |
support versioning schema drop
-rw-r--r-- | src/pq/pq_connect.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c index 70ae4fb2e..559361f32 100644 --- a/src/pq/pq_connect.c +++ b/src/pq/pq_connect.c | |||
@@ -147,21 +147,17 @@ apply_patch (struct GNUNET_PQ_Context *db, | |||
147 | const char *load_path, | 147 | const char *load_path, |
148 | unsigned int i) | 148 | unsigned int i) |
149 | { | 149 | { |
150 | size_t slen = strlen (load_path) + 10; | ||
151 | |||
152 | char buf[slen]; | ||
153 | struct GNUNET_OS_Process *psql; | 150 | struct GNUNET_OS_Process *psql; |
154 | enum GNUNET_OS_ProcessStatusType type; | 151 | enum GNUNET_OS_ProcessStatusType type; |
155 | unsigned long code; | 152 | unsigned long code; |
153 | size_t slen = strlen (load_path) + 10; | ||
154 | char buf[slen]; | ||
156 | 155 | ||
157 | GNUNET_snprintf (buf, | 156 | GNUNET_snprintf (buf, |
158 | sizeof (buf), | 157 | sizeof (buf), |
159 | "%s%04u.sql", | 158 | "%s%04u.sql", |
160 | load_path, | 159 | load_path, |
161 | i); | 160 | i); |
162 | if (GNUNET_YES != | ||
163 | GNUNET_DISK_file_test (buf)) | ||
164 | return GNUNET_NO; /* We are done */ | ||
165 | psql = GNUNET_OS_start_process (GNUNET_NO, | 161 | psql = GNUNET_OS_start_process (GNUNET_NO, |
166 | GNUNET_OS_INHERIT_STD_NONE, | 162 | GNUNET_OS_INHERIT_STD_NONE, |
167 | NULL, | 163 | NULL, |
@@ -213,7 +209,7 @@ GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db, | |||
213 | const char *load_path) | 209 | const char *load_path) |
214 | { | 210 | { |
215 | const char *load_path_suffix; | 211 | const char *load_path_suffix; |
216 | 212 | size_t slen = strlen (load_path) + 10; | |
217 | 213 | ||
218 | load_path_suffix = strrchr (load_path, '/'); | 214 | load_path_suffix = strrchr (load_path, '/'); |
219 | if (NULL == load_path_suffix) | 215 | if (NULL == load_path_suffix) |
@@ -225,13 +221,27 @@ GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db, | |||
225 | for (unsigned int i = 1; i<10000; i++) | 221 | for (unsigned int i = 1; i<10000; i++) |
226 | { | 222 | { |
227 | enum GNUNET_DB_QueryStatus qs; | 223 | enum GNUNET_DB_QueryStatus qs; |
224 | { | ||
225 | char buf[slen]; | ||
226 | |||
227 | /* First, check patch actually exists */ | ||
228 | GNUNET_snprintf (buf, | ||
229 | sizeof (buf), | ||
230 | "%s%04u.sql", | ||
231 | load_path, | ||
232 | i); | ||
233 | if (GNUNET_YES != | ||
234 | GNUNET_DISK_file_test (buf)) | ||
235 | return GNUNET_NO; /* We are done */ | ||
236 | } | ||
228 | 237 | ||
229 | /* First check with DB versioning schema if this patch was already applied, | 238 | /* Second, check with DB versioning schema if this patch was already applied, |
230 | if so, skip it. */ | 239 | if so, skip it. */ |
231 | { | 240 | { |
232 | char *patch_name; | 241 | char patch_name[slen]; |
233 | 242 | ||
234 | GNUNET_asprintf (&patch_name, | 243 | GNUNET_snprintf (patch_name, |
244 | sizeof (patch_name), | ||
235 | "%s%04u", | 245 | "%s%04u", |
236 | load_path_suffix, | 246 | load_path_suffix, |
237 | i); | 247 | i); |
@@ -265,7 +275,6 @@ GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db, | |||
265 | return GNUNET_SYSERR; | 275 | return GNUNET_SYSERR; |
266 | } | 276 | } |
267 | } | 277 | } |
268 | GNUNET_free (patch_name); | ||
269 | } | 278 | } |
270 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) | 279 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) |
271 | continue; /* patch already applied, skip it */ | 280 | continue; /* patch already applied, skip it */ |