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
create_backup(char *file)
{
#if defined(HAVE_ACCESS)
char bfile[MAX_PATH];
char command[MAX_PATH*2+10];
int c = 1;
do {
sprintf(bfile, "%s.backup%d", file, c);
c++;
} while(access(bfile, R_OK) == 0);
sprintf(command, "cp %s %s", file, bfile);
system(command);
#ifdef HAVE_UNISTD_H
char bfile[MAX_PATH];
char command[MAX_PATH*2+10];
int c = 1;
do {
sprintf(bfile, "%s.backup%d", file, c);
c++;
} while(access(bfile, R_OK) == 0);
link(file, bfile);
#endif
}
@ -2017,6 +2016,12 @@ writegame(const char *filename, char quiet)
#endif
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");
if (F==NULL)
return -1;

View File

@ -154,28 +154,28 @@ static struct curse_type ct_slavery = { "slavery",
static int
cinfo_calm(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self)
{
unit *u;
const struct race * rc;
faction *f;
unused(typ);
unit *u;
const struct race * rc;
faction *f;
unused(typ);
assert(typ == TYP_UNIT);
u = (unit *)obj;
if (c->magician){
rc = c->magician->irace;
f = c->magician->faction;
if (self != 0) {
sprintf(buf, "%s mag %s", u->name, factionname(f));
} else {
sprintf(buf, "%s scheint %s zu mögen", u->name, LOC(f->locale, rc_name(rc, 1)));
}
scat(". (");
scat(itoa36(c->no));
scat(")");
return 1;
}
return 0;
assert(typ == TYP_UNIT);
u = (unit *)obj;
if (c->magician && c->magician->faction) {
rc = c->magician->irace;
f = c->magician->faction;
if (f!=NULL && self != 0) {
sprintf(buf, "%s mag %s", u->name, factionname(f));
} else {
sprintf(buf, "%s scheint %s zu mögen", u->name, LOC(lang, rc_name(rc, 1)));
}
scat(". (");
scat(itoa36(c->no));
scat(")");
return 1;
}
return 0;
}
static struct curse_type ct_calmmonster = { "calmmonster",
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)
# include <unistd.h>
# define HAVE_UNISTD_H
# define HAVE_STRCASECMP
# define HAVE_STRNCASECMP
# define HAVE_ACCESS

View File

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