--- deliantra/server/common/map.C 2006/08/20 20:57:34 1.5 +++ deliantra/server/common/map.C 2006/08/21 02:55:10 1.6 @@ -1,6 +1,6 @@ /* * static char *rcsid_map_c = - * "$Id: map.C,v 1.5 2006/08/20 20:57:34 elmex Exp $"; + * "$Id: map.C,v 1.6 2006/08/21 02:55:10 elmex Exp $"; */ /* @@ -1222,7 +1222,8 @@ int new_save_map(mapstruct *m, int flag) { FILE *fp, *fp2; - char filename[MAX_BUF],buf[MAX_BUF], shop[MAX_BUF]; + char filename[MAX_BUF],buf[MAX_BUF], buf_s[MAX_BUF], + shop[MAX_BUF], filename_s[MAX_BUF]; int i; if (flag && !*m->path) { @@ -1253,23 +1254,23 @@ m->tmpname = tempnam_local(settings.tmpdir,NULL); strcpy(filename, m->tmpname); } - LOG(llevDebug,"Saving map %s\n",m->path); + LOG(llevDebug,"Saving map %s to %s\n", m->path, filename); m->in_memory = MAP_SAVING; - unlink (filename); // do not overwrite backups if done via hardlinks + sprintf (filename_s, "%s~", filename); /* Compress if it isn't a temporary save. Do compress if unique */ if (m->compressed && (m->unique || m->templatemap || flag)) { char buf[MAX_BUF]; strcpy(buf, uncomp[m->compressed][2]); strcat(buf, " > "); - strcat(buf, filename); + strcat(buf, filename_s); fp = popen(buf, "w"); } else - fp = fopen(filename, "w"); + fp = fopen(filename_s, "w"); if(fp == NULL) { - LOG(llevError, "Cannot write %s: %s\n", filename, strerror_local(errno)); + LOG(llevError, "Cannot write %s: %s\n", filename_s, strerror_local(errno)); return -1; } @@ -1329,12 +1330,12 @@ * If unique map, save files in the proper destination (set by * player) */ - fp2 = fp; /* save unique items into fp2 */ if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) { sprintf (buf,"%s.v00",create_items_path (m->path)); - unlink (buf); // unlink here too, so that we have backups when using hard links - if ((fp2 = fopen (buf, "w")) == NULL) { - LOG(llevError, "Can't open unique items file %s\n", buf); + LOG(llevDebug,"Saving unique items of map %s to %s\n", m->path, buf); + sprintf (buf_s, "%s~", buf); + if ((fp2 = fopen (buf_s, "w")) == NULL) { + LOG(llevError, "Can't open unique items file %s\n", buf_s); } if (flag == 2) save_objects(m, fp, fp2, 2); @@ -1343,9 +1344,11 @@ if (fp2 != NULL) { if (ftell (fp2) == 0) { fclose (fp2); + rename (buf_s, buf); unlink (buf); } else { fclose (fp2); + rename (buf_s, buf); chmod (buf, SAVE_MODE); } } @@ -1358,6 +1361,8 @@ else fclose(fp); + rename (filename_s, filename); + chmod (filename, SAVE_MODE); return 0; } @@ -1830,7 +1835,7 @@ if (QUERY_FLAG(tmp,FLAG_DAMNED)) flags |= P_NO_CLERIC; if (tmp->type == SAFE_GROUND) - flags |= P_SAFE; + flags |= P_SAFE | P_NO_CLERIC | P_NO_MAGIC; if (QUERY_FLAG(tmp,FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW;