From 32384f9fd7e9a3ca23b6972b96b970163d77af35 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 5 Aug 2016 17:21:29 +0200 Subject: [PATCH 1/3] ignore file-not-found errors when trying to rotate logs. I suspect this is faster and safer than testing existence. --- src/util/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/log.c b/src/util/log.c index 1399ce562..26dd8cdbc 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -104,7 +104,7 @@ void log_rotate(const char *filename, int maxindex) int err, src = 1 - dst; sprintf(buffer[src], "%s.%d", filename, --maxindex); err = rename(buffer[src], buffer[dst]); - if (err != 0) { + if (err != 0 && err != ENOENT) { fprintf(stderr, "log rotate %s: %s", buffer[dst], strerror(errno)); } dst = src; From 170ca3e396eeb738ed904f917c02c94be9faae65 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 5 Aug 2016 20:09:07 +0200 Subject: [PATCH 2/3] block rename warnings, part deux --- src/util/log.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util/log.c b/src/util/log.c index 26dd8cdbc..ee3909a01 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -93,7 +93,7 @@ cp_convert(const char *format, char *buffer, size_t length, int codepage) void log_rotate(const char *filename, int maxindex) { char buffer[2][MAX_PATH]; - int dst = 1; + int err, dst = 1; assert(strlen(filename) < sizeof(buffer[0]) - 4); sprintf(buffer[dst], "%s.%d", filename, maxindex); @@ -101,16 +101,17 @@ void log_rotate(const char *filename, int maxindex) remove(buffer[dst]); while (maxindex > 0) { - int err, src = 1 - dst; + int src = 1 - dst; sprintf(buffer[src], "%s.%d", filename, --maxindex); err = rename(buffer[src], buffer[dst]); - if (err != 0 && err != ENOENT) { - fprintf(stderr, "log rotate %s: %s", buffer[dst], strerror(errno)); + if ((err != 0) && (err != ENOENT)) { + fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno)); } dst = src; } - if (rename(filename, buffer[dst]) != 0) { - fprintf(stderr, "log rotate %s: %s", buffer[dst], strerror(errno)); + err = rename(filename, buffer[dst]); + if ((err != 0) && (err != ENOENT)) { + fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno)); } } From 50860ea0ef94e1e601768126a795d1739a560cf3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 5 Aug 2016 21:58:06 +0200 Subject: [PATCH 3/3] fix reading data from very old files --- src/kernel/connection.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 41c67299a..d9f1871d0 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -651,17 +651,12 @@ int read_borders(gamedata *data) if (r != NULL) to = r; } - if ((type->read && !type->write)) { - log_warning("ignore invalid border '%s' between '%s' and '%s'\n", zText, regionname(from, 0), regionname(to, 0)); - } - else { + if (type->read) { connection *b = new_border(type, from, to); nextborder--; /* new_border erhöht den Wert */ b->id = bid; assert(bid <= nextborder); - if (type->read) { - type->read(b, data); - } + type->read(b, data); if (data->version < NOBORDERATTRIBS_VERSION) { attrib *a = NULL; int result = read_attribs(data, &a, b); @@ -675,6 +670,9 @@ int read_borders(gamedata *data) return result; } } + if (!type->write) { + log_warning("invalid border '%s' between '%s' and '%s'\n", zText, regionname(from, 0), regionname(to, 0)); + } } } return 0;