/*! \brief Close vector map \param Map vector map to be closed \return 0 on success \return non-zero on error */ int V1_close_nat(struct Map_info *Map) { struct Coor_info CInfo; G_debug(1, "V1_close_nat(): name = %s mapset= %s", Map->name, Map->mapset); if (!VECT_OPEN(Map)) return 1; if (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW) { Vect_coor_info(Map, &CInfo); Map->head.size = CInfo.size; dig__write_head(Map); Vect__write_head(Map); Vect_write_dblinks(Map); } /* close coor file */ fclose(Map->dig_fp.file); dig_file_free(&(Map->dig_fp)); /* delete temporary map ? */ if (Map->temporary) { if (getenv("GRASS_VECTOR_TEMPORARY") == NULL) { G_debug(1, "V1_close_nat(): temporary map <%s> TO BE DELETED", Map->name); Vect__delete(Map->name, TRUE); } else { G_debug(1, "V1_close_nat(): temporary map <%s> IS NOT DELETED", Map->name); } } return 0; }
/* check file size */ int check_coor(struct Map_info *Map) { struct Coor_info CInfo; long dif; Vect_coor_info(Map, &CInfo); dif = CInfo.size - Map->head.size; G_debug(1, "coor size in head = %ld, real coor file size= %ld", Map->head.size, CInfo.size); if (dif > 0) { G_warning(_("Coor files of vector map <%s@%s> is larger than it should be " "(%ld bytes excess)"), Map->name, Map->mapset, dif); } else if (dif < 0) { G_warning(_("Coor files of vector <%s@%s> is shorter than it should be " "(%ld bytes missing)."), Map->name, Map->mapset, -dif); } return 1; }
/*! \brief Close vector data file \param Map vector map to be closed \return 0 on success \return non-zero on error */ int Vect_close(struct Map_info *Map) { struct Coor_info CInfo; G_debug(1, "Vect_close(): name = %s, mapset = %s, format = %d, level = %d", Map->name, Map->mapset, Map->format, Map->level); /* Store support files if in write mode on level 2 */ if (strcmp(Map->mapset, G_mapset()) == 0 && Map->support_updated && Map->plus.built == GV_BUILD_ALL) { char buf[GPATH_MAX]; char file_path[GPATH_MAX]; struct stat info; /* Delete old support files if available */ sprintf(buf, "%s/%s", GRASS_VECT_DIRECTORY, Map->name); G__file_name(file_path, buf, GV_TOPO_ELEMENT, G_mapset()); if (stat(file_path, &info) == 0) /* file exists? */ unlink(file_path); G__file_name(file_path, buf, GV_SIDX_ELEMENT, G_mapset()); if (stat(file_path, &info) == 0) /* file exists? */ unlink(file_path); G__file_name(file_path, buf, GV_CIDX_ELEMENT, G_mapset()); if (stat(file_path, &info) == 0) /* file exists? */ unlink(file_path); Vect_coor_info(Map, &CInfo); Map->plus.coor_size = CInfo.size; Map->plus.coor_mtime = CInfo.mtime; Vect_save_topo(Map); /* Spatial index is not saved */ /* Vect_save_spatial_index ( Map ); */ Vect_cidx_save(Map); #ifdef HAVE_OGR if (Map->format == GV_FORMAT_OGR) V2_close_ogr(Map); #endif } if (Map->level == 2 && Map->plus.release_support) { G_debug(1, "free topology"); dig_free_plus(&(Map->plus)); if (!Map->head_only) { G_debug(1, "free spatial index"); dig_spidx_free(&(Map->plus)); } G_debug(1, "free category index"); dig_cidx_free(&(Map->plus)); } if (Map->format == GV_FORMAT_NATIVE) { G_debug(1, "close history file"); if (Map->hist_fp != NULL) fclose(Map->hist_fp); } /* Close level 1 files / data sources if not head_only */ if (!Map->head_only) { if (((*Close_array[Map->format][1]) (Map)) != 0) { G_warning(_("Unable to close vector <%s>"), Vect_get_full_name(Map)); return 1; } } G_free((void *)Map->name); Map->name = NULL; G_free((void *)Map->mapset); Map->mapset = NULL; Map->open = VECT_CLOSED_CODE; return 0; }