Sicherstellen, dass keien hardlinks automatisch übermeiert werden (unlink).

Schnelleres Backup ohne system() mit Hardlinks.
This commit is contained in:
Enno Rehling 2005-12-18 21:53:12 +00:00
parent a18ca097b9
commit 945a60a20c
4 changed files with 38 additions and 32 deletions

View File

@ -718,16 +718,15 @@ typus2race(unsigned char typus)
void void
create_backup(char *file) create_backup(char *file)
{ {
#if defined(HAVE_ACCESS) #ifdef HAVE_UNISTD_H
char bfile[MAX_PATH]; char bfile[MAX_PATH];
char command[MAX_PATH*2+10]; char command[MAX_PATH*2+10];
int c = 1; int c = 1;
do { do {
sprintf(bfile, "%s.backup%d", file, c); sprintf(bfile, "%s.backup%d", file, c);
c++; c++;
} while(access(bfile, R_OK) == 0); } while(access(bfile, R_OK) == 0);
sprintf(command, "cp %s %s", file, bfile); link(file, bfile);
system(command);
#endif #endif
} }
@ -2017,6 +2016,12 @@ writegame(const char *filename, char quiet)
#endif #endif
sprintf(buf, "%s/%s", datapath(), filename); sprintf(buf, "%s/%s", datapath(), filename);
#ifdef HAVE_UNISTD_H
if (access(buf, R_OK) == 0) {
/* make sure we don't overwrite some hardlinkedfile */
unlink(buf);
}
#endif
F = cfopen(buf, "w"); F = cfopen(buf, "w");
if (F==NULL) if (F==NULL)
return -1; return -1;

View File

@ -154,28 +154,28 @@ static struct curse_type ct_slavery = { "slavery",
static int static int
cinfo_calm(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) cinfo_calm(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self)
{ {
unit *u; unit *u;
const struct race * rc; const struct race * rc;
faction *f; faction *f;
unused(typ); unused(typ);
assert(typ == TYP_UNIT); assert(typ == TYP_UNIT);
u = (unit *)obj; u = (unit *)obj;
if (c->magician){ if (c->magician && c->magician->faction) {
rc = c->magician->irace; rc = c->magician->irace;
f = c->magician->faction; f = c->magician->faction;
if (self != 0) { if (f!=NULL && self != 0) {
sprintf(buf, "%s mag %s", u->name, factionname(f)); sprintf(buf, "%s mag %s", u->name, factionname(f));
} else { } else {
sprintf(buf, "%s scheint %s zu mögen", u->name, LOC(f->locale, rc_name(rc, 1))); sprintf(buf, "%s scheint %s zu mögen", u->name, LOC(lang, rc_name(rc, 1)));
} }
scat(". ("); scat(". (");
scat(itoa36(c->no)); scat(itoa36(c->no));
scat(")"); scat(")");
return 1; return 1;
} }
return 0; return 0;
} }
static struct curse_type ct_calmmonster = { "calmmonster", static struct curse_type ct_calmmonster = { "calmmonster",
CURSETYP_NORM, CURSE_SPREADNEVER, NO_MERGE, CURSETYP_NORM, CURSE_SPREADNEVER, NO_MERGE,

View File

@ -94,6 +94,7 @@ extern "C" {
#if defined(__USE_SVID) || defined(_BSD_SOURCE) || defined(__USE_XOPEN_EXTENDED) || defined(_BE_SETUP_H) || defined(CYGWIN) #if defined(__USE_SVID) || defined(_BSD_SOURCE) || defined(__USE_XOPEN_EXTENDED) || defined(_BE_SETUP_H) || defined(CYGWIN)
# include <unistd.h> # include <unistd.h>
# define HAVE_UNISTD_H
# define HAVE_STRCASECMP # define HAVE_STRCASECMP
# define HAVE_STRNCASECMP # define HAVE_STRNCASECMP
# define HAVE_ACCESS # define HAVE_ACCESS

View File

@ -8,7 +8,7 @@ end
function change_locales() function change_locales()
-- local localechange = { } -- local localechange = { }
local localechange = { de = { "2xwr" } } local localechange = { de = { "bLub" } }
for loc, flist in localechange do for loc, flist in localechange do
for index, name in flist do for index, name in flist do