]> granicus.if.org Git - postgis/commitdiff
If GUC postgis.gdal_enabled_drivers = 'DISABLE_ALL', use of GDALOpen and GDALOpenShar...
authorBborie Park <bkpark at ucdavis.edu>
Sun, 13 Apr 2014 22:02:16 +0000 (22:02 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Sun, 13 Apr 2014 22:02:16 +0000 (22:02 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@12477 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/librtcore.h
raster/rt_core/rt_band.c
raster/rt_core/rt_util.c
raster/rt_pg/rtpg_create.c
raster/rt_pg/rtpg_gdal.c
raster/rt_pg/rtpostgis.c

index 2d0cd298d58b4c78d30fd4e18c6fda6732122ce9..c69429d4e237099b56c4274bed671f31d6c25bee 100644 (file)
@@ -2000,9 +2000,15 @@ extern void *rtalloc(size_t size);
 extern void *rtrealloc(void *mem, size_t size);
 extern void rtdealloc(void *mem);
 
+/*
+ * GDAL driver flags
+ */
 
+#define GDAL_ENABLE_ALL "ENABLE_ALL"
+#define GDAL_DISABLE_ALL "DISABLE_ALL"
 
-/* Set of functions to clamp double to int of different size
+/*
+ * Set of functions to clamp double to int of different size
  */
 
 #if !defined(POSTGIS_RASTER_WARN_ON_TRUNCATION)
@@ -2115,7 +2121,8 @@ rt_util_gdal_supported_sr(const char *srs);
  *
  * @return ES_NONE on success, ES_ERROR on error
  */
-rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
+rt_errorstate
+rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
 
 /*
        is GDAL configured correctly?
@@ -2135,6 +2142,12 @@ rt_util_gdal_register_all(int force_register_all);
 int
 rt_util_gdal_driver_registered(const char *drv);
 
+/*
+       wrapper for GDALOpen and GDALOpenShared
+*/
+GDALDatasetH
+rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared);
+
 void
 rt_util_from_ogr_envelope(
        OGREnvelope     env,
index 1e714b0321790e511c2610476bf2ed39834e5c26..c4dd6f563a84ddd8eac5307f4ab83bf81803dc92 100644 (file)
@@ -354,9 +354,9 @@ rt_band_load_offline_data(rt_band band) {
 
        rt_util_gdal_register_all(0);
        /*
-       hdsSrc = GDALOpenShared(band->data.offline.path, GA_ReadOnly);
+       hdsSrc = rt_util_gdal_open(band->data.offline.path, GA_ReadOnly, 1);
        */
-       hdsSrc = GDALOpen(band->data.offline.path, GA_ReadOnly);
+       hdsSrc = rt_util_gdal_open(band->data.offline.path, GA_ReadOnly, 0);
        if (hdsSrc == NULL) {
                rterror("rt_band_load_offline_data: Cannot open offline raster: %s", band->data.offline.path);
                return ES_ERROR;
@@ -450,8 +450,6 @@ rt_band_load_offline_data(rt_band band) {
        _rast = rt_raster_from_gdal_dataset(hdsDst);
 
        GDALClose(hdsDst);
-       /* XXX: need to find a way to clean up the GDALOpenShared datasets at end of transaction */
-       /* GDALClose(hdsSrc); */
        GDALClose(hdsSrc);
        /*
        {
index 6960c6e1726854426d44c5c352f710dba8e52ec6..4b62deedb829826e8c87bf513704937d2f86bbdf 100644 (file)
@@ -328,6 +328,8 @@ int rt_util_gdal_configured(void) {
        return 1;
 }
 
+char *gdal_enabled_drivers = NULL;
+
 /*
        register all GDAL drivers
 */
@@ -370,6 +372,27 @@ rt_util_gdal_driver_registered(const char *drv) {
        return 0;
 }
 
+/*
+       wrapper for GDALOpen and GDALOpenShared
+*/
+GDALDatasetH
+rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared) {
+       assert(NULL != fn);
+
+       if (
+               gdal_enabled_drivers != NULL &&
+               strstr(gdal_enabled_drivers, GDAL_DISABLE_ALL) != NULL
+       ) {
+               rterror("rt_util_gdal_open: Cannot open file. All GDAL drivers disabled");
+               return NULL;
+       }
+
+       if (shared)
+               return GDALOpenShared(fn, fn_access);
+       else
+               return GDALOpen(fn, fn_access);
+}
+
 void
 rt_util_from_ogr_envelope(
        OGREnvelope     env,
index 1dd5f5a6b8f6b85babdff6173f8f105eabf4fd90..67388ad52cea2447ffb714553e113092c02e9374 100644 (file)
@@ -726,7 +726,7 @@ Datum RASTER_addBandOutDB(PG_FUNCTION_ARGS)
 
        /* open outdb raster file */
        rt_util_gdal_register_all(0);
-       hdsOut = GDALOpenShared(outdbfile, GA_ReadOnly);
+       hdsOut = rt_util_gdal_open(outdbfile, GA_ReadOnly, 0);
        if (hdsOut == NULL) {
                if (pgraster != NULL) {
                        rt_raster_destroy(raster);
index e787bafd71043e3b5e563b6d30791079ada6d291..35b253df8c4b55ae977a85b76d3df89843f0cfd4 100644 (file)
@@ -97,7 +97,7 @@ Datum RASTER_fromGDALRaster(PG_FUNCTION_ARGS)
        rt_util_gdal_register_all(0);
 
        /* open GDAL raster */
-       hdsSrc = GDALOpenShared("/vsimem/in.dat", GA_ReadOnly);
+       hdsSrc = rt_util_gdal_open("/vsimem/in.dat", GA_ReadOnly, 1);
        if (hdsSrc == NULL) {
                VSIFCloseL(vsifp);
                PG_FREE_IF_COPY(bytea_data, 0);
index 0c750e702c9f9164bdaf947eee0cab93bfc643fc..387202dd3e77403ae7e5abc3f5c7490610843d47 100644 (file)
@@ -152,8 +152,8 @@ void _PG_init(void);
 /*  PostGIS raster GUCs                                             */
 /* ---------------------------------------------------------------- */
 
-static char *gdaldatapath = NULL;
-static char *gdalenableddrivers = NULL;
+static char *gdal_datapath = NULL;
+extern char *gdal_enabled_drivers;
 
 /* postgis.gdal_datapath */
 static void
@@ -173,8 +173,6 @@ rtpg_assignHookGDALDataPath(const char *newpath, void *extra) {
 }
 
 /* postgis.gdal_enabled_drivers */
-#define ENABLE_ALL "ENABLE_ALL"
-#define DISABLE_ALL "DISABLE_ALL"
 static void
 rtpg_assignHookGDALEnabledDrivers(const char *enabled_drivers, void *extra) {
        int enable_all = 0;
@@ -207,17 +205,17 @@ rtpg_assignHookGDALEnabledDrivers(const char *enabled_drivers, void *extra) {
        /* scan for keywords DISABLE_ALL and ENABLE_ALL */
        disable_all = 0;
        enable_all = 0;
-       if (strstr(enabled_drivers, DISABLE_ALL) != NULL) {
+       if (strstr(enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
                for (i = 0; i < enabled_drivers_count; i++) {
-                       if (strstr(enabled_drivers_array[i], DISABLE_ALL) != NULL) {
+                       if (strstr(enabled_drivers_array[i], GDAL_DISABLE_ALL) != NULL) {
                                disable_all = 1;
                                break;
                        }
                }
        }
-       else if (strstr(enabled_drivers, ENABLE_ALL) != NULL) {
+       else if (strstr(enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
                for (i = 0; i < enabled_drivers_count; i++) {
-                       if (strstr(enabled_drivers_array[i], ENABLE_ALL) != NULL) {
+                       if (strstr(enabled_drivers_array[i], GDAL_ENABLE_ALL) != NULL) {
                                enable_all = 1;
                                break;
                        }
@@ -308,7 +306,7 @@ _PG_init(void) {
                "postgis.gdal_datapath", /* name */
                "Path to GDAL data files.", /* short_desc */
                "Physical path to directory containing GDAL data files (sets the GDAL_DATA config option).", /* long_desc */
-               &gdaldatapath, /* valueAddr */
+               &gdal_datapath, /* valueAddr */
                NULL, /* bootValue */
                PGC_SUSET, /* GucContext context */
                0, /* int flags */
@@ -333,8 +331,8 @@ _PG_init(void) {
                "postgis.gdal_enabled_drivers", /* name */
                "Enabled GDAL drivers.", /* short_desc */
                "List of enabled GDAL drivers by short name. To enable/disable all drivers, use 'ENABLE_ALL' or 'DISABLE_ALL' (sets the GDAL_SKIP config option).", /* long_desc */
-               &gdalenableddrivers, /* valueAddr */
-               DISABLE_ALL, /* bootValue */
+               &gdal_enabled_drivers, /* valueAddr */
+               GDAL_DISABLE_ALL, /* bootValue */
                PGC_SUSET, /* GucContext context */
                GUC_LIST_INPUT, /* int flags */
 #if POSTGIS_PGSQL_VERSION >= 91