[GRASS-SVN] r50486 - grass/branches/develbranch_6/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 27 03:44:16 EST 2012
Author: hamish
Date: 2012-01-27 00:44:16 -0800 (Fri, 27 Jan 2012)
New Revision: 50486
Modified:
grass/branches/develbranch_6/lib/gis/closecell.c
Log:
only try to remove previous raster map files (prior to moving in new versions from .tmp) if they actually exist. still a few more left to do.
Modified: grass/branches/develbranch_6/lib/gis/closecell.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/closecell.c 2012-01-27 08:15:03 UTC (rev 50485)
+++ grass/branches/develbranch_6/lib/gis/closecell.c 2012-01-27 08:44:16 UTC (rev 50486)
@@ -190,9 +190,12 @@
G__file_name_misc(path, "cell_misc", NULL_FILE, fcb->name,
G_mapset());
- if (remove(path) != 0)
- G_warning(_("Unable to delete prior null-cells file"));
- /* should this be fatal? how to print human readable equiv of errno? */
+ if (access(path, F_OK) == 0) {
+ if (remove(path) != 0) {
+ perror(path);
+ G_warning(_("Unable to delete prior null-cells file"));
+ }
+ }
if (fcb->null_cur_row > 0) {
/* if temporary NULL file exists, write it into cell_misc/name/null */
@@ -221,7 +224,6 @@
}
if (close(null_fd) != 0)
G_warning(_("Unable to close the null-cells file"));
- /* should this be fatal? how to print human readable equiv of errno? */
if (rename(fcb->null_temp_name, path)) {
G_warning(_("closecell: can't move [%s] to null-cells file [%s]"),
@@ -233,13 +235,18 @@
G_warning(_("Unable to delete the temporary null-cells file"));
}
}
- else {
- if (remove(fcb->null_temp_name) != 0)
- G_warning(_("Unable to delete the temporary null-cells file"));
- if (remove(path) != 0)
- G_warning(_("Unable to delete the null-cells file"));
- } /* null_cur_row > 0 */
+ else { /* no NULL data encountered */
+ if (access(fcb->null_temp_name, F_OK) == 0) {
+ if (remove(fcb->null_temp_name) != 0)
+ G_warning(_("Unable to delete the empty temporary null-cells file"));
+ }
+ if (access(path, F_OK) == 0) {
+ if (remove(path) != 0) /* duplicate? */
+ G_warning(_("Unable to delete the prior null-cells file"));
+ }
+ } /* null_cur_row > 0 */
+
if (fcb->open_mode == OPEN_NEW_COMPRESSED) { /* auto compression */
fcb->row_ptr[fcb->cellhd.rows] = lseek(fd, 0L, SEEK_CUR);
G__write_row_ptrs(fd);
@@ -265,18 +272,23 @@
strcpy(CELL_DIR, "fcell");
}
else {
- /* remove fcell/name file */
+ /* it's a CELL map, so remove fcell/name file if it exists */
G__file_name(path, "fcell", fcb->name, fcb->mapset);
- if (remove(path) != 0)
- G_warning(_("Unable to delete prior 'fcell' file"));
+ if (access(path, F_OK) == 0) {
+ if (remove(path) != 0)
+ G_warning(_("Unable to delete prior 'fcell' file"));
+ }
/* remove cell_misc/name/f_format */
G__file_name_misc(path, "cell_misc", FORMAT_FILE, fcb->name,
fcb->mapset);
- if (remove(path) != 0)
- G_warning(_("Unable to delete the %s file"), FORMAT_FILE);
+ if (access(path, F_OK) == 0) {
+ if (remove(path) != 0)
+ G_warning(_("Unable to delete the prior %s file"), FORMAT_FILE);
+ }
+
strcpy(CELL_DIR, "cell");
}
} /* if(ok) */
@@ -307,9 +319,11 @@
G_debug(5, "Moving temporary cell map into main mapset...");
G__file_name(path, CELL_DIR, fcb->name, fcb->mapset);
- if (remove(path) != 0) {
- perror(path);
- G_warning(_("Unable to delete the prior 'cell' file"));
+ if (access(path, F_OK) == 0) {
+ if (remove(path) != 0) {
+ perror(path);
+ G_warning(_("Unable to delete the prior 'cell' file"));
+ }
}
if (rename(fcb->temp_name, path)) {
More information about the grass-commit
mailing list