add proper error handling for in-place restarts (Thanks Markus)
fixes #806
This commit is contained in:
parent
514265b529
commit
8c8fce82e5
@ -52,7 +52,7 @@ static bool mkdirp(const char *path) {
|
|||||||
ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
|
ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
char *copy = strdup(path);
|
char *copy = sstrdup(path);
|
||||||
/* strip trailing slashes, if any */
|
/* strip trailing slashes, if any */
|
||||||
while (copy[strlen(copy)-1] == '/')
|
while (copy[strlen(copy)-1] == '/')
|
||||||
copy[strlen(copy)-1] = '\0';
|
copy[strlen(copy)-1] = '\0';
|
||||||
|
@ -350,11 +350,22 @@ void tree_append_json(const char *filename) {
|
|||||||
/* TODO: percent of other windows are not correctly fixed at the moment */
|
/* TODO: percent of other windows are not correctly fixed at the moment */
|
||||||
FILE *f;
|
FILE *f;
|
||||||
if ((f = fopen(filename, "r")) == NULL) {
|
if ((f = fopen(filename, "r")) == NULL) {
|
||||||
LOG("Cannot open file\n");
|
LOG("Cannot open file \"%s\"\n", filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct stat stbuf;
|
||||||
|
if (fstat(fileno(f), &stbuf) != 0) {
|
||||||
|
LOG("Cannot fstat() the file\n");
|
||||||
|
fclose(f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char *buf = smalloc(stbuf.st_size);
|
||||||
|
int n = fread(buf, 1, stbuf.st_size, f);
|
||||||
|
if (n != stbuf.st_size) {
|
||||||
|
LOG("File \"%s\" could not be read entirely, not loading.\n", filename);
|
||||||
|
fclose(f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char *buf = malloc(65535); /* TODO */
|
|
||||||
int n = fread(buf, 1, 65535, f);
|
|
||||||
LOG("read %d bytes\n", n);
|
LOG("read %d bytes\n", n);
|
||||||
yajl_gen g;
|
yajl_gen g;
|
||||||
yajl_handle hand;
|
yajl_handle hand;
|
||||||
|
Loading…
Reference in New Issue
Block a user