diff options
author | David Robillard <d@drobilla.net> | 2020-01-18 15:12:26 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-01-18 15:32:59 +0100 |
commit | d186359c86185453692871b33d9c73adabf47eb6 (patch) | |
tree | 2e81c345683cf7e9ac5556e8bfadb7741e91ffde | |
parent | c157f33ab2fd1ef5832e31eddfd339f72923810b (diff) | |
download | lilv-d186359c86185453692871b33d9c73adabf47eb6.tar.gz lilv-d186359c86185453692871b33d9c73adabf47eb6.tar.bz2 lilv-d186359c86185453692871b33d9c73adabf47eb6.zip |
Factor out writing state manifest
-rw-r--r-- | src/state.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/state.c b/src/state.c index 10f37ff..5db529c 100644 --- a/src/state.c +++ b/src/state.c @@ -850,6 +850,30 @@ remove_manifest_entry(SordWorld* world, SordModel* model, const char* subject) } static int +write_manifest(LilvWorld* world, + SerdEnv* env, + SordModel* model, + const SerdNode* file_uri) +{ + char* const path = (char*)serd_file_uri_parse(file_uri->buf, NULL); + FILE* const wfd = fopen(path, "w"); + if (!wfd) { + LILV_ERRORF("Failed to open %s for writing (%s)\n", + path, strerror(errno)); + + serd_free(path); + return 1; + } + + SerdWriter* writer = ttl_file_writer(wfd, file_uri, &env); + sord_write(model, writer, NULL); + serd_writer_free(writer); + fclose(wfd); + serd_free(path); + return 0; +} + +static int add_state_to_manifest(LilvWorld* lworld, const LilvNode* plugin_uri, const char* manifest_path, @@ -908,16 +932,7 @@ add_state_to_manifest(LilvWorld* lworld, USTR(lilv_node_as_string(plugin_uri)))); // Write manifest model to file - FILE* wfd = fopen(manifest_path, "w"); - if (wfd) { - SerdWriter* writer = ttl_file_writer(wfd, &manifest, &env); - sord_write(model, writer, NULL); - serd_writer_free(writer); - fclose(wfd); - } else { - LILV_ERRORF("Failed to open %s for writing (%s)\n", - manifest_path, strerror(errno)); - } + write_manifest(lworld, env, model, &manifest); sord_free(model); serd_node_free(&file); |