Phase 28: add project diagnostics, dependency inspection and durability regressions

This commit is contained in:
Johannes Findeisen 2026-10-27 16:58:26 +01:00
commit ca6c869b0b
16 changed files with 495 additions and 42 deletions

View file

@ -12,10 +12,13 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
typedef struct {
FILE *file;
size_t bytes;
size_t bytes, line_number, record_line;
uint64_t version;
char expected[32];
char line[1536];
char *tokens[12];
size_t count;
@ -33,6 +36,7 @@ static xtc_result line(reader *input)
int byte;
char *cursor;
input->count = 0U;
input->record_line = ++input->line_number;
while ((byte = fgetc(input->file)) != EOF) {
if (++input->bytes > 4194304U)
return XTC_ERR_FORMAT;
@ -166,7 +170,9 @@ static int decode_float(const char *text, float *value)
#define READ(tag, total) \
do { \
xtc_result read_result = line(input); \
xtc_result read_result; \
snprintf(input->expected, sizeof(input->expected), "%s", (tag)); \
read_result = line(input); \
if (read_result != XTC_OK) \
return read_result; \
if (input->count != (total) || strcmp(input->tokens[0], (tag)) != 0) \
@ -193,6 +199,7 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
xtc_graph *graph = project->graph;
READ("XTC_PROJECT", 2U);
NUM(1U, version);
input->version = version;
if (version < 1U || version > XTC_PROJECT_FORMAT_VERSION)
return XTC_ERR_UNSUPPORTED;
format_version = version;
@ -435,6 +442,8 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
return XTC_ERR_FORMAT;
if (ferror(input->file))
return XTC_ERR_IO;
input->record_line = 0;
snprintf(input->expected,sizeof(input->expected),"%s","ASSET_PATH");
if (format_version >= 7) for (i = 0; i < project->clip_count; ++i) {
char *asset = project->clips[i].asset_path;
if (asset[0] && asset[0] != '/') {
@ -444,6 +453,7 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
memcpy(asset,directory,root); asset[root] = '/';
}
}
snprintf(input->expected,sizeof(input->expected),"%s","MODEL");
return xtc_project_validate(project);
}
@ -612,36 +622,64 @@ static char *project_folder(const char *path)
* @param path NUL-terminated file or asset path.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_load(xtc_project *project, const char *path)
static xtc_result load_report(const reader *input, xtc_result result, xtc_project_diagnostic *out)
{
xtc_project_diagnostic d = {0};
d.result = result;
d.format_version = input->version;
d.line = result == XTC_OK ? 0 : input->record_line;
if (result != XTC_OK) snprintf(d.record,sizeof(d.record),"%s",input->expected);
if (result == XTC_OK) snprintf(d.message,sizeof(d.message),"Metadata valid; external media/plugins not loaded.");
else if (result == XTC_ERR_UNSUPPORTED && !strcmp(input->expected,"XTC_PROJECT"))
snprintf(d.message,sizeof(d.message),"Project format %" PRIu64 " is unsupported; this build reads versions 1..%u.",input->version,XTC_PROJECT_FORMAT_VERSION);
else if (result == XTC_ERR_UNSUPPORTED) snprintf(d.message,sizeof(d.message),"Unsupported project feature or node type; no data was discarded.");
else if (result == XTC_ERR_FORMAT && !strcmp(input->expected,"SIZE")) snprintf(d.message,sizeof(d.message),"Project exceeds the 4 MiB input limit.");
else if (result == XTC_ERR_FORMAT && !strcmp(input->expected,"MODEL")) snprintf(d.message,sizeof(d.message),"Invalid project references, IDs, graph, routing or values.");
else if (result == XTC_ERR_FORMAT) snprintf(d.message,sizeof(d.message),"Invalid, unknown or truncated record; expected %s. Unknown fields are rejected.",input->expected);
else if (result == XTC_ERR_IO) snprintf(d.message,sizeof(d.message),"Cannot read project or resolve its containing directory; check path and permissions.");
else if (result == XTC_ERR_CAPACITY) snprintf(d.message,sizeof(d.message),"Project capacity or resolved media path exceeds supported limits.");
else snprintf(d.message,sizeof(d.message),"Project load failed: %s.",xtc_result_string(result));
if (out) *out = d;
return result;
}
xtc_result xtc_project_load_diagnostic(xtc_project *project, const char *path, xtc_project_diagnostic *diagnostic)
{
xtc_project *candidate = NULL;
reader input = {0};
char *directory;
xtc_result result;
struct stat info;
snprintf(input.expected,sizeof(input.expected),"%s","OPEN");
if (project == NULL || path_length(path) == 0U)
return XTC_ERR_INVALID_ARGUMENT;
return load_report(&input,XTC_ERR_INVALID_ARGUMENT,diagnostic);
input.file = fopen(path, "rb");
if (input.file == NULL)
return XTC_ERR_IO;
if (input.file == NULL) return load_report(&input,XTC_ERR_IO,diagnostic);
if (fstat(fileno(input.file),&info) == 0 && S_ISREG(info.st_mode) && info.st_size > 4194304) {
snprintf(input.expected,sizeof(input.expected),"%s","SIZE");
fclose(input.file);
return load_report(&input,XTC_ERR_FORMAT,diagnostic);
}
{
char *canonical = realpath(path,NULL);
directory = canonical ? project_folder(canonical) : NULL;
free(canonical);
}
if (!directory) { fclose(input.file); return XTC_ERR_IO; }
if (!directory) { fclose(input.file); return load_report(&input,XTC_ERR_IO,diagnostic); }
result = xtc_project_create(&candidate);
if (result == XTC_OK)
result = read_project(&input, candidate, directory);
if (result == XTC_OK) result = read_project(&input, candidate, directory);
free(directory);
if (fclose(input.file) != 0 && result == XTC_OK)
result = XTC_ERR_IO;
if (fclose(input.file) != 0 && result == XTC_OK) result = XTC_ERR_IO;
if (result == XTC_OK) {
xtc_graph *old = project->graph;
*project = *candidate;
candidate->graph = old;
}
xtc_project_destroy(candidate);
return result;
return load_report(&input,result,diagnostic);
}
xtc_result xtc_project_load(xtc_project *project, const char *path)
{
return xtc_project_load_diagnostic(project,path,NULL);
}
/**