src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 282
cfb588e27198
parent 281
e9dc53661df4
child 283
25e5b771677d
equal deleted inserted replaced
281:e9dc53661df4 282:cfb588e27198
219 if(iscollection && iscol) { 219 if(iscollection && iscol) {
220 *iscollection = iscol[0] == 't' ? TRUE : FALSE; 220 *iscollection = iscol[0] == 't' ? TRUE : FALSE;
221 } 221 }
222 222
223 if(s) { 223 if(s) {
224 memset(s, 0, sizeof(struct stat)); 224 pg_set_stat(s, iscol, lastmodified, creationdate, contentlength);
225
226 s->st_ino = *resource_id;
227 if(iscol) {
228 s->st_mode |= 0x4000;
229 }
230 if(lastmodified) {
231 // TODO
232 }
233 if(creationdate) {
234 // TODO
235 }
236 if(contentlength) {
237 int64_t len;
238 if(util_strtoint(contentlength, &len)) {
239 s->st_size = len;
240 }
241 }
242 } 225 }
243 } else { 226 } else {
244 ctx->vfs_errno = ENOENT; 227 ctx->vfs_errno = ENOENT;
245 } 228 }
246 229
247 PQclear(result); 230 PQclear(result);
248 231
249 return ret; 232 return ret;
250 } 233 }
251 234
235
236 void pg_set_stat(
237 struct stat *s,
238 const char *iscollection,
239 const char *lastmodified,
240 const char *creationdate,
241 const char *contentlength)
242 {
243 memset(s, 0, sizeof(struct stat));
244 if(iscollection) {
245 WSBool iscol = iscollection[0] == 't' ? TRUE : FALSE;
246 if(iscol) {
247 s->st_mode |= 0x4000;
248 }
249 }
250 // TODO: lastmodified, creationdate
251 if(contentlength) {
252 int64_t len;
253 if(util_strtoint(contentlength, &len)) {
254 s->st_size = len;
255 }
256 }
257 }
252 258
253 /* -------------------------- VFS functions -------------------------- */ 259 /* -------------------------- VFS functions -------------------------- */
254 260
255 SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags) { 261 SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags) {
256 const char *resname; 262 const char *resname;
336 342
337 return dir; 343 return dir;
338 } 344 }
339 345
340 int pg_vfs_mkdir(VFSContext *ctx, const char *path) { 346 int pg_vfs_mkdir(VFSContext *ctx, const char *path) {
341 347 return 1;
342 } 348 }
343 349
344 int pg_vfs_unlink(VFSContext *ctx, const char *path) { 350 int pg_vfs_unlink(VFSContext *ctx, const char *path) {
345 351 return 1;
346 } 352 }
347 353
348 int pg_vfs_rmdir(VFSContext *Ctx, const char *path) { 354 int pg_vfs_rmdir(VFSContext *Ctx, const char *path) {
349 355 return 1;
350 } 356 }
351 357
352 358
353 /* -------------------------- VFS_IO functions -------------------------- */ 359 /* -------------------------- VFS_IO functions -------------------------- */
354 360
355 ssize_t pg_vfs_io_read(SYS_FILE fd, void *buf, size_t nbyte) { 361 ssize_t pg_vfs_io_read(SYS_FILE fd, void *buf, size_t nbyte) {
356 362 return 0;
357 } 363 }
358 364
359 ssize_t pg_vfs_io_write(SYS_FILE fd, const void *buf, size_t nbyte) { 365 ssize_t pg_vfs_io_write(SYS_FILE fd, const void *buf, size_t nbyte) {
360 366 return 0;
361 } 367 }
362 368
363 ssize_t pg_vfs_io_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) { 369 ssize_t pg_vfs_io_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) {
364 370 return 0;
365 } 371 }
366 372
367 ssize_t pg_vfs_io_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) { 373 ssize_t pg_vfs_io_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) {
368 374 return 0;
369 } 375 }
370 376
371 off_t pg_vfs_io_seek(SYS_FILE fd, off_t offset, int whence) { 377 off_t pg_vfs_io_seek(SYS_FILE fd, off_t offset, int whence) {
372 378 return 0;
373 } 379 }
374 380
375 void pg_vfs_io_close(SYS_FILE fd) { 381 void pg_vfs_io_close(SYS_FILE fd) {
376 382 pool_handle_t *pool = fd->ctx->pool;
383 PgFile *pg = fd->data;
384
385 pool_free(pool, pg);
386 pool_free(pool, fd);
377 } 387 }
378 388
379 389
380 /* -------------------------- VFS_DIRIO functions -------------------------- */ 390 /* -------------------------- VFS_DIRIO functions -------------------------- */
381 391
418 return 0; // EOF 428 return 0; // EOF
419 } 429 }
420 430
421 entry->name = PQgetvalue(pg->result, pg->row, 1); 431 entry->name = PQgetvalue(pg->result, pg->row, 1);
422 432
423 // TODO: stat 433 if(getstat) {
434 memset(&entry->stat, 0, sizeof(struct stat));
435
436 char *iscollection = PQgetvalue(pg->result, pg->row, 2);
437 char *lastmodified = PQgetvalue(pg->result, pg->row, 3);
438 char *creationdate = PQgetvalue(pg->result, pg->row, 4);
439 char *contentlength = PQgetvalue(pg->result, pg->row, 5);
440 pg_set_stat(&entry->stat, iscollection, lastmodified, creationdate, contentlength);
441 }
424 442
425 pg->row++; 443 pg->row++;
426 return 1; 444 return 1;
427 } 445 }
428 446

mercurial