meta: replace bluelib with fx
This commit is contained in:
@@ -5,10 +5,13 @@ add_library(libropkg SHARED ${sources})
|
||||
set_target_properties(libropkg PROPERTIES
|
||||
OUTPUT_NAME ropkg)
|
||||
target_link_libraries(libropkg
|
||||
Bluelib::Io
|
||||
Bluelib::Compress)
|
||||
FX::Runtime
|
||||
FX::Io
|
||||
FX::Compression
|
||||
SQLite3::SQLite3)
|
||||
target_include_directories(libropkg PUBLIC
|
||||
include/)
|
||||
target_compile_definitions(libropkg PRIVATE
|
||||
LIBROPKG_EXPORT=1
|
||||
LIBROPKG_STATIC=0)
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#include "config.h"
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "db.h"
|
||||
|
||||
#include <ropkg/status.h>
|
||||
|
||||
fx_result open_database(
|
||||
fx_directory *root,
|
||||
const char *path,
|
||||
int flags,
|
||||
sqlite3 **out)
|
||||
{
|
||||
fx_path *abs_path = fx_path_join_list(
|
||||
2,
|
||||
&FX_VALUE_OBJECT(fx_directory_get_path(root)),
|
||||
&FX_CSTR(path));
|
||||
if (!abs_path) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
if (fx_path_exists(abs_path) && (flags & SQLITE_OPEN_CREATE)) {
|
||||
if (fx_path_is_directory(abs_path)) {
|
||||
fx_path_unref(abs_path);
|
||||
return FX_RESULT_ERR(IS_DIRECTORY);
|
||||
}
|
||||
|
||||
fx_path_unlink(abs_path);
|
||||
}
|
||||
|
||||
sqlite3 *db = NULL;
|
||||
int err = sqlite3_open_v2(fx_path_get_cstr(abs_path), &db, flags, NULL);
|
||||
fx_path_unref(abs_path);
|
||||
|
||||
if (err != SQLITE_OK) {
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
if (db) {
|
||||
result = fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
} else {
|
||||
result = fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_NO_MEMORY);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
*out = db;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef _DB_H_
|
||||
#define _DB_H_
|
||||
|
||||
#include <fx/io/directory.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
extern fx_result open_database(
|
||||
fx_directory *root,
|
||||
const char *path,
|
||||
int flags,
|
||||
sqlite3 **out);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef ROPKG_CONFIG_H_
|
||||
#define ROPKG_CONFIG_H_
|
||||
|
||||
#endif
|
||||
@@ -1,15 +1,16 @@
|
||||
#ifndef ROPKG_INSTANCE_H_
|
||||
#define ROPKG_INSTANCE_H_
|
||||
|
||||
#include <blue/core/error.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/misc.h>
|
||||
#include <ropkg/status.h>
|
||||
|
||||
struct ropkg_instance;
|
||||
|
||||
ROPKG_API b_result
|
||||
ROPKG_API fx_result
|
||||
ropkg_instance_open(const char *path, struct ropkg_instance **out);
|
||||
ROPKG_API b_result
|
||||
ROPKG_API fx_result
|
||||
ropkg_instance_bootstrap(const char *path, struct ropkg_instance **out);
|
||||
ROPKG_API void ropkg_instance_close(struct ropkg_instance *inst);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef ROPKG_MANIFEST_H_
|
||||
#define ROPKG_MANIFEST_H_
|
||||
|
||||
#include <blue/core/error.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/misc.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <stdio.h>
|
||||
@@ -36,7 +36,7 @@ struct ropkg_manifest_value;
|
||||
ROPKG_API enum ropkg_status ropkg_manifest_create(struct ropkg_manifest **out);
|
||||
ROPKG_API void ropkg_manifest_destroy(struct ropkg_manifest *manifest);
|
||||
|
||||
ROPKG_API b_result ropkg_manifest_parse(FILE *fp, struct ropkg_manifest *dest);
|
||||
ROPKG_API fx_result ropkg_manifest_parse(FILE *fp, struct ropkg_manifest *dest);
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_manifest_get_by_name(
|
||||
struct ropkg_manifest *manifest,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef ROPKG_PACKAGE_DB_H_
|
||||
#define ROPKG_PACKAGE_DB_H_
|
||||
|
||||
#include <fx/error.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <ropkg/misc.h>
|
||||
|
||||
struct ropkg_package_db;
|
||||
|
||||
ROPKG_API fx_result ropkg_package_db_init(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_package_db **out);
|
||||
ROPKG_API fx_result ropkg_package_db_open(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_package_db **out);
|
||||
ROPKG_API void ropkg_package_db_close(struct ropkg_package_db *db);
|
||||
|
||||
#endif
|
||||
@@ -1,13 +1,18 @@
|
||||
#ifndef ROPKG_PACKAGE_H_
|
||||
#define ROPKG_PACKAGE_H_
|
||||
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/io/directory.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <ropkg/misc.h>
|
||||
|
||||
struct ropkg_reader;
|
||||
|
||||
ROPKG_API b_result
|
||||
ropkg_extract_metadata(struct ropkg_reader *reader, b_directory *dest);
|
||||
struct ropkg_package;
|
||||
|
||||
ROPKG_API fx_result ropkg_package_open(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_package **out);
|
||||
ROPKG_API fx_result ropkg_package_close(struct ropkg_package *pkg);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@ struct ropkg_pkg_expr_or;
|
||||
|
||||
ROPKG_API void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr);
|
||||
|
||||
ROPKG_API b_result
|
||||
ROPKG_API fx_result
|
||||
ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out);
|
||||
|
||||
ROPKG_API enum ropkg_pkg_expr_type ropkg_pkg_expr_get_type(
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#ifndef ROPKG_READER_H_
|
||||
#define ROPKG_READER_H_
|
||||
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <ropkg/misc.h>
|
||||
#include <ropkg/status.h>
|
||||
|
||||
struct ropkg_reader;
|
||||
struct b_cstream;
|
||||
struct fx_cstream;
|
||||
|
||||
struct ropkg_file_info {
|
||||
char f_filename[255];
|
||||
@@ -18,7 +19,7 @@ struct ropkg_file_info {
|
||||
};
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_reader_open(
|
||||
struct b_cstream *fp,
|
||||
fx_cstream *fp,
|
||||
struct ropkg_reader **out);
|
||||
ROPKG_API enum ropkg_status ropkg_reader_close(struct ropkg_reader *pkg);
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef ROPKG_REPO_MGMT_H_
|
||||
#define ROPKG_REPO_MGMT_H_
|
||||
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/misc.h>
|
||||
|
||||
struct ropkg_repo_mgmt;
|
||||
struct ropkg_repo_mgmt_channel;
|
||||
struct ropkg_repo_mgmt_component;
|
||||
|
||||
ROPKG_API fx_result
|
||||
ropkg_repo_mgmt_open(const char *path, struct ropkg_repo_mgmt **out);
|
||||
ROPKG_API fx_result
|
||||
ropkg_repo_mgmt_create(const char *path, struct ropkg_repo_mgmt **out);
|
||||
ROPKG_API void ropkg_repo_mgmt_close(struct ropkg_repo_mgmt *repo);
|
||||
|
||||
ROPKG_API void ropkg_repo_mgmt_add_package(
|
||||
struct ropkg_repo_mgmt *repo,
|
||||
const char *pkg_path);
|
||||
|
||||
ROPKG_API fx_result ropkg_repo_mgmt_open_channel(
|
||||
struct ropkg_repo_mgmt *repo,
|
||||
const char *name,
|
||||
struct ropkg_repo_mgmt_channel **out);
|
||||
ROPKG_API fx_result ropkg_repo_mgmt_create_channel(
|
||||
struct ropkg_repo_mgmt *repo,
|
||||
const char *name,
|
||||
struct ropkg_repo_mgmt_channel **out);
|
||||
ROPKG_API void ropkg_repo_mgmt_channel_close(
|
||||
struct ropkg_repo_mgmt_channel *channel);
|
||||
|
||||
ROPKG_API fx_result ropkg_repo_mgmt_channel_open_component(
|
||||
struct ropkg_repo_mgmt_channel *channel,
|
||||
const char *name,
|
||||
struct ropkg_repo_mgmt_component **out);
|
||||
ROPKG_API fx_result ropkg_repo_mgmt_channel_create_component(
|
||||
struct ropkg_repo_mgmt_channel *channel,
|
||||
const char *name,
|
||||
struct ropkg_repo_mgmt_component **out);
|
||||
ROPKG_API void ropkg_repo_mgmt_component_close(
|
||||
struct ropkg_repo_mgmt_component *component);
|
||||
|
||||
#endif
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef ROPKG_STATUS_H_
|
||||
#define ROPKG_STATUS_H_
|
||||
|
||||
#include <blue/core/error.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/misc.h>
|
||||
|
||||
#define ROPKG_ERROR_VENDOR (ropkg_error_vendor())
|
||||
|
||||
#define ROPKG_RESULT_SUCCESS B_RESULT_SUCCESS
|
||||
#define ROPKG_RESULT_SUCCESS FX_RESULT_SUCCESS
|
||||
#define ROPKG_RESULT_ERR(code) \
|
||||
b_error_with_code(ROPKG_ERROR_VENDOR, ROPKG_ERR_##code)
|
||||
#define ROPKG_RESULT_STATUS(code) b_error_with_code(ROPKG_ERROR_VENDOR, code)
|
||||
fx_error_with_code(ROPKG_ERROR_VENDOR, ROPKG_ERR_##code)
|
||||
#define ROPKG_RESULT_STATUS(code) fx_error_with_code(ROPKG_ERROR_VENDOR, code)
|
||||
|
||||
enum ropkg_status {
|
||||
ROPKG_SUCCESS = 0,
|
||||
@@ -24,12 +24,16 @@ enum ropkg_status {
|
||||
ROPKG_ERR_NAME_EXISTS,
|
||||
|
||||
ROPKG_ERR_DIR_OPEN_FAILED,
|
||||
ROPKG_ERR_INSTANCE_LOCKED,
|
||||
ROPKG_ERR_INSTANCE_DIR_CREATE_FAILED,
|
||||
ROPKG_ERR_FILE_OPEN_FAILED,
|
||||
ROPKG_ERR_INVALID_MANIFEST_FORMAT,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_ERR_INVALID_PKG_EXPR,
|
||||
ROPKG_ERR_INVALID_PKG_FILE,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
ROPKG_ERR_NO_CHANNEL,
|
||||
ROPKG_ERR_NO_COMPONENT,
|
||||
};
|
||||
|
||||
enum ropkg_error_msg {
|
||||
@@ -53,6 +57,6 @@ enum ropkg_error_msg {
|
||||
ROPKG_EMSG_INVALID_VERSION_UNKNOWN_END,
|
||||
};
|
||||
|
||||
ROPKG_API const struct b_error_vendor *ropkg_error_vendor(void);
|
||||
ROPKG_API const struct fx_error_vendor *ropkg_error_vendor(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef ROPKG_SYSTEM_STATE_H_
|
||||
#define ROPKG_SYSTEM_STATE_H_
|
||||
|
||||
#include <fx/error.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <ropkg/misc.h>
|
||||
|
||||
struct ropkg_system_state;
|
||||
|
||||
ROPKG_API fx_result ropkg_system_state_init(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_system_state **out);
|
||||
ROPKG_API fx_result ropkg_system_state_open(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_system_state **out);
|
||||
ROPKG_API void ropkg_system_state_close(struct ropkg_system_state *state);
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef ROPKG_VERSION_H_
|
||||
#define ROPKG_VERSION_H_
|
||||
|
||||
#include <blue/core/error.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/misc.h>
|
||||
#include <ropkg/status.h>
|
||||
|
||||
@@ -18,7 +18,7 @@ enum ropkg_comparison_op {
|
||||
ROPKG_OP_GREATER_EQUAL = 2,
|
||||
};
|
||||
|
||||
enum ropkg_version_release_phase {
|
||||
enum ropkg_version_unref_phase {
|
||||
ROPKG_VERSION_RELEASE_PHASE_ALPHA = 0,
|
||||
ROPKG_VERSION_RELEASE_PHASE_BETA,
|
||||
ROPKG_VERSION_RELEASE_PHASE_RC,
|
||||
@@ -28,21 +28,21 @@ enum ropkg_version_release_phase {
|
||||
ROPKG_API enum ropkg_status ropkg_version_create(struct ropkg_version **out);
|
||||
ROPKG_API void ropkg_version_destroy(struct ropkg_version *version);
|
||||
|
||||
ROPKG_API void ropkg_version_set_release_phase(
|
||||
ROPKG_API void ropkg_version_set_unref_phase(
|
||||
struct ropkg_version *version,
|
||||
enum ropkg_version_release_phase phase);
|
||||
enum ropkg_version_unref_phase phase);
|
||||
ROPKG_API void ropkg_version_set_upstream_version(
|
||||
struct ropkg_version *version,
|
||||
const unsigned int upstream_version[ROPKG_VERSION_UPSTREAM_DIGIT_MAX]);
|
||||
ROPKG_API void ropkg_version_set_version_release_phase(
|
||||
ROPKG_API void ropkg_version_set_version_unref_phase(
|
||||
struct ropkg_version *version,
|
||||
enum ropkg_version_release_phase phase,
|
||||
enum ropkg_version_unref_phase phase,
|
||||
unsigned int revision);
|
||||
ROPKG_API void ropkg_version_set_package_revision(
|
||||
struct ropkg_version *version,
|
||||
unsigned int revision);
|
||||
|
||||
ROPKG_API b_result
|
||||
ROPKG_API fx_result
|
||||
ropkg_version_parse(struct ropkg_version *version, const char *s);
|
||||
ROPKG_API size_t ropkg_version_to_string(
|
||||
const struct ropkg_version *version,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef ROPKG_WRITER_H_
|
||||
#define ROPKG_WRITER_H_
|
||||
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <ropkg/misc.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <stdio.h>
|
||||
@@ -10,14 +11,14 @@
|
||||
#define ROPKG_PATH_META "meta.tar"
|
||||
|
||||
struct ropkg_writer;
|
||||
struct b_cstream;
|
||||
struct fx_cstream;
|
||||
|
||||
struct ropkg_writer_file_info {
|
||||
size_t f_length;
|
||||
};
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_writer_open(
|
||||
struct b_cstream *fp,
|
||||
fx_cstream *fp,
|
||||
struct ropkg_writer **out);
|
||||
ROPKG_API enum ropkg_status ropkg_writer_close(struct ropkg_writer *pkg);
|
||||
|
||||
|
||||
+206
-67
@@ -1,52 +1,58 @@
|
||||
#include "instance.h"
|
||||
|
||||
#include "ropkg/system-state.h"
|
||||
|
||||
#include <ropkg/instance.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CREATE_FILE_OR_THROW(inst, path, out_file) \
|
||||
do { \
|
||||
b_result result = b_file_open( \
|
||||
fx_path *path_object = fx_path_create_from_cstr(path); \
|
||||
fx_result result = fx_file_open( \
|
||||
inst->inst_root, \
|
||||
B_RV_PATH(path), \
|
||||
B_FILE_READ_WRITE | B_FILE_CREATE, \
|
||||
path_object, \
|
||||
FX_FILE_READ_WRITE | FX_FILE_CREATE, \
|
||||
out_file); \
|
||||
fx_path_unref(path_object); \
|
||||
\
|
||||
if (b_result_is_error(result)) { \
|
||||
return b_error_with_template_caused_by_error( \
|
||||
if (fx_result_is_error(result)) { \
|
||||
return fx_error_with_template_caused_by_error( \
|
||||
ROPKG_ERROR_VENDOR, \
|
||||
ROPKG_ERR_INSTANCE_DIR_CREATE_FAILED, \
|
||||
result, \
|
||||
B_ERROR_PARAM( \
|
||||
FX_ERROR_PARAM( \
|
||||
"instancepath", \
|
||||
b_directory_get_rel_path_cstr( \
|
||||
fx_directory_get_rel_path_cstr( \
|
||||
inst->inst_root)), \
|
||||
B_ERROR_PARAM("subdirpath", path)); \
|
||||
FX_ERROR_PARAM("subdirpath", path)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CREATE_DIRECTORY_OR_THROW(inst, path, out_dir) \
|
||||
do { \
|
||||
b_result result = b_directory_open( \
|
||||
fx_path *path_object = fx_path_create_from_cstr(path); \
|
||||
fx_result result = fx_directory_open( \
|
||||
inst->inst_root, \
|
||||
B_RV_PATH(path), \
|
||||
B_DIRECTORY_OPEN_CREATE_INTERMEDIATE, \
|
||||
path_object, \
|
||||
FX_DIRECTORY_OPEN_CREATE_INTERMEDIATE, \
|
||||
out_dir); \
|
||||
fx_path_unref(path_object); \
|
||||
\
|
||||
if (b_result_is_error(result)) { \
|
||||
return b_error_with_template_caused_by_error( \
|
||||
if (fx_result_is_error(result)) { \
|
||||
return fx_error_with_template_caused_by_error( \
|
||||
ROPKG_ERROR_VENDOR, \
|
||||
ROPKG_ERR_INSTANCE_DIR_CREATE_FAILED, \
|
||||
result, \
|
||||
B_ERROR_PARAM( \
|
||||
FX_ERROR_PARAM( \
|
||||
"instancepath", \
|
||||
b_directory_get_rel_path_cstr( \
|
||||
fx_directory_get_rel_path_cstr( \
|
||||
inst->inst_root)), \
|
||||
B_ERROR_PARAM("subdirpath", path)); \
|
||||
FX_ERROR_PARAM("subdirpath", path)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static b_result bootstrap_base(struct ropkg_instance *instance)
|
||||
static fx_result bootstrap_base(struct ropkg_instance *instance)
|
||||
{
|
||||
CREATE_DIRECTORY_OR_THROW(
|
||||
instance,
|
||||
@@ -61,66 +67,70 @@ static b_result bootstrap_base(struct ropkg_instance *instance)
|
||||
ROPKG_INSTANCE_DIRPATH_DATABASE,
|
||||
&instance->inst_dir_database);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result bootstrap_config(struct ropkg_instance *instance)
|
||||
static fx_result bootstrap_config(struct ropkg_instance *instance)
|
||||
{
|
||||
b_directory *dir;
|
||||
fx_directory *dir;
|
||||
|
||||
CREATE_DIRECTORY_OR_THROW(
|
||||
instance,
|
||||
ROPKG_INSTANCE_DIRPATH_CONFIG_COLLECTION,
|
||||
ROPKG_INSTANCE_DIRPATH_CONFIG_FILES,
|
||||
&dir);
|
||||
|
||||
b_directory_release(dir);
|
||||
fx_directory_unref(dir);
|
||||
|
||||
CREATE_DIRECTORY_OR_THROW(
|
||||
instance,
|
||||
ROPKG_INSTANCE_DIRPATH_SOURCES,
|
||||
&dir);
|
||||
|
||||
b_directory_release(dir);
|
||||
fx_directory_unref(dir);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result bootstrap_cache(struct ropkg_instance *instance)
|
||||
static fx_result bootstrap_cache(struct ropkg_instance *instance)
|
||||
{
|
||||
b_directory *dir;
|
||||
fx_directory *dir;
|
||||
|
||||
CREATE_DIRECTORY_OR_THROW(
|
||||
instance,
|
||||
ROPKG_INSTANCE_DIRPATH_ARCHIVES,
|
||||
&dir);
|
||||
|
||||
b_directory_release(dir);
|
||||
fx_directory_unref(dir);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result bootstrap_database(struct ropkg_instance *instance)
|
||||
static fx_result bootstrap_database(struct ropkg_instance *instance)
|
||||
{
|
||||
b_file *file;
|
||||
fx_result result;
|
||||
|
||||
CREATE_FILE_OR_THROW(
|
||||
instance,
|
||||
result = ropkg_system_state_init(
|
||||
instance->inst_root,
|
||||
ROPKG_INSTANCE_FILEPATH_STATUS,
|
||||
&instance->inst_status);
|
||||
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = ropkg_package_db_init(
|
||||
instance->inst_root,
|
||||
ROPKG_INSTANCE_FILEPATH_AVAILABLE,
|
||||
&file);
|
||||
&instance->inst_available);
|
||||
|
||||
b_file_release(file);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
CREATE_FILE_OR_THROW(
|
||||
instance,
|
||||
ROPKG_INSTANCE_FILEPATH_INSTALLED,
|
||||
&file);
|
||||
|
||||
b_file_release(file);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
b_result ropkg_instance_open(const char *cpath, struct ropkg_instance **out)
|
||||
fx_result ropkg_instance_open(const char *cpath, struct ropkg_instance **out)
|
||||
{
|
||||
struct ropkg_instance *inst = malloc(sizeof *inst);
|
||||
if (!inst) {
|
||||
@@ -129,25 +139,79 @@ b_result ropkg_instance_open(const char *cpath, struct ropkg_instance **out)
|
||||
|
||||
memset(inst, 0x0, sizeof *inst);
|
||||
|
||||
b_path *path = b_path_create_from_cstr(cpath);
|
||||
fx_path *path = fx_path_create_from_cstr(cpath);
|
||||
if (!path) {
|
||||
free(inst);
|
||||
return ROPKG_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
b_result result = b_directory_open(NULL, path, 0, &inst->inst_root);
|
||||
b_path_release(path);
|
||||
fx_result result = fx_directory_open(NULL, path, 0, &inst->inst_root);
|
||||
fx_path_unref(path);
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
free(inst);
|
||||
return b_result_propagate(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
fx_path *path_object
|
||||
= fx_path_create_from_cstr(ROPKG_INSTANCE_FILEPATH_LOCK);
|
||||
result = fx_file_open(
|
||||
inst->inst_root,
|
||||
path_object,
|
||||
FX_FILE_WRITE_ONLY | FX_FILE_CREATE_ONLY
|
||||
| FX_FILE_DELETE_ON_CLOSE,
|
||||
&inst->inst_lock);
|
||||
fx_path_unref(path_object);
|
||||
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_error_caused_by_error(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INSTANCE_LOCKED,
|
||||
result);
|
||||
}
|
||||
|
||||
path_object = fx_path_create_from_cstr(ROPKG_INSTANCE_DIRPATH_CONFIG);
|
||||
result = fx_directory_open(
|
||||
inst->inst_root,
|
||||
path_object,
|
||||
0,
|
||||
&inst->inst_dir_config);
|
||||
fx_path_unref(path_object);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
path_object = fx_path_create_from_cstr(ROPKG_INSTANCE_DIRPATH_CACHE);
|
||||
result = fx_directory_open(
|
||||
inst->inst_root,
|
||||
path_object,
|
||||
0,
|
||||
&inst->inst_dir_cache);
|
||||
fx_path_unref(path_object);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
path_object = fx_path_create_from_cstr(ROPKG_INSTANCE_DIRPATH_DATABASE);
|
||||
result = fx_directory_open(
|
||||
inst->inst_root,
|
||||
path_object,
|
||||
0,
|
||||
&inst->inst_dir_database);
|
||||
fx_path_unref(path_object);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = inst;
|
||||
return ROPKG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
b_result ropkg_instance_bootstrap(
|
||||
fx_result ropkg_instance_bootstrap(
|
||||
const char *cpath,
|
||||
struct ropkg_instance **out)
|
||||
{
|
||||
@@ -158,44 +222,119 @@ b_result ropkg_instance_bootstrap(
|
||||
|
||||
memset(inst, 0x0, sizeof *inst);
|
||||
|
||||
b_path *path = b_path_create_from_cstr(cpath);
|
||||
fx_path *path = fx_path_create_from_cstr(cpath);
|
||||
if (!path) {
|
||||
free(inst);
|
||||
ropkg_instance_close(inst);
|
||||
return ROPKG_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
b_result result = b_directory_open(NULL, path, 0, &inst->inst_root);
|
||||
b_path_release(path);
|
||||
fx_result result = fx_directory_open(NULL, path, 0, &inst->inst_root);
|
||||
fx_path_unref(path);
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
free(inst);
|
||||
return b_error_with_template_caused_by_error(
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_error_with_template_caused_by_error(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DIR_OPEN_FAILED,
|
||||
result,
|
||||
B_ERROR_PARAM("filepath", cpath));
|
||||
FX_ERROR_PARAM("filepath", cpath));
|
||||
}
|
||||
|
||||
fx_path *path_object
|
||||
= fx_path_create_from_cstr(ROPKG_INSTANCE_FILEPATH_LOCK);
|
||||
result = fx_file_open(
|
||||
inst->inst_root,
|
||||
path_object,
|
||||
FX_FILE_READ_ONLY,
|
||||
&inst->inst_lock);
|
||||
fx_path_unref(path_object);
|
||||
if (!fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INSTANCE_LOCKED);
|
||||
}
|
||||
|
||||
result = bootstrap_base(inst);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = bootstrap_config(inst);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = bootstrap_cache(inst);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = bootstrap_database(inst);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
path_object = fx_path_create_from_cstr(ROPKG_INSTANCE_FILEPATH_LOCK);
|
||||
result = fx_file_open(
|
||||
inst->inst_root,
|
||||
path_object,
|
||||
FX_FILE_WRITE_ONLY | FX_FILE_CREATE_ONLY
|
||||
| FX_FILE_DELETE_ON_CLOSE,
|
||||
&inst->inst_lock);
|
||||
fx_path_unref(path_object);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_instance_close(inst);
|
||||
return fx_error_caused_by_error(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INSTANCE_LOCKED,
|
||||
result);
|
||||
}
|
||||
|
||||
*out = inst;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void ropkg_instance_close(struct ropkg_instance *inst)
|
||||
{
|
||||
if (inst->inst_status) {
|
||||
ropkg_system_state_close(inst->inst_status);
|
||||
inst->inst_status = NULL;
|
||||
}
|
||||
|
||||
if (inst->inst_available) {
|
||||
ropkg_package_db_close(inst->inst_available);
|
||||
inst->inst_available = NULL;
|
||||
}
|
||||
|
||||
if (inst->inst_dir_config) {
|
||||
fx_directory_unref(inst->inst_dir_config);
|
||||
inst->inst_dir_config = NULL;
|
||||
}
|
||||
|
||||
if (inst->inst_dir_cache) {
|
||||
fx_directory_unref(inst->inst_dir_cache);
|
||||
inst->inst_dir_cache = NULL;
|
||||
}
|
||||
|
||||
if (inst->inst_dir_database) {
|
||||
fx_directory_unref(inst->inst_dir_database);
|
||||
inst->inst_dir_database = NULL;
|
||||
}
|
||||
|
||||
if (inst->inst_root) {
|
||||
fx_directory_unref(inst->inst_root);
|
||||
inst->inst_root = NULL;
|
||||
}
|
||||
|
||||
if (inst->inst_lock) {
|
||||
fx_file_unref(inst->inst_lock);
|
||||
inst->inst_lock = NULL;
|
||||
}
|
||||
|
||||
free(inst);
|
||||
}
|
||||
|
||||
+18
-12
@@ -1,30 +1,36 @@
|
||||
#ifndef _ROPKG_INSTANCE_H_
|
||||
#define _ROPKG_INSTANCE_H_
|
||||
|
||||
#include <blue/io/directory.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <fx/io/file.h>
|
||||
#include <ropkg/package-db.h>
|
||||
#include <ropkg/system-state.h>
|
||||
|
||||
#define ROPKG_INSTANCE_DIRPATH_CONFIG "etc/ropkg"
|
||||
#define ROPKG_INSTANCE_DIRPATH_CACHE "var/cache/ropkg"
|
||||
#define ROPKG_INSTANCE_DIRPATH_DATABASE "var/lib/ropkg"
|
||||
|
||||
#define ROPKG_INSTANCE_DIRPATH_CONFIG_COLLECTION \
|
||||
#define ROPKG_INSTANCE_DIRPATH_CONFIG_FILES \
|
||||
ROPKG_INSTANCE_DIRPATH_CONFIG "/config"
|
||||
#define ROPKG_INSTANCE_DIRPATH_SOURCES ROPKG_INSTANCE_DIRPATH_CONFIG "/sources"
|
||||
#define ROPKG_INSTANCE_DIRPATH_AVAILABLE \
|
||||
ROPKG_INSTANCE_DIRPATH_DATABASE "/available.d"
|
||||
#define ROPKG_INSTANCE_DIRPATH_SOURCES ROPKG_INSTANCE_DIRPATH_CONFIG "/sources"
|
||||
#define ROPKG_INSTANCE_DIRPATH_ARCHIVES ROPKG_INSTANCE_DIRPATH_CACHE "/archives"
|
||||
|
||||
#define ROPKG_INSTANCE_FILEPATH_INSTALLED \
|
||||
ROPKG_INSTANCE_DIRPATH_DATABASE "/installed"
|
||||
#define ROPKG_INSTANCE_FILEPATH_STATUS \
|
||||
ROPKG_INSTANCE_DIRPATH_DATABASE "/status.rodb"
|
||||
#define ROPKG_INSTANCE_FILEPATH_AVAILABLE \
|
||||
ROPKG_INSTANCE_DIRPATH_DATABASE "/available"
|
||||
ROPKG_INSTANCE_DIRPATH_DATABASE "/available.rodb"
|
||||
#define ROPKG_INSTANCE_FILEPATH_LOCK ROPKG_INSTANCE_DIRPATH_DATABASE "/lock"
|
||||
|
||||
struct ropkg_instance {
|
||||
b_directory *inst_root;
|
||||
fx_directory *inst_root;
|
||||
|
||||
b_directory *inst_dir_config;
|
||||
b_directory *inst_dir_cache;
|
||||
b_directory *inst_dir_database;
|
||||
fx_file *inst_lock;
|
||||
fx_directory *inst_dir_config;
|
||||
fx_directory *inst_dir_cache;
|
||||
fx_directory *inst_dir_database;
|
||||
|
||||
struct ropkg_system_state *inst_status;
|
||||
struct ropkg_package_db *inst_available;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+49
-49
@@ -1,6 +1,6 @@
|
||||
#include "manifest.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <fx/string.h>
|
||||
#include <ropkg/manifest.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -51,26 +51,26 @@ enum ropkg_status ropkg_manifest_create(struct ropkg_manifest **out)
|
||||
|
||||
void ropkg_manifest_destroy(struct ropkg_manifest *manifest)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_back(&manifest->m_values);
|
||||
fx_queue_entry *entry = fx_queue_pop_back(&manifest->m_values);
|
||||
while (entry) {
|
||||
struct ropkg_manifest_value *value
|
||||
= b_unbox(struct ropkg_manifest_value, entry, v_entry);
|
||||
= fx_unbox(struct ropkg_manifest_value, entry, v_entry);
|
||||
ropkg_manifest_value_destroy(value);
|
||||
entry = b_queue_pop_back(&manifest->m_values);
|
||||
entry = fx_queue_pop_back(&manifest->m_values);
|
||||
}
|
||||
|
||||
free(manifest);
|
||||
}
|
||||
|
||||
static b_result create_manifest_value(
|
||||
b_string *name,
|
||||
b_string *value,
|
||||
static fx_result create_manifest_value(
|
||||
fx_string *name,
|
||||
fx_string *value,
|
||||
struct ropkg_manifest_value **out)
|
||||
{
|
||||
const char *name_cstr = b_string_ptr(name);
|
||||
const char *name_cstr = fx_string_get_cstr(name);
|
||||
enum ropkg_manifest_value_id id = value_id_from_string(name_cstr);
|
||||
|
||||
const char *value_cstr = b_string_ptr(value);
|
||||
const char *value_cstr = fx_string_get_cstr(value);
|
||||
char *ep;
|
||||
size_t v = strtoull(value_cstr, &ep, 10);
|
||||
struct ropkg_manifest_value *result = NULL;
|
||||
@@ -103,14 +103,14 @@ static b_result create_manifest_value(
|
||||
}
|
||||
|
||||
if (status != ROPKG_SUCCESS) {
|
||||
return b_error_with_code(ROPKG_ERROR_VENDOR, status);
|
||||
return fx_error_with_code(ROPKG_ERROR_VENDOR, status);
|
||||
}
|
||||
|
||||
*out = result;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
b_result ropkg_manifest_parse(FILE *fp, struct ropkg_manifest *dest)
|
||||
fx_result ropkg_manifest_parse(FILE *fp, struct ropkg_manifest *dest)
|
||||
{
|
||||
enum parser_state {
|
||||
PARSER_STATE_NAME,
|
||||
@@ -118,9 +118,9 @@ b_result ropkg_manifest_parse(FILE *fp, struct ropkg_manifest *dest)
|
||||
} parser_state = PARSER_STATE_NAME;
|
||||
|
||||
enum ropkg_status status = ROPKG_SUCCESS;
|
||||
b_result result = B_RESULT_SUCCESS;
|
||||
b_string *name = b_string_create();
|
||||
b_string *value_string = b_string_create();
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
fx_string *name = fx_string_create();
|
||||
fx_string *value_string = fx_string_create();
|
||||
struct ropkg_manifest_value *value = NULL;
|
||||
char s[2] = {0};
|
||||
|
||||
@@ -137,7 +137,7 @@ b_result ropkg_manifest_parse(FILE *fp, struct ropkg_manifest *dest)
|
||||
}
|
||||
|
||||
s[0] = c;
|
||||
b_string_append_cstr(value_string, s);
|
||||
fx_string_append_cstr(value_string, s);
|
||||
continue;
|
||||
case '\n':
|
||||
if (parser_state == PARSER_STATE_NAME) {
|
||||
@@ -149,50 +149,50 @@ b_result ropkg_manifest_parse(FILE *fp, struct ropkg_manifest *dest)
|
||||
name,
|
||||
value_string,
|
||||
&value);
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
||||
status = ropkg_manifest_put(dest, value);
|
||||
if (status != ROPKG_SUCCESS) {
|
||||
result = b_error_with_code(
|
||||
result = fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
status);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
||||
b_string_clear(name);
|
||||
b_string_clear(value_string);
|
||||
fx_string_clear(name);
|
||||
fx_string_clear(value_string);
|
||||
parser_state = PARSER_STATE_NAME;
|
||||
break;
|
||||
case ' ':
|
||||
case '\t':
|
||||
if (parser_state == PARSER_STATE_NAME
|
||||
&& b_string_get_size(name, 0) == 0) {
|
||||
&& fx_string_get_size(name, 0) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (parser_state == PARSER_STATE_VALUE
|
||||
&& b_string_get_size(value_string, 0) == 0) {
|
||||
&& fx_string_get_size(value_string, 0) == 0) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
s[0] = c;
|
||||
|
||||
if (parser_state == PARSER_STATE_NAME) {
|
||||
b_string_append_cstr(name, s);
|
||||
fx_string_append_cstr(name, s);
|
||||
} else {
|
||||
b_string_append_cstr(value_string, s);
|
||||
fx_string_append_cstr(value_string, s);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b_string_release(name);
|
||||
b_string_release(value_string);
|
||||
fx_string_unref(name);
|
||||
fx_string_unref(value_string);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -202,17 +202,17 @@ enum ropkg_status ropkg_manifest_get_by_name(
|
||||
const char *name,
|
||||
struct ropkg_manifest_value **out)
|
||||
{
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach(&it, &manifest->m_values)
|
||||
{
|
||||
struct ropkg_manifest_value *value = b_unbox(
|
||||
struct ropkg_manifest_value,
|
||||
it.entry,
|
||||
v_entry);
|
||||
fx_queue_entry *entry = fx_queue_first(&manifest->m_values);
|
||||
while (entry) {
|
||||
|
||||
struct ropkg_manifest_value *value
|
||||
= fx_unbox(struct ropkg_manifest_value, entry, v_entry);
|
||||
if (value->v_name && !strcmp(value->v_name, name)) {
|
||||
*out = value;
|
||||
return ROPKG_SUCCESS;
|
||||
}
|
||||
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return ROPKG_ERR_NO_ENTRY;
|
||||
@@ -223,18 +223,18 @@ enum ropkg_status ropkg_manifest_get_by_id(
|
||||
enum ropkg_manifest_value_id id,
|
||||
struct ropkg_manifest_value **out)
|
||||
{
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach(&it, &manifest->m_values)
|
||||
{
|
||||
struct ropkg_manifest_value *value = b_unbox(
|
||||
struct ropkg_manifest_value,
|
||||
it.entry,
|
||||
v_entry);
|
||||
fx_queue_entry *entry = fx_queue_first(&manifest->m_values);
|
||||
while (entry) {
|
||||
|
||||
struct ropkg_manifest_value *value
|
||||
= fx_unbox(struct ropkg_manifest_value, entry, v_entry);
|
||||
if (value->v_id != ROPKG_MANIFEST_VALUE_N_NONE
|
||||
&& value->v_id == id) {
|
||||
*out = value;
|
||||
return ROPKG_SUCCESS;
|
||||
}
|
||||
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return ROPKG_ERR_NO_ENTRY;
|
||||
@@ -261,7 +261,7 @@ enum ropkg_status ropkg_manifest_put(
|
||||
return ROPKG_ERR_NAME_EXISTS;
|
||||
}
|
||||
|
||||
b_queue_push_back(&manifest->m_values, &value->v_entry);
|
||||
fx_queue_push_back(&manifest->m_values, &value->v_entry);
|
||||
|
||||
return ROPKG_SUCCESS;
|
||||
}
|
||||
@@ -269,24 +269,24 @@ enum ropkg_status ropkg_manifest_put(
|
||||
const struct ropkg_manifest_value *ropkg_manifest_get_first_value(
|
||||
const struct ropkg_manifest *manifest)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&manifest->m_values);
|
||||
fx_queue_entry *entry = fx_queue_first(&manifest->m_values);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct ropkg_manifest_value, entry, v_entry);
|
||||
return fx_unbox(struct ropkg_manifest_value, entry, v_entry);
|
||||
}
|
||||
|
||||
const struct ropkg_manifest_value *ropkg_manifest_get_next_value(
|
||||
const struct ropkg_manifest *manifest,
|
||||
const struct ropkg_manifest_value *value)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_next(&value->v_entry);
|
||||
fx_queue_entry *entry = fx_queue_next(&value->v_entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct ropkg_manifest_value, entry, v_entry);
|
||||
return fx_unbox(struct ropkg_manifest_value, entry, v_entry);
|
||||
}
|
||||
|
||||
enum ropkg_status ropkg_manifest_value_create_int_with_name(
|
||||
@@ -302,7 +302,7 @@ enum ropkg_status ropkg_manifest_value_create_int_with_name(
|
||||
memset(vp, 0x0, sizeof *vp);
|
||||
|
||||
vp->v_type = ROPKG_MANIFEST_VALUE_T_INT;
|
||||
vp->v_name = b_strdup(name);
|
||||
vp->v_name = fx_strdup(name);
|
||||
|
||||
if (!vp->v_name) {
|
||||
free(vp);
|
||||
@@ -349,14 +349,14 @@ enum ropkg_status ropkg_manifest_value_create_string_with_name(
|
||||
memset(vp, 0x0, sizeof *vp);
|
||||
|
||||
vp->v_type = ROPKG_MANIFEST_VALUE_T_STRING;
|
||||
vp->v_name = b_strdup(vp->v_name);
|
||||
vp->v_name = fx_strdup(vp->v_name);
|
||||
|
||||
if (!vp->v_name) {
|
||||
free(vp);
|
||||
return ROPKG_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
vp->v_value.s = b_strdup(value);
|
||||
vp->v_value.s = fx_strdup(value);
|
||||
if (!vp->v_value.s) {
|
||||
free(vp);
|
||||
return ROPKG_ERR_NO_MEMORY;
|
||||
@@ -380,7 +380,7 @@ enum ropkg_status ropkg_manifest_value_create_string_with_id(
|
||||
vp->v_type = ROPKG_MANIFEST_VALUE_T_STRING;
|
||||
vp->v_id = id;
|
||||
|
||||
vp->v_value.s = b_strdup(value);
|
||||
vp->v_value.s = fx_strdup(value);
|
||||
if (!vp->v_value.s) {
|
||||
free(vp);
|
||||
return ROPKG_ERR_NO_MEMORY;
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#ifndef _MANIFEST_H_
|
||||
#define _MANIFEST_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <fx/queue.h>
|
||||
#include <ropkg/manifest.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -9,7 +9,7 @@ struct ropkg_manifest_value {
|
||||
enum ropkg_manifest_value_type v_type;
|
||||
enum ropkg_manifest_value_id v_id;
|
||||
char *v_name;
|
||||
b_queue_entry v_entry;
|
||||
fx_queue_entry v_entry;
|
||||
|
||||
union {
|
||||
size_t i;
|
||||
@@ -18,7 +18,7 @@ struct ropkg_manifest_value {
|
||||
};
|
||||
|
||||
struct ropkg_manifest {
|
||||
b_queue m_values;
|
||||
fx_queue m_values;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
#include <fx/io/directory.h>
|
||||
#include <fx/io/path.h>
|
||||
#include <ropkg/package-db.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <sqlite3.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ropkg_package_db {
|
||||
sqlite3 *db_connection;
|
||||
};
|
||||
|
||||
static fx_result init_database_schema(sqlite3 *db)
|
||||
{
|
||||
const char *sql = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = 0;
|
||||
|
||||
sql = "CREATE TABLE repo ("
|
||||
"name TEXT PRIMARY KEY,"
|
||||
"description TEXT,"
|
||||
"protocol TEXT NOT NULL,"
|
||||
"channel TEXT NOT NULL);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sql = "CREATE TABLE repo_component ("
|
||||
"repo_name TEXT NOT NULL,"
|
||||
"channel_name TEXT NOT NULL,"
|
||||
"PRIMARY KEY (repo_name, channel_name));";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sql = "CREATE TABLE package ("
|
||||
"name TEXT NOT NULL,"
|
||||
"arch TEXT NOT NULL,"
|
||||
"version TEXT NOT NULL,"
|
||||
"description TEXT,"
|
||||
"priority TEXT,"
|
||||
"category TEXT,"
|
||||
"maintainer TEXT NOT NULL,"
|
||||
"provides TEXT,"
|
||||
"dependencies TEXT,"
|
||||
"recommends TEXT,"
|
||||
"suggests TEXT,"
|
||||
"conflicts TEXT,"
|
||||
"enhances TEXT,"
|
||||
"repo_name TEXT NOT NULL,"
|
||||
"channel_name TEXT NOT NULL,"
|
||||
"PRIMARY KEY(name, arch, version, repo_name, channel_name));";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result create_database(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
sqlite3 **out)
|
||||
{
|
||||
fx_path *abs_path = fx_path_join_list(
|
||||
2,
|
||||
&FX_VALUE_OBJECT(fx_directory_get_path(dir)),
|
||||
&FX_CSTR(path));
|
||||
if (!abs_path) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
if (fx_path_exists(abs_path)) {
|
||||
if (fx_path_is_directory(abs_path)) {
|
||||
fx_path_unref(abs_path);
|
||||
return FX_RESULT_ERR(IS_DIRECTORY);
|
||||
}
|
||||
|
||||
fx_path_unlink(abs_path);
|
||||
}
|
||||
|
||||
sqlite3 *db = NULL;
|
||||
int err = sqlite3_open_v2(
|
||||
fx_path_get_cstr(abs_path),
|
||||
&db,
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
|
||||
NULL);
|
||||
fx_path_unref(abs_path);
|
||||
|
||||
if (err != SQLITE_OK) {
|
||||
if (db) {
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
/* TODO check err */
|
||||
return FX_RESULT_ERR(IO_FAILURE);
|
||||
}
|
||||
|
||||
fx_result result = init_database_schema(db);
|
||||
if (fx_result_is_error(result)) {
|
||||
sqlite3_close(db);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = db;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_package_db_init(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_package_db **out)
|
||||
{
|
||||
struct ropkg_package_db *db = malloc(sizeof *db);
|
||||
if (!db) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(db, 0x0, sizeof *db);
|
||||
|
||||
fx_result result = create_database(dir, path, &db->db_connection);
|
||||
if (fx_result_is_error(result)) {
|
||||
free(db);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = db;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_package_db_open(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_package_db **out)
|
||||
{
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void ropkg_package_db_close(struct ropkg_package_db *db)
|
||||
{
|
||||
}
|
||||
+129
-36
@@ -1,78 +1,90 @@
|
||||
#include "reader.h"
|
||||
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/io/directory.h>
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <fx/compression/zstd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <ropkg/package.h>
|
||||
#include <ropkg/reader.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static b_result extract_file(
|
||||
struct ropkg_package {
|
||||
fx_file *pkg_file;
|
||||
fx_cstream *pkg_file_cstream;
|
||||
|
||||
struct ropkg_reader *pkg_reader;
|
||||
fx_directory *pkg_metadata;
|
||||
};
|
||||
|
||||
static fx_result extract_file(
|
||||
struct ropkg_reader *pkg,
|
||||
const char *path_cstr,
|
||||
b_directory *dest)
|
||||
fx_directory *dest)
|
||||
{
|
||||
b_path *path = b_path_create_from_cstr(path_cstr);
|
||||
fx_path *path = fx_path_create_from_cstr(path_cstr);
|
||||
if (!path) {
|
||||
return ROPKG_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
b_path *dir_path = NULL;
|
||||
b_path_get_directory(path, &dir_path);
|
||||
fx_path *dir_path = NULL;
|
||||
fx_path_get_directory(path, &dir_path);
|
||||
if (!dir_path) {
|
||||
b_path_release(path);
|
||||
fx_path_unref(path);
|
||||
return ROPKG_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
b_result result = B_RESULT_SUCCESS;
|
||||
if (b_path_length(dir_path) > 0) {
|
||||
b_directory *parent_dir;
|
||||
result = b_directory_open(
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
if (fx_path_length(dir_path) > 0) {
|
||||
fx_directory *parent_dir;
|
||||
result = fx_directory_open(
|
||||
dest,
|
||||
dir_path,
|
||||
B_DIRECTORY_OPEN_CREATE_INTERMEDIATE,
|
||||
FX_DIRECTORY_OPEN_CREATE_INTERMEDIATE,
|
||||
&parent_dir);
|
||||
b_directory_release(parent_dir);
|
||||
fx_directory_unref(parent_dir);
|
||||
}
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
b_file *dest_file = NULL;
|
||||
result = b_file_open(
|
||||
fx_file *dest_file = NULL;
|
||||
result = fx_file_open(
|
||||
dest,
|
||||
path,
|
||||
B_FILE_WRITE_ONLY | B_FILE_CREATE | B_FILE_BINARY,
|
||||
FX_FILE_WRITE_ONLY | FX_FILE_CREATE | FX_FILE_BINARY,
|
||||
&dest_file);
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
char data[] = "Hello";
|
||||
size_t nr_written = 0;
|
||||
b_file_write(dest_file, 0, sizeof data, data, &nr_written);
|
||||
b_file_release(dest_file);
|
||||
fx_file_write(dest_file, 0, sizeof data, data, &nr_written);
|
||||
fx_file_unref(dest_file);
|
||||
|
||||
end:
|
||||
b_path_release(path);
|
||||
b_path_release(dir_path);
|
||||
fx_path_unref(path);
|
||||
fx_path_unref(dir_path);
|
||||
return result;
|
||||
}
|
||||
|
||||
static b_result extract_subpackage(
|
||||
static fx_result extract_subpackage(
|
||||
struct ropkg_reader *pkg,
|
||||
const char *name,
|
||||
b_directory *dest)
|
||||
fx_directory *dest)
|
||||
{
|
||||
b_directory *dest_subdir;
|
||||
b_result result = b_directory_open(
|
||||
fx_directory *dest_subdir;
|
||||
fx_result result = fx_directory_open(
|
||||
dest,
|
||||
B_RV_PATH(name),
|
||||
B_DIRECTORY_OPEN_CREATE,
|
||||
FX_RV_PATH(name),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&dest_subdir);
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
b_cstream_begin_compressed_section(pkg->r_stream, NULL);
|
||||
fx_cstream_begin_compressed_section(pkg->r_stream, NULL);
|
||||
|
||||
struct ropkg_reader *subpkg = NULL;
|
||||
enum ropkg_status status = ropkg_reader_open(pkg->r_stream, &subpkg);
|
||||
@@ -85,7 +97,7 @@ static b_result extract_subpackage(
|
||||
const struct ropkg_file_info *file
|
||||
= ropkg_reader_current_file(subpkg);
|
||||
result = extract_file(subpkg, file->f_filename, dest_subdir);
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -97,13 +109,13 @@ static b_result extract_subpackage(
|
||||
}
|
||||
|
||||
end:
|
||||
b_cstream_end_compressed_section(pkg->r_stream, NULL, NULL);
|
||||
fx_cstream_end_compressed_section(pkg->r_stream, NULL, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
b_result ropkg_extract_metadata(struct ropkg_reader *pkg, b_directory *dest)
|
||||
static fx_result extract_metadata(struct ropkg_reader *pkg, fx_directory *dest)
|
||||
{
|
||||
b_result result = B_RESULT_SUCCESS;
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
|
||||
while (!ropkg_reader_eof(pkg)) {
|
||||
const struct ropkg_file_info *file
|
||||
@@ -117,7 +129,7 @@ b_result ropkg_extract_metadata(struct ropkg_reader *pkg, b_directory *dest)
|
||||
result = extract_subpackage(pkg, "control", dest);
|
||||
}
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -130,3 +142,84 @@ b_result ropkg_extract_metadata(struct ropkg_reader *pkg, b_directory *dest)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
fx_result ropkg_package_open(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_package **out)
|
||||
{
|
||||
struct ropkg_package *pkg = malloc(sizeof *pkg);
|
||||
if (!pkg) {
|
||||
return ROPKG_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(pkg, 0x0, sizeof *pkg);
|
||||
|
||||
fx_result result = fx_file_open(
|
||||
dir,
|
||||
FX_RV_PATH(path),
|
||||
FX_FILE_READ_ONLY | FX_FILE_BINARY,
|
||||
&pkg->pkg_file);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_package_close(pkg);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
fx_status bstatus = fx_cstream_open(
|
||||
pkg->pkg_file,
|
||||
FX_TYPE_ZSTD_COMPRESSOR,
|
||||
FX_COMPRESSOR_MODE_DECOMPRESS,
|
||||
&pkg->pkg_file_cstream);
|
||||
if (!FX_OK(bstatus)) {
|
||||
ropkg_package_close(pkg);
|
||||
return FX_RESULT_STATUS(bstatus);
|
||||
}
|
||||
|
||||
enum ropkg_status status
|
||||
= ropkg_reader_open(pkg->pkg_file_cstream, &pkg->pkg_reader);
|
||||
if (status != ROPKG_SUCCESS) {
|
||||
ropkg_package_close(pkg);
|
||||
return ROPKG_RESULT_STATUS(status);
|
||||
}
|
||||
|
||||
result = fx_directory_open_temp(&pkg->pkg_metadata);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_package_close(pkg);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = extract_metadata(pkg->pkg_reader, pkg->pkg_metadata);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_package_close(pkg);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = pkg;
|
||||
return ROPKG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_package_close(struct ropkg_package *pkg)
|
||||
{
|
||||
if (pkg->pkg_reader) {
|
||||
ropkg_reader_close(pkg->pkg_reader);
|
||||
pkg->pkg_reader = NULL;
|
||||
}
|
||||
|
||||
if (pkg->pkg_file_cstream) {
|
||||
fx_cstream_unref(pkg->pkg_file_cstream);
|
||||
pkg->pkg_file_cstream = NULL;
|
||||
}
|
||||
|
||||
if (pkg->pkg_file) {
|
||||
fx_file_unref(pkg->pkg_file);
|
||||
pkg->pkg_file = NULL;
|
||||
}
|
||||
|
||||
if (pkg->pkg_metadata) {
|
||||
fx_directory_unref(pkg->pkg_metadata);
|
||||
pkg->pkg_metadata = NULL;
|
||||
}
|
||||
|
||||
free(pkg);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
+70
-69
@@ -1,8 +1,8 @@
|
||||
#include "pkg-expr.h"
|
||||
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/object/string.h>
|
||||
#include <ctype.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -22,52 +22,52 @@ enum parse_state {
|
||||
|
||||
struct parse_ctx {
|
||||
const char *ctx_str;
|
||||
b_string *ctx_temp;
|
||||
fx_string *ctx_temp;
|
||||
enum parse_state ctx_state;
|
||||
size_t ctx_i;
|
||||
b_queue ctx_stack, ctx_queue;
|
||||
fx_queue ctx_stack, ctx_queue;
|
||||
};
|
||||
|
||||
static struct ropkg_pkg_expr *parse_ctx_peek_stack(struct parse_ctx *ctx)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&ctx->ctx_stack);
|
||||
fx_queue_entry *entry = fx_queue_last(&ctx->ctx_stack);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct ropkg_pkg_expr, entry, expr_entry);
|
||||
return fx_unbox(struct ropkg_pkg_expr, entry, expr_entry);
|
||||
}
|
||||
|
||||
static struct ropkg_pkg_expr *parse_ctx_pop(struct parse_ctx *ctx)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_back(&ctx->ctx_stack);
|
||||
fx_queue_entry *entry = fx_queue_pop_back(&ctx->ctx_stack);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct ropkg_pkg_expr, entry, expr_entry);
|
||||
return fx_unbox(struct ropkg_pkg_expr, entry, expr_entry);
|
||||
}
|
||||
|
||||
static void parse_ctx_push(struct parse_ctx *ctx, struct ropkg_pkg_expr *expr)
|
||||
{
|
||||
b_queue_push_back(&ctx->ctx_stack, &expr->expr_entry);
|
||||
fx_queue_push_back(&ctx->ctx_stack, &expr->expr_entry);
|
||||
}
|
||||
|
||||
static struct ropkg_pkg_expr *parse_ctx_dequeue(struct parse_ctx *ctx)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_front(&ctx->ctx_queue);
|
||||
fx_queue_entry *entry = fx_queue_pop_front(&ctx->ctx_queue);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct ropkg_pkg_expr, entry, expr_entry);
|
||||
return fx_unbox(struct ropkg_pkg_expr, entry, expr_entry);
|
||||
}
|
||||
|
||||
static void parse_ctx_enqueue(
|
||||
struct parse_ctx *ctx,
|
||||
struct ropkg_pkg_expr *expr)
|
||||
{
|
||||
b_queue_push_back(&ctx->ctx_queue, &expr->expr_entry);
|
||||
fx_queue_push_back(&ctx->ctx_queue, &expr->expr_entry);
|
||||
}
|
||||
|
||||
static char parse_ctx_peek(struct parse_ctx *ctx)
|
||||
@@ -99,7 +99,7 @@ static char parse_ctx_advance(struct parse_ctx *ctx)
|
||||
static void parse_ctx_cleanup(struct parse_ctx *ctx)
|
||||
{
|
||||
if (ctx->ctx_temp) {
|
||||
b_string_release(ctx->ctx_temp);
|
||||
fx_string_unref(ctx->ctx_temp);
|
||||
}
|
||||
|
||||
struct ropkg_pkg_expr *expr = parse_ctx_dequeue(ctx);
|
||||
@@ -122,16 +122,16 @@ enum ropkg_status ropkg_pkg_expr_create(struct ropkg_pkg_expr **out)
|
||||
|
||||
void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr)
|
||||
{
|
||||
b_queue q = B_QUEUE_INIT;
|
||||
b_queue_push_back(&q, &expr->expr_entry);
|
||||
fx_queue q = FX_QUEUE_INIT;
|
||||
fx_queue_push_back(&q, &expr->expr_entry);
|
||||
|
||||
while (1) {
|
||||
b_queue_entry *entry = b_queue_pop_front(&q);
|
||||
fx_queue_entry *entry = fx_queue_pop_front(&q);
|
||||
if (!entry) {
|
||||
break;
|
||||
}
|
||||
|
||||
expr = b_unbox(struct ropkg_pkg_expr, entry, expr_entry);
|
||||
expr = fx_unbox(struct ropkg_pkg_expr, entry, expr_entry);
|
||||
|
||||
switch (expr->expr_type) {
|
||||
case ROPKG_PKG_EXPR_NODE_PKG: {
|
||||
@@ -150,13 +150,13 @@ void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr)
|
||||
struct ropkg_pkg_expr_and *and_node
|
||||
= (struct ropkg_pkg_expr_and *)expr;
|
||||
if (and_node->and_left) {
|
||||
b_queue_push_back(
|
||||
fx_queue_push_back(
|
||||
&q,
|
||||
&and_node->and_left->expr_entry);
|
||||
}
|
||||
|
||||
if (and_node->and_right) {
|
||||
b_queue_push_back(
|
||||
fx_queue_push_back(
|
||||
&q,
|
||||
&and_node->and_right->expr_entry);
|
||||
}
|
||||
@@ -166,13 +166,13 @@ void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr)
|
||||
struct ropkg_pkg_expr_or *or_node
|
||||
= (struct ropkg_pkg_expr_or *)expr;
|
||||
if (or_node->or_left) {
|
||||
b_queue_push_back(
|
||||
fx_queue_push_back(
|
||||
&q,
|
||||
&or_node->or_left->expr_entry);
|
||||
}
|
||||
|
||||
if (or_node->or_right) {
|
||||
b_queue_push_back(
|
||||
fx_queue_push_back(
|
||||
&q,
|
||||
&or_node->or_right->expr_entry);
|
||||
}
|
||||
@@ -187,11 +187,11 @@ void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr)
|
||||
}
|
||||
}
|
||||
|
||||
static b_result parse_pkg_name(
|
||||
static fx_result parse_pkg_name(
|
||||
struct parse_ctx *ctx,
|
||||
struct ropkg_pkg_expr_pkg *pkg)
|
||||
{
|
||||
b_string_clear(ctx->ctx_temp);
|
||||
fx_string_clear(ctx->ctx_temp);
|
||||
|
||||
while (1) {
|
||||
char c = parse_ctx_peek(ctx);
|
||||
@@ -200,19 +200,19 @@ static b_result parse_pkg_name(
|
||||
}
|
||||
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(ctx->ctx_temp, s);
|
||||
fx_string_append_cstr(ctx->ctx_temp, s);
|
||||
parse_ctx_advance(ctx);
|
||||
}
|
||||
|
||||
pkg->pkg_name = b_string_steal(ctx->ctx_temp);
|
||||
return B_RESULT_SUCCESS;
|
||||
pkg->pkg_name = fx_string_steal(ctx->ctx_temp);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_pkg_version_predicate(
|
||||
static fx_result parse_pkg_version_predicate(
|
||||
struct parse_ctx *ctx,
|
||||
struct ropkg_pkg_expr_pkg *pkg)
|
||||
{
|
||||
b_string_clear(ctx->ctx_temp);
|
||||
fx_string_clear(ctx->ctx_temp);
|
||||
|
||||
while (1) {
|
||||
char c = parse_ctx_peek(ctx);
|
||||
@@ -221,11 +221,11 @@ static b_result parse_pkg_version_predicate(
|
||||
}
|
||||
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(ctx->ctx_temp, s);
|
||||
fx_string_append_cstr(ctx->ctx_temp, s);
|
||||
parse_ctx_advance(ctx);
|
||||
}
|
||||
|
||||
const char *pred = b_string_ptr(ctx->ctx_temp);
|
||||
const char *pred = fx_string_get_cstr(ctx->ctx_temp);
|
||||
if (!strcmp(pred, ">=")) {
|
||||
pkg->pkg_version_predicate = ROPKG_OP_GREATER_EQUAL;
|
||||
} else if (!strcmp(pred, ">")) {
|
||||
@@ -237,19 +237,19 @@ static b_result parse_pkg_version_predicate(
|
||||
} else if (!strcmp(pred, "==") || !strcmp(pred, "=")) {
|
||||
pkg->pkg_version_predicate = ROPKG_OP_EQUAL;
|
||||
} else {
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_PKG_EXPR);
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_pkg_version_id(
|
||||
static fx_result parse_pkg_version_id(
|
||||
struct parse_ctx *ctx,
|
||||
struct ropkg_pkg_expr_pkg *pkg)
|
||||
{
|
||||
b_string_clear(ctx->ctx_temp);
|
||||
fx_string_clear(ctx->ctx_temp);
|
||||
while (1) {
|
||||
char c = parse_ctx_peek(ctx);
|
||||
if (!isalnum(c) && c != '.' && c != '-' && c != '~') {
|
||||
@@ -257,40 +257,41 @@ static b_result parse_pkg_version_id(
|
||||
}
|
||||
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(ctx->ctx_temp, s);
|
||||
fx_string_append_cstr(ctx->ctx_temp, s);
|
||||
parse_ctx_advance(ctx);
|
||||
}
|
||||
|
||||
struct ropkg_version *version = NULL;
|
||||
enum ropkg_status status = ropkg_version_create(&version);
|
||||
if (status != ROPKG_SUCCESS) {
|
||||
return b_error_with_code(ROPKG_ERROR_VENDOR, status);
|
||||
return fx_error_with_code(ROPKG_ERROR_VENDOR, status);
|
||||
}
|
||||
|
||||
b_result result
|
||||
= ropkg_version_parse(version, b_string_ptr(ctx->ctx_temp));
|
||||
if (b_result_is_error(result)) {
|
||||
fx_result result = ropkg_version_parse(
|
||||
version,
|
||||
fx_string_get_cstr(ctx->ctx_temp));
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_version_destroy(version);
|
||||
version = NULL;
|
||||
}
|
||||
|
||||
pkg->pkg_version = version;
|
||||
return b_result_propagate(result);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
static b_result parse_pkg_version(
|
||||
static fx_result parse_pkg_version(
|
||||
struct parse_ctx *ctx,
|
||||
struct ropkg_pkg_expr_pkg *pkg)
|
||||
{
|
||||
parse_ctx_advance(ctx);
|
||||
|
||||
b_result result = B_RESULT_SUCCESS;
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
char c = parse_ctx_peek(ctx);
|
||||
if (c == '>' || c == '<' || c == '=') {
|
||||
result = parse_pkg_version_predicate(ctx, pkg);
|
||||
}
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -299,7 +300,7 @@ static b_result parse_pkg_version(
|
||||
if (isalnum(c)) {
|
||||
result = parse_pkg_version_id(ctx, pkg);
|
||||
} else {
|
||||
result = b_error_with_code(
|
||||
result = fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_PKG_EXPR);
|
||||
}
|
||||
@@ -308,7 +309,7 @@ static b_result parse_pkg_version(
|
||||
if (c == ')') {
|
||||
parse_ctx_advance(ctx);
|
||||
} else {
|
||||
result = b_error_with_code(
|
||||
result = fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_PKG_EXPR);
|
||||
}
|
||||
@@ -316,19 +317,19 @@ static b_result parse_pkg_version(
|
||||
return result;
|
||||
}
|
||||
|
||||
static b_result parse_pkg(struct parse_ctx *ctx)
|
||||
static fx_result parse_pkg(struct parse_ctx *ctx)
|
||||
{
|
||||
struct ropkg_pkg_expr_pkg *pkg = ropkg_pkg_expr_pkg_create();
|
||||
|
||||
b_result result = B_RESULT_SUCCESS;
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
char c = parse_ctx_peek(ctx);
|
||||
if (isalpha(c)) {
|
||||
result = parse_pkg_name(ctx, pkg);
|
||||
}
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_pkg_expr_destroy((struct ropkg_pkg_expr *)pkg);
|
||||
return b_result_propagate(result);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
c = parse_ctx_peek(ctx);
|
||||
@@ -336,9 +337,9 @@ static b_result parse_pkg(struct parse_ctx *ctx)
|
||||
result = parse_pkg_version(ctx, pkg);
|
||||
}
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_pkg_expr_destroy((struct ropkg_pkg_expr *)pkg);
|
||||
return b_result_propagate(result);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
parse_ctx_enqueue(ctx, &pkg->pkg_base);
|
||||
@@ -346,7 +347,7 @@ static b_result parse_pkg(struct parse_ctx *ctx)
|
||||
return result;
|
||||
}
|
||||
|
||||
static b_result parse_and(struct parse_ctx *ctx)
|
||||
static fx_result parse_and(struct parse_ctx *ctx)
|
||||
{
|
||||
parse_ctx_advance(ctx);
|
||||
|
||||
@@ -371,10 +372,10 @@ static b_result parse_and(struct parse_ctx *ctx)
|
||||
}
|
||||
|
||||
parse_ctx_push(ctx, &and_node->and_base);
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_or(struct parse_ctx *ctx)
|
||||
static fx_result parse_or(struct parse_ctx *ctx)
|
||||
{
|
||||
parse_ctx_advance(ctx);
|
||||
|
||||
@@ -395,16 +396,16 @@ static b_result parse_or(struct parse_ctx *ctx)
|
||||
}
|
||||
|
||||
parse_ctx_push(ctx, &or_node->or_base);
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_group_start(struct parse_ctx *ctx)
|
||||
static fx_result parse_group_start(struct parse_ctx *ctx)
|
||||
{
|
||||
parse_ctx_advance(ctx);
|
||||
|
||||
struct ropkg_pkg_expr *group_node = malloc(sizeof *group_node);
|
||||
if (!group_node) {
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_NO_MEMORY);
|
||||
}
|
||||
@@ -414,10 +415,10 @@ static b_result parse_group_start(struct parse_ctx *ctx)
|
||||
group_node->expr_type = ROPKG_PKG_EXPR_NODE_GROUP;
|
||||
|
||||
parse_ctx_push(ctx, group_node);
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_group_end(struct parse_ctx *ctx)
|
||||
static fx_result parse_group_end(struct parse_ctx *ctx)
|
||||
{
|
||||
parse_ctx_advance(ctx);
|
||||
|
||||
@@ -427,7 +428,7 @@ static b_result parse_group_end(struct parse_ctx *ctx)
|
||||
struct ropkg_pkg_expr *expr = parse_ctx_pop(ctx);
|
||||
|
||||
if (!expr) {
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_PKG_EXPR);
|
||||
}
|
||||
@@ -443,10 +444,10 @@ static b_result parse_group_end(struct parse_ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
|
||||
fx_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
|
||||
{
|
||||
while (isspace(*s)) {
|
||||
s++;
|
||||
@@ -454,12 +455,12 @@ b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
|
||||
|
||||
struct parse_ctx ctx = {
|
||||
.ctx_str = s,
|
||||
.ctx_temp = b_string_create(),
|
||||
.ctx_temp = fx_string_create(),
|
||||
};
|
||||
|
||||
b_result result = B_RESULT_SUCCESS;
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
|
||||
while (!b_result_is_error(result)) {
|
||||
while (!fx_result_is_error(result)) {
|
||||
char c = parse_ctx_peek(&ctx);
|
||||
if (c == 0) {
|
||||
break;
|
||||
@@ -476,14 +477,14 @@ b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
|
||||
} else if (isalpha(c)) {
|
||||
result = parse_pkg(&ctx);
|
||||
} else {
|
||||
result = b_error_with_code(
|
||||
result = fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_PKG_EXPR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
if (fx_result_is_error(result)) {
|
||||
parse_ctx_cleanup(&ctx);
|
||||
return result;
|
||||
}
|
||||
@@ -507,7 +508,7 @@ b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
|
||||
|
||||
if (expr->expr_type == ROPKG_PKG_EXPR_NODE_GROUP) {
|
||||
parse_ctx_cleanup(&ctx);
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_PKG_EXPR);
|
||||
}
|
||||
@@ -517,7 +518,7 @@ b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
|
||||
left = parse_ctx_pop(&ctx);
|
||||
if (!left || !right) {
|
||||
parse_ctx_cleanup(&ctx);
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_PKG_EXPR);
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,12 +1,13 @@
|
||||
#ifndef _PKG_EXPR_H_
|
||||
#define _PKG_EXPR_H_
|
||||
|
||||
#include <fx/queue.h>
|
||||
#include <ropkg/pkg-expr.h>
|
||||
#include <ropkg/version.h>
|
||||
|
||||
struct ropkg_pkg_expr {
|
||||
enum ropkg_pkg_expr_type expr_type;
|
||||
b_queue_entry expr_entry;
|
||||
fx_queue_entry expr_entry;
|
||||
};
|
||||
|
||||
struct ropkg_pkg_expr_pkg {
|
||||
|
||||
+13
-13
@@ -13,7 +13,7 @@ static void copy_string(
|
||||
size_t dest_max)
|
||||
{
|
||||
size_t start = strlen(dest);
|
||||
size_t max = b_min(size_t, src_max, dest_max - start);
|
||||
size_t max = fx_min(size_t, src_max, dest_max - start);
|
||||
|
||||
for (size_t i = 0; i < max; i++) {
|
||||
dest[start + i] = src[i];
|
||||
@@ -47,23 +47,23 @@ static long long from_octal(const char *s, size_t len)
|
||||
|
||||
static enum ropkg_status read_file_header(struct ropkg_reader *reader)
|
||||
{
|
||||
if (b_cstream_in_compressed_section(reader->r_stream)) {
|
||||
b_cstream_tx_bytes_uncompressed(
|
||||
if (fx_cstream_in_compressed_section(reader->r_stream)) {
|
||||
fx_cstream_tx_bytes_uncompressed(
|
||||
reader->r_stream,
|
||||
&reader->r_cur_header_offset);
|
||||
} else {
|
||||
b_cstream_tx_bytes(
|
||||
fx_cstream_tx_bytes(
|
||||
reader->r_stream,
|
||||
&reader->r_cur_header_offset);
|
||||
}
|
||||
|
||||
size_t nr_read = 0;
|
||||
b_status status = b_cstream_read(
|
||||
fx_status status = fx_cstream_read(
|
||||
reader->r_stream,
|
||||
&reader->r_cur_header,
|
||||
sizeof reader->r_cur_header,
|
||||
&nr_read);
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
return ROPKG_ERR_IO_FAILURE;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ static enum ropkg_status read_file_header(struct ropkg_reader *reader)
|
||||
return ROPKG_SUCCESS;
|
||||
}
|
||||
|
||||
enum ropkg_status ropkg_reader_open(b_cstream *fp, struct ropkg_reader **out)
|
||||
enum ropkg_status ropkg_reader_open(fx_cstream *fp, struct ropkg_reader **out)
|
||||
{
|
||||
struct ropkg_reader *reader = malloc(sizeof *reader);
|
||||
if (!reader) {
|
||||
@@ -127,7 +127,7 @@ enum ropkg_status ropkg_reader_open(b_cstream *fp, struct ropkg_reader **out)
|
||||
}
|
||||
|
||||
if (!memcmp(&reader->r_cur_header, &null_header, sizeof null_header)) {
|
||||
b_cstream_skip(reader->r_stream, sizeof null_header, NULL);
|
||||
fx_cstream_skip(reader->r_stream, sizeof null_header, NULL);
|
||||
reader->r_eof = true;
|
||||
}
|
||||
|
||||
@@ -154,10 +154,10 @@ enum ropkg_status ropkg_reader_move_next(struct ropkg_reader *pkg)
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
if (b_cstream_in_compressed_section(pkg->r_stream)) {
|
||||
b_cstream_tx_bytes_uncompressed(pkg->r_stream, &pos);
|
||||
if (fx_cstream_in_compressed_section(pkg->r_stream)) {
|
||||
fx_cstream_tx_bytes_uncompressed(pkg->r_stream, &pos);
|
||||
} else {
|
||||
b_cstream_tx_bytes(pkg->r_stream, &pos);
|
||||
fx_cstream_tx_bytes(pkg->r_stream, &pos);
|
||||
}
|
||||
|
||||
size_t end = pkg->r_cur_header_offset + sizeof pkg->r_cur_header
|
||||
@@ -169,7 +169,7 @@ enum ropkg_status ropkg_reader_move_next(struct ropkg_reader *pkg)
|
||||
size_t skip = end - pos;
|
||||
|
||||
size_t nr_skipped = 0;
|
||||
b_cstream_skip(pkg->r_stream, skip, &nr_skipped);
|
||||
fx_cstream_skip(pkg->r_stream, skip, &nr_skipped);
|
||||
|
||||
if (nr_skipped != skip) {
|
||||
pkg->r_eof = true;
|
||||
@@ -182,7 +182,7 @@ enum ropkg_status ropkg_reader_move_next(struct ropkg_reader *pkg)
|
||||
}
|
||||
|
||||
if (!memcmp(&pkg->r_cur_header, &null_header, sizeof null_header)) {
|
||||
b_cstream_skip(pkg->r_stream, sizeof null_header, NULL);
|
||||
fx_cstream_skip(pkg->r_stream, sizeof null_header, NULL);
|
||||
pkg->r_eof = true;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -3,11 +3,11 @@
|
||||
|
||||
#include "tar.h"
|
||||
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <ropkg/reader.h>
|
||||
|
||||
struct ropkg_reader {
|
||||
b_cstream *r_stream;
|
||||
fx_cstream *r_stream;
|
||||
struct ustar_header r_cur_header;
|
||||
size_t r_cur_header_offset;
|
||||
struct ropkg_file_info f_cur_file;
|
||||
|
||||
@@ -0,0 +1,930 @@
|
||||
#include "db.h"
|
||||
|
||||
#include <fx/io/directory.h>
|
||||
#include <ropkg/repo-mgmt.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <sqlite3.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct ropkg_repo_mgmt {
|
||||
sqlite3 *repo_meta;
|
||||
sqlite3 *repo_packages;
|
||||
|
||||
fx_directory *repo_root;
|
||||
fx_directory *repo_pool;
|
||||
fx_directory *repo_news;
|
||||
fx_directory *repo_channel;
|
||||
};
|
||||
|
||||
struct ropkg_repo_mgmt_channel {
|
||||
sqlite3 *c_meta;
|
||||
|
||||
fx_directory *c_root;
|
||||
fx_directory *c_news;
|
||||
};
|
||||
|
||||
struct ropkg_repo_mgmt_component {
|
||||
sqlite3 *c_meta;
|
||||
sqlite3 *c_packages;
|
||||
|
||||
fx_directory *c_root;
|
||||
fx_directory *c_news;
|
||||
};
|
||||
|
||||
static fx_result init_repo_meta_db(sqlite3 *db)
|
||||
{
|
||||
const char *sql = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = 0;
|
||||
|
||||
sql = "CREATE TABLE repo ("
|
||||
"name TEXT PRIMARY KEY,"
|
||||
"description TEXT NOT NULL);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sql = "CREATE TABLE architecture ("
|
||||
"name TEXT PRIMARY KEY);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sql = "CREATE TABLE channel ("
|
||||
"name TEXT PRIMARY KEY);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sql = "CREATE TABLE news ("
|
||||
"id NUMBER PRIMARY KEY,"
|
||||
"title TEXT NOT NULL,"
|
||||
"importance TEXT,"
|
||||
"category TEXT,"
|
||||
"publish_date TEXT NOT NULL,"
|
||||
"filename TEXT NOT NULL);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result init_repo_packages_db(sqlite3 *db)
|
||||
{
|
||||
const char *sql = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = 0;
|
||||
|
||||
sql = "CREATE TABLE package ("
|
||||
"name TEXT NOT NULL,"
|
||||
"arch TEXT NOT NULL,"
|
||||
"version TEXT NOT NULL,"
|
||||
"description TEXT,"
|
||||
"priority TEXT,"
|
||||
"category TEXT,"
|
||||
"maintainer TEXT NOT NULL,"
|
||||
"provides TEXT,"
|
||||
"dependencies TEXT,"
|
||||
"recommends TEXT,"
|
||||
"suggests TEXT,"
|
||||
"conflicts TEXT,"
|
||||
"enhances TEXT,"
|
||||
"filename TEXT UNIQUE,"
|
||||
"PRIMARY KEY(name, arch, version));";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result init_channel_meta_db(sqlite3 *db)
|
||||
{
|
||||
const char *sql = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = 0;
|
||||
|
||||
sql = "CREATE TABLE channel ("
|
||||
"name TEXT PRIMARY KEY,"
|
||||
"description TEXT NOT NULL);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sql = "CREATE TABLE component ("
|
||||
"name TEXT PRIMARY KEY);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sql = "CREATE TABLE news ("
|
||||
"id NUMBER PRIMARY KEY,"
|
||||
"title TEXT NOT NULL,"
|
||||
"importance TEXT,"
|
||||
"category TEXT,"
|
||||
"publish_date TEXT NOT NULL,"
|
||||
"filename TEXT NOT NULL);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result init_component_meta_db(sqlite3 *db)
|
||||
{
|
||||
const char *sql = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = 0;
|
||||
|
||||
sql = "CREATE TABLE component ("
|
||||
"name TEXT PRIMARY KEY,"
|
||||
"description TEXT NOT NULL);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sql = "CREATE TABLE news ("
|
||||
"id NUMBER PRIMARY KEY,"
|
||||
"title TEXT NOT NULL,"
|
||||
"importance TEXT,"
|
||||
"category TEXT,"
|
||||
"publish_date TEXT NOT NULL,"
|
||||
"filename TEXT NOT NULL);";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result init_component_packages_db(sqlite3 *db)
|
||||
{
|
||||
const char *sql = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = 0;
|
||||
|
||||
sql = "CREATE TABLE package ("
|
||||
"name TEXT NOT NULL,"
|
||||
"arch TEXT NOT NULL,"
|
||||
"version TEXT NOT NULL,"
|
||||
"description TEXT,"
|
||||
"priority TEXT,"
|
||||
"category TEXT,"
|
||||
"maintainer TEXT NOT NULL,"
|
||||
"provides TEXT,"
|
||||
"dependencies TEXT,"
|
||||
"recommends TEXT,"
|
||||
"suggests TEXT,"
|
||||
"conflicts TEXT,"
|
||||
"enhances TEXT,"
|
||||
"repo_name TEXT NOT NULL,"
|
||||
"channel_name TEXT NOT NULL,"
|
||||
"PRIMARY KEY(name, arch, version, repo_name, channel_name));";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_repo_mgmt_open(const char *path, struct ropkg_repo_mgmt **out)
|
||||
{
|
||||
struct ropkg_repo_mgmt *repo = malloc(sizeof *repo);
|
||||
if (!repo) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(repo, 0x0, sizeof *repo);
|
||||
|
||||
fx_result result = fx_directory_open(
|
||||
NULL,
|
||||
FX_RV_PATH(path),
|
||||
0,
|
||||
&repo->repo_root);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
repo->repo_root,
|
||||
FX_RV_PATH("pool"),
|
||||
0,
|
||||
&repo->repo_pool);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
repo->repo_root,
|
||||
FX_RV_PATH("news"),
|
||||
0,
|
||||
&repo->repo_news);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
repo->repo_root,
|
||||
FX_RV_PATH("channel"),
|
||||
0,
|
||||
&repo->repo_channel);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
repo->repo_root,
|
||||
"meta.rodb",
|
||||
SQLITE_OPEN_READWRITE,
|
||||
&repo->repo_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = repo;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_repo_mgmt_create(const char *path, struct ropkg_repo_mgmt **out)
|
||||
{
|
||||
struct ropkg_repo_mgmt *repo = malloc(sizeof *repo);
|
||||
if (!repo) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(repo, 0x0, sizeof *repo);
|
||||
|
||||
fx_result result = fx_directory_open(
|
||||
NULL,
|
||||
FX_RV_PATH(path),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&repo->repo_root);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
repo->repo_root,
|
||||
FX_RV_PATH("pool"),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&repo->repo_pool);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
repo->repo_root,
|
||||
FX_RV_PATH("news"),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&repo->repo_news);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
repo->repo_root,
|
||||
FX_RV_PATH("channel"),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&repo->repo_channel);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
repo->repo_root,
|
||||
"meta.rodb",
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
|
||||
&repo->repo_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = init_repo_meta_db(repo->repo_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
repo->repo_root,
|
||||
"packages.rodb",
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
|
||||
&repo->repo_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = init_repo_packages_db(repo->repo_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = repo;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void ropkg_repo_mgmt_close(struct ropkg_repo_mgmt *repo)
|
||||
{
|
||||
if (repo->repo_meta) {
|
||||
sqlite3_close(repo->repo_meta);
|
||||
repo->repo_meta = NULL;
|
||||
}
|
||||
|
||||
if (repo->repo_pool) {
|
||||
fx_directory_unref(repo->repo_pool);
|
||||
repo->repo_pool = NULL;
|
||||
}
|
||||
|
||||
if (repo->repo_news) {
|
||||
fx_directory_unref(repo->repo_news);
|
||||
repo->repo_news = NULL;
|
||||
}
|
||||
|
||||
if (repo->repo_root) {
|
||||
fx_directory_unref(repo->repo_root);
|
||||
repo->repo_root = NULL;
|
||||
}
|
||||
|
||||
free(repo);
|
||||
}
|
||||
|
||||
static fx_result channel_exists(
|
||||
struct ropkg_repo_mgmt *repo,
|
||||
const char *name,
|
||||
bool *exists)
|
||||
{
|
||||
const char *sql = "SELECT * FROM channel WHERE name = ?;";
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = sqlite3_prepare_v2(repo->repo_meta, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(repo->repo_meta));
|
||||
}
|
||||
|
||||
sqlite3_bind_text(stmt, 1, name, strlen(name), NULL);
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
switch (err) {
|
||||
case SQLITE_ROW:
|
||||
*exists = true;
|
||||
break;
|
||||
case SQLITE_ERROR:
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(repo->repo_meta));
|
||||
default:
|
||||
*exists = false;
|
||||
break;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result component_exists(
|
||||
struct ropkg_repo_mgmt_channel *channel,
|
||||
const char *name,
|
||||
bool *exists)
|
||||
{
|
||||
const char *sql = "SELECT * FROM component WHERE name = ?;";
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = sqlite3_prepare_v2(channel->c_meta, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(channel->c_meta));
|
||||
}
|
||||
|
||||
sqlite3_bind_text(stmt, 1, name, strlen(name), NULL);
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
switch (err) {
|
||||
case SQLITE_ROW:
|
||||
*exists = true;
|
||||
break;
|
||||
case SQLITE_ERROR:
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(channel->c_meta));
|
||||
default:
|
||||
*exists = false;
|
||||
break;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_repo_mgmt_open_channel(
|
||||
struct ropkg_repo_mgmt *repo,
|
||||
const char *name,
|
||||
struct ropkg_repo_mgmt_channel **out)
|
||||
{
|
||||
bool exists;
|
||||
fx_result result = channel_exists(repo, name, &exists);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_NO_CHANNEL);
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt_channel *channel = malloc(sizeof *channel);
|
||||
if (!channel) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(channel, 0x0, sizeof *channel);
|
||||
|
||||
result = fx_directory_open(
|
||||
repo->repo_channel,
|
||||
FX_RV_PATH(name),
|
||||
0,
|
||||
&channel->c_root);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
channel->c_root,
|
||||
FX_RV_PATH("news"),
|
||||
0,
|
||||
&channel->c_news);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
channel->c_root,
|
||||
"meta.rodb",
|
||||
SQLITE_OPEN_READWRITE,
|
||||
&channel->c_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = channel;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_repo_mgmt_create_channel(
|
||||
struct ropkg_repo_mgmt *repo,
|
||||
const char *name,
|
||||
struct ropkg_repo_mgmt_channel **out)
|
||||
{
|
||||
struct ropkg_repo_mgmt_channel *channel = malloc(sizeof *channel);
|
||||
if (!channel) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(channel, 0x0, sizeof *channel);
|
||||
|
||||
fx_result result = fx_directory_open(
|
||||
repo->repo_channel,
|
||||
FX_RV_PATH(name),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&channel->c_root);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
channel->c_root,
|
||||
FX_RV_PATH("news"),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&channel->c_news);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
channel->c_root,
|
||||
"meta.rodb",
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
|
||||
&channel->c_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = init_channel_meta_db(channel->c_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
const char *sql = "INSERT INTO channel (name) VALUES (?);";
|
||||
sqlite3_stmt *stmt;
|
||||
int err = sqlite3_prepare(repo->repo_meta, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(repo->repo_meta));
|
||||
}
|
||||
|
||||
sqlite3_bind_text(stmt, 1, name, strlen(name), SQLITE_STATIC);
|
||||
err = sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
if (err != SQLITE_DONE) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(repo->repo_meta));
|
||||
}
|
||||
|
||||
*out = channel;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void ropkg_repo_mgmt_channel_close(struct ropkg_repo_mgmt_channel *channel)
|
||||
{
|
||||
if (channel->c_meta) {
|
||||
sqlite3_close(channel->c_meta);
|
||||
channel->c_meta = NULL;
|
||||
}
|
||||
|
||||
if (channel->c_news) {
|
||||
fx_directory_unref(channel->c_news);
|
||||
channel->c_news = NULL;
|
||||
}
|
||||
|
||||
if (channel->c_root) {
|
||||
fx_directory_unref(channel->c_root);
|
||||
channel->c_root = NULL;
|
||||
}
|
||||
|
||||
free(channel);
|
||||
}
|
||||
|
||||
fx_result ropkg_repo_mgmt_channel_open_component(
|
||||
struct ropkg_repo_mgmt_channel *channel,
|
||||
const char *name,
|
||||
struct ropkg_repo_mgmt_component **out)
|
||||
{
|
||||
bool exists;
|
||||
fx_result result = component_exists(channel, name, &exists);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_NO_COMPONENT);
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt_component *component = malloc(sizeof *component);
|
||||
if (!component) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(component, 0x0, sizeof *component);
|
||||
|
||||
result = fx_directory_open(
|
||||
channel->c_root,
|
||||
FX_RV_PATH(name),
|
||||
0,
|
||||
&component->c_root);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
component->c_root,
|
||||
FX_RV_PATH("news"),
|
||||
0,
|
||||
&component->c_news);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
component->c_root,
|
||||
"meta.rodb",
|
||||
SQLITE_OPEN_READWRITE,
|
||||
&component->c_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
component->c_root,
|
||||
"packages.rodb",
|
||||
SQLITE_OPEN_READWRITE,
|
||||
&component->c_packages);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = component;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_repo_mgmt_channel_create_component(
|
||||
struct ropkg_repo_mgmt_channel *channel,
|
||||
const char *name,
|
||||
struct ropkg_repo_mgmt_component **out)
|
||||
{
|
||||
struct ropkg_repo_mgmt_component *component = malloc(sizeof *component);
|
||||
if (!channel) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(component, 0x0, sizeof *component);
|
||||
|
||||
fx_result result = fx_directory_open(
|
||||
channel->c_root,
|
||||
FX_RV_PATH(name),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&component->c_root);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_directory_open(
|
||||
component->c_root,
|
||||
FX_RV_PATH("news"),
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&component->c_news);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
component->c_root,
|
||||
"meta.rodb",
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
|
||||
&component->c_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = init_component_meta_db(component->c_meta);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = open_database(
|
||||
component->c_root,
|
||||
"packages.rodb",
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
|
||||
&component->c_packages);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = init_component_packages_db(component->c_packages);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
const char *sql = "INSERT INTO component (name) VALUES (?);";
|
||||
sqlite3_stmt *stmt;
|
||||
int err = sqlite3_prepare(channel->c_meta, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(channel->c_meta));
|
||||
}
|
||||
|
||||
sqlite3_bind_text(stmt, 1, name, strlen(name), SQLITE_STATIC);
|
||||
err = sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
if (err != SQLITE_DONE) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(channel->c_meta));
|
||||
}
|
||||
|
||||
*out = component;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void ropkg_repo_mgmt_component_close(
|
||||
struct ropkg_repo_mgmt_component *component)
|
||||
{
|
||||
if (component->c_packages) {
|
||||
sqlite3_close(component->c_packages);
|
||||
component->c_packages = NULL;
|
||||
}
|
||||
|
||||
if (component->c_meta) {
|
||||
sqlite3_close(component->c_meta);
|
||||
component->c_meta = NULL;
|
||||
}
|
||||
|
||||
if (component->c_news) {
|
||||
fx_directory_unref(component->c_news);
|
||||
component->c_news = NULL;
|
||||
}
|
||||
|
||||
if (component->c_root) {
|
||||
fx_directory_unref(component->c_root);
|
||||
component->c_root = NULL;
|
||||
}
|
||||
|
||||
free(component);
|
||||
}
|
||||
+66
-41
@@ -1,123 +1,148 @@
|
||||
#include <blue/core/error.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/status.h>
|
||||
|
||||
static const b_error_definition ropkg_errors[] = {
|
||||
B_ERROR_DEFINITION(ROPKG_SUCCESS, "SUCCESS", "Success"),
|
||||
B_ERROR_DEFINITION(
|
||||
static const fx_error_definition ropkg_errors[] = {
|
||||
FX_ERROR_DEFINITION(ROPKG_SUCCESS, "SUCCESS", "Success"),
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_NOT_SUPPORTED,
|
||||
"NOT_SUPPORTED",
|
||||
"Operation not supported"),
|
||||
B_ERROR_DEFINITION(
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_INVALID_ARGUMENT,
|
||||
"INVALID_ARGUMENT",
|
||||
"Invalid argument"),
|
||||
B_ERROR_DEFINITION(ROPKG_ERR_NO_MEMORY, "NO_MEMORY", "Out of memory"),
|
||||
B_ERROR_DEFINITION(ROPKG_ERR_BAD_STATE, "BAD_STATE", "Bad state"),
|
||||
B_ERROR_DEFINITION(
|
||||
FX_ERROR_DEFINITION(ROPKG_ERR_NO_MEMORY, "NO_MEMORY", "Out of memory"),
|
||||
FX_ERROR_DEFINITION(ROPKG_ERR_BAD_STATE, "BAD_STATE", "Bad state"),
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_INTERNAL_FAILURE,
|
||||
"INTERNAL_FAILURE",
|
||||
"Internal failure"),
|
||||
B_ERROR_DEFINITION(ROPKG_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
|
||||
B_ERROR_DEFINITION(
|
||||
FX_ERROR_DEFINITION(ROPKG_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_NO_ENTRY,
|
||||
"NO_ENTRY",
|
||||
"Name does not exist"),
|
||||
B_ERROR_DEFINITION(
|
||||
FX_ERROR_DEFINITION(ROPKG_ERR_NO_DATA, "NO_DATA", "No data available"),
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_NAME_EXISTS,
|
||||
"NAME_EXISTS",
|
||||
"Name already exist"),
|
||||
|
||||
B_ERROR_DEFINITION_TEMPLATE(
|
||||
FX_ERROR_DEFINITION_TEMPLATE(
|
||||
ROPKG_ERR_DIR_OPEN_FAILED,
|
||||
"DIR_OPEN_FAILED",
|
||||
"Cannot open directory @i[filepath]",
|
||||
B_ERROR_TEMPLATE_PARAM(
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"filepath",
|
||||
B_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
"%s")),
|
||||
|
||||
B_ERROR_DEFINITION_TEMPLATE(
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_INSTANCE_LOCKED,
|
||||
"INSTANCE_LOCKED",
|
||||
"The Rosetta system root is locked. Another Rosetta package "
|
||||
"management tool may be running."),
|
||||
|
||||
FX_ERROR_DEFINITION_TEMPLATE(
|
||||
ROPKG_ERR_INSTANCE_DIR_CREATE_FAILED,
|
||||
"INSTANCE_DIR_CREATE_FAILED",
|
||||
"Cannot create sub-directory @i[subdirpath] in instance "
|
||||
"@i[instancepath]",
|
||||
B_ERROR_TEMPLATE_PARAM(
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"instancepath",
|
||||
B_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
"%s"),
|
||||
B_ERROR_TEMPLATE_PARAM(
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"subdirpath",
|
||||
B_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
"%s")),
|
||||
|
||||
B_ERROR_DEFINITION_TEMPLATE(
|
||||
FX_ERROR_DEFINITION_TEMPLATE(
|
||||
ROPKG_ERR_FILE_OPEN_FAILED,
|
||||
"FILE_OPEN_FAILED",
|
||||
"Cannot open file @i[filepath]",
|
||||
B_ERROR_TEMPLATE_PARAM(
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"filepath",
|
||||
B_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
"%s")),
|
||||
|
||||
B_ERROR_DEFINITION(
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_INVALID_MANIFEST_FORMAT,
|
||||
"INVALID_MANIFSET_FORMAT",
|
||||
"Invalid manifest format"),
|
||||
|
||||
B_ERROR_DEFINITION(
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
"INVALID_VERSION_FORMAT",
|
||||
"Invalid version format"),
|
||||
|
||||
B_ERROR_DEFINITION(
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_INVALID_PKG_EXPR,
|
||||
"INVALID_PKG_EXPR",
|
||||
"Invalid package expression"),
|
||||
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_INVALID_PKG_FILE,
|
||||
"INVALID_PKG_FILE",
|
||||
"Invalid package file"),
|
||||
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
"DB_OP_FAILED",
|
||||
"Database operation failed"),
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_NO_CHANNEL,
|
||||
"NO_CHANNEL",
|
||||
"Channel does not exist"),
|
||||
FX_ERROR_DEFINITION(
|
||||
ROPKG_ERR_NO_COMPONENT,
|
||||
"NO_COMPONENT",
|
||||
"Component does not exist"),
|
||||
};
|
||||
|
||||
static const b_error_msg ropkg_error_msg[] = {
|
||||
B_ERROR_MSG_TEMPLATE(
|
||||
static const fx_error_msg ropkg_error_msg[] = {
|
||||
FX_ERROR_MSG_TEMPLATE(
|
||||
ROPKG_EMSG_INVALID_RELEASE_PHASE,
|
||||
"@i[phase] is not a valid package release phase",
|
||||
B_ERROR_TEMPLATE_PARAM(
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"phase",
|
||||
B_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
"%s")),
|
||||
B_ERROR_MSG(
|
||||
FX_ERROR_MSG(
|
||||
ROPKG_EMSG_AVAILABLE_RELEASE_PHASES,
|
||||
"valid release phases: @i{alpha}, @i{beta}"),
|
||||
B_ERROR_MSG(
|
||||
FX_ERROR_MSG(
|
||||
ROPKG_EMSG_AVAILABLE_VERSION_RELEASE_PHASES,
|
||||
"valid version release phases: @i{alpha}, @i{beta}, @i{rc}"),
|
||||
|
||||
B_ERROR_MSG(
|
||||
FX_ERROR_MSG(
|
||||
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_UNKNOWN_START,
|
||||
"unexpected character found while parsing upstream version"),
|
||||
B_ERROR_MSG(
|
||||
FX_ERROR_MSG(
|
||||
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_TWO_DOTS,
|
||||
"two consecutive full stops found in upstream version"),
|
||||
B_ERROR_MSG(
|
||||
FX_ERROR_MSG(
|
||||
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_END_DOT,
|
||||
"upstream version identifier cannot end with a full stop"),
|
||||
B_ERROR_MSG(
|
||||
FX_ERROR_MSG(
|
||||
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_TOO_MANY_NUMBERS,
|
||||
"upstream version can contain no more than five number "
|
||||
"components"),
|
||||
|
||||
B_ERROR_MSG_TEMPLATE(
|
||||
FX_ERROR_MSG_TEMPLATE(
|
||||
ROPKG_EMSG_INVALID_VERSION_RELEASE_PHASE,
|
||||
"@i[phase] is not a valid package version release phase",
|
||||
B_ERROR_TEMPLATE_PARAM(
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"phase",
|
||||
B_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
"%s")),
|
||||
|
||||
B_ERROR_MSG(
|
||||
FX_ERROR_MSG(
|
||||
ROPKG_EMSG_INVALID_VERSION_UNKNOWN_END,
|
||||
"unrecognised characters at the end of the version identifier"),
|
||||
};
|
||||
|
||||
static const b_error_vendor ropkg_error_vend = {
|
||||
static const fx_error_vendor ropkg_error_vend = {
|
||||
.v_name = "Ropkg",
|
||||
.v_error_definitions = ropkg_errors,
|
||||
.v_error_definitions_length = sizeof ropkg_errors,
|
||||
@@ -125,7 +150,7 @@ static const b_error_vendor ropkg_error_vend = {
|
||||
.v_msg_length = sizeof ropkg_error_msg,
|
||||
};
|
||||
|
||||
const struct b_error_vendor *ropkg_error_vendor(void)
|
||||
const struct fx_error_vendor *ropkg_error_vendor(void)
|
||||
{
|
||||
return &ropkg_error_vend;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
#include <fx/io/directory.h>
|
||||
#include <fx/io/path.h>
|
||||
#include <ropkg/package-db.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <sqlite3.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ropkg_system_state {
|
||||
sqlite3 *db_connection;
|
||||
};
|
||||
|
||||
static fx_result init_database_schema(sqlite3 *db)
|
||||
{
|
||||
const char *sql = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int err = 0;
|
||||
|
||||
sql = "CREATE TABLE package ("
|
||||
"name TEXT NOT NULL,"
|
||||
"arch TEXT NOT NULL,"
|
||||
"version TEXT NOT NULL,"
|
||||
"status TEXT NOT NULL,"
|
||||
"description TEXT,"
|
||||
"priority TEXT,"
|
||||
"category TEXT,"
|
||||
"maintainer TEXT NOT NULL,"
|
||||
"provides TEXT,"
|
||||
"dependencies TEXT,"
|
||||
"recommends TEXT,"
|
||||
"suggests TEXT,"
|
||||
"conflicts TEXT,"
|
||||
"enhances TEXT,"
|
||||
"repo_name TEXT NOT NULL,"
|
||||
"channel_name TEXT NOT NULL,"
|
||||
"PRIMARY KEY(name, arch, version, repo_name, channel_name));";
|
||||
err = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err != SQLITE_DONE) {
|
||||
return fx_error_with_string(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DB_OP_FAILED,
|
||||
sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result create_database(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
sqlite3 **out)
|
||||
{
|
||||
fx_path *abs_path = fx_path_join_list(
|
||||
2,
|
||||
&FX_VALUE_OBJECT(fx_directory_get_path(dir)),
|
||||
&FX_CSTR(path));
|
||||
if (!abs_path) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
if (fx_path_exists(abs_path)) {
|
||||
if (fx_path_is_directory(abs_path)) {
|
||||
fx_path_unref(abs_path);
|
||||
return FX_RESULT_ERR(IS_DIRECTORY);
|
||||
}
|
||||
|
||||
fx_path_unlink(abs_path);
|
||||
}
|
||||
|
||||
sqlite3 *db = NULL;
|
||||
int err = sqlite3_open_v2(
|
||||
fx_path_get_cstr(abs_path),
|
||||
&db,
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
|
||||
NULL);
|
||||
fx_path_unref(abs_path);
|
||||
|
||||
if (err != SQLITE_OK) {
|
||||
if (db) {
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
/* TODO check err */
|
||||
return FX_RESULT_ERR(IO_FAILURE);
|
||||
}
|
||||
|
||||
fx_result result = init_database_schema(db);
|
||||
if (fx_result_is_error(result)) {
|
||||
sqlite3_close(db);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = db;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_system_state_init(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_system_state **out)
|
||||
{
|
||||
struct ropkg_system_state *db = malloc(sizeof *db);
|
||||
if (!db) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(db, 0x0, sizeof *db);
|
||||
|
||||
fx_result result = create_database(dir, path, &db->db_connection);
|
||||
if (fx_result_is_error(result)) {
|
||||
free(db);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
*out = db;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_result ropkg_system_state_open(
|
||||
fx_directory *dir,
|
||||
const char *path,
|
||||
struct ropkg_system_state **out)
|
||||
{
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void ropkg_system_state_close(struct ropkg_system_state *db)
|
||||
{
|
||||
}
|
||||
+95
-85
@@ -1,7 +1,7 @@
|
||||
#include "version.h"
|
||||
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <ctype.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -14,10 +14,10 @@ enum ropkg_status ropkg_version_create(struct ropkg_version **out)
|
||||
|
||||
memset(version, 0x0, sizeof *version);
|
||||
|
||||
version->v_release_phase = ROPKG_VERSION_RELEASE_PHASE_RELEASE;
|
||||
version->v_unref_phase = ROPKG_VERSION_RELEASE_PHASE_RELEASE;
|
||||
version->v_upstream_version[0] = 1;
|
||||
version->v_version_release_phase = ROPKG_VERSION_RELEASE_PHASE_RELEASE;
|
||||
version->v_version_release_phase_revision = 1;
|
||||
version->v_version_unref_phase = ROPKG_VERSION_RELEASE_PHASE_RELEASE;
|
||||
version->v_version_unref_phase_revision = 1;
|
||||
version->v_package_revision = 1;
|
||||
|
||||
*out = version;
|
||||
@@ -29,9 +29,9 @@ void ropkg_version_destroy(struct ropkg_version *version)
|
||||
free(version);
|
||||
}
|
||||
|
||||
static b_result parse_release_phase(
|
||||
static fx_result parse_unref_phase(
|
||||
const char *s,
|
||||
enum ropkg_version_release_phase *out)
|
||||
enum ropkg_version_unref_phase *out)
|
||||
{
|
||||
if (s[0] == 0) {
|
||||
*out = ROPKG_VERSION_RELEASE_PHASE_RELEASE;
|
||||
@@ -40,24 +40,24 @@ static b_result parse_release_phase(
|
||||
} else if (!strcmp(s, "beta")) {
|
||||
*out = ROPKG_VERSION_RELEASE_PHASE_BETA;
|
||||
} else {
|
||||
b_result result = b_error_with_msg_template(
|
||||
fx_result result = fx_error_with_msg_template(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_RELEASE_PHASE,
|
||||
B_ERROR_PARAM("phase", s));
|
||||
b_error_add_submsg(
|
||||
FX_ERROR_PARAM("phase", s));
|
||||
fx_error_add_submsg(
|
||||
result,
|
||||
B_ERROR_SUBMSG_INFO,
|
||||
FX_ERROR_SUBMSG_INFO,
|
||||
ROPKG_EMSG_AVAILABLE_RELEASE_PHASES);
|
||||
return result;
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_version_release_phase(
|
||||
static fx_result parse_version_unref_phase(
|
||||
const char *s,
|
||||
enum ropkg_version_release_phase *out_phase,
|
||||
enum ropkg_version_unref_phase *out_phase,
|
||||
unsigned int *out_revision,
|
||||
size_t *nr_read)
|
||||
{
|
||||
@@ -67,14 +67,14 @@ static b_result parse_version_release_phase(
|
||||
*out_phase = ROPKG_VERSION_RELEASE_PHASE_RELEASE;
|
||||
*out_revision = 1;
|
||||
*nr_read = i;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
if (*s == '~') {
|
||||
i++;
|
||||
s++;
|
||||
} else {
|
||||
return b_error_with_msg(
|
||||
return fx_error_with_msg(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_VERSION_RELEASE_PHASE_UNKNOWN_START);
|
||||
@@ -97,14 +97,14 @@ static b_result parse_version_release_phase(
|
||||
} else if (!strcmp(temp, "rc")) {
|
||||
*out_phase = ROPKG_VERSION_RELEASE_PHASE_RC;
|
||||
} else {
|
||||
b_result result = b_error_with_msg_template(
|
||||
fx_result result = fx_error_with_msg_template(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_VERSION_RELEASE_PHASE,
|
||||
B_ERROR_PARAM("phase", temp));
|
||||
b_error_add_submsg(
|
||||
FX_ERROR_PARAM("phase", temp));
|
||||
fx_error_add_submsg(
|
||||
result,
|
||||
B_ERROR_SUBMSG_INFO,
|
||||
FX_ERROR_SUBMSG_INFO,
|
||||
ROPKG_EMSG_AVAILABLE_VERSION_RELEASE_PHASES);
|
||||
return result;
|
||||
}
|
||||
@@ -123,10 +123,10 @@ static b_result parse_version_release_phase(
|
||||
}
|
||||
|
||||
*nr_read = i;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_package_revision(
|
||||
static fx_result parse_package_revision(
|
||||
const char *s,
|
||||
unsigned int *out_revision,
|
||||
size_t *nr_read)
|
||||
@@ -136,14 +136,14 @@ static b_result parse_package_revision(
|
||||
if (*s == '\0') {
|
||||
*out_revision = 1;
|
||||
*nr_read = i;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
if (*s == '-') {
|
||||
i++;
|
||||
s++;
|
||||
} else {
|
||||
return b_error_with_msg(
|
||||
return fx_error_with_msg(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_PACKAGE_REVISION_UNKNOWN_START);
|
||||
@@ -163,16 +163,16 @@ static b_result parse_package_revision(
|
||||
*out_revision = strtoul(temp, &ep, 10);
|
||||
|
||||
*nr_read = i;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result parse_upstream_version(
|
||||
static fx_result parse_upstream_version(
|
||||
const char *s,
|
||||
unsigned int out[ROPKG_VERSION_UPSTREAM_DIGIT_MAX],
|
||||
size_t *nr_read)
|
||||
{
|
||||
if (!isdigit(*s)) {
|
||||
return b_error_with_msg(
|
||||
return fx_error_with_msg(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_UNKNOWN_START);
|
||||
@@ -197,14 +197,14 @@ static b_result parse_upstream_version(
|
||||
|
||||
if (s[i] == '.') {
|
||||
if (nr_temp == 0) {
|
||||
return b_error_with_msg(
|
||||
return fx_error_with_msg(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_TWO_DOTS);
|
||||
}
|
||||
|
||||
if (nr_digits >= ROPKG_VERSION_UPSTREAM_DIGIT_MAX - 1) {
|
||||
return b_error_with_msg(
|
||||
return fx_error_with_msg(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_TOO_MANY_NUMBERS);
|
||||
@@ -218,7 +218,7 @@ static b_result parse_upstream_version(
|
||||
}
|
||||
|
||||
if (nr_temp == 0) {
|
||||
return b_error_with_msg(
|
||||
return fx_error_with_msg(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_END_DOT);
|
||||
@@ -231,21 +231,21 @@ static b_result parse_upstream_version(
|
||||
}
|
||||
|
||||
*nr_read = i;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
b_result ropkg_version_parse(struct ropkg_version *version, const char *s)
|
||||
fx_result ropkg_version_parse(struct ropkg_version *version, const char *s)
|
||||
{
|
||||
enum ropkg_version_release_phase release_phase
|
||||
enum ropkg_version_unref_phase release_phase
|
||||
= ROPKG_VERSION_RELEASE_PHASE_RELEASE;
|
||||
unsigned int upstream_version[ROPKG_VERSION_UPSTREAM_DIGIT_MAX]
|
||||
= {0, 0, 0, 0, 0};
|
||||
enum ropkg_version_release_phase version_release_phase
|
||||
enum ropkg_version_unref_phase version_unref_phase
|
||||
= ROPKG_VERSION_RELEASE_PHASE_RELEASE;
|
||||
unsigned int version_release_phase_revision = 1;
|
||||
unsigned int version_unref_phase_revision = 1;
|
||||
unsigned int package_revision = 1;
|
||||
|
||||
b_result result = B_RESULT_SUCCESS;
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
|
||||
char temp[64] = {0};
|
||||
size_t z = 0;
|
||||
@@ -256,28 +256,28 @@ b_result ropkg_version_parse(struct ropkg_version *version, const char *s)
|
||||
s++;
|
||||
}
|
||||
|
||||
result = parse_release_phase(temp, &release_phase);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
result = parse_unref_phase(temp, &release_phase);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
size_t nr_read = 0;
|
||||
result = parse_upstream_version(s, upstream_version, &nr_read);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
s += nr_read;
|
||||
if (*s == '~' || *s == 0) {
|
||||
result = parse_version_release_phase(
|
||||
result = parse_version_unref_phase(
|
||||
s,
|
||||
&version_release_phase,
|
||||
&version_release_phase_revision,
|
||||
&version_unref_phase,
|
||||
&version_unref_phase_revision,
|
||||
&nr_read);
|
||||
|
||||
s += nr_read;
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,39 +285,38 @@ b_result ropkg_version_parse(struct ropkg_version *version, const char *s)
|
||||
result = parse_package_revision(s, &package_revision, &nr_read);
|
||||
|
||||
s += nr_read;
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
}
|
||||
|
||||
if (*s != 0) {
|
||||
return b_error_with_msg(
|
||||
return fx_error_with_msg(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_VERSION_FORMAT,
|
||||
ROPKG_EMSG_INVALID_VERSION_UNKNOWN_END);
|
||||
}
|
||||
|
||||
version->v_release_phase = release_phase;
|
||||
version->v_unref_phase = release_phase;
|
||||
memcpy(version->v_upstream_version,
|
||||
upstream_version,
|
||||
sizeof upstream_version);
|
||||
version->v_version_release_phase = version_release_phase;
|
||||
version->v_version_release_phase_revision
|
||||
= version_release_phase_revision;
|
||||
version->v_version_unref_phase = version_unref_phase;
|
||||
version->v_version_unref_phase_revision = version_unref_phase_revision;
|
||||
version->v_package_revision = package_revision;
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void ropkg_version_set_release_phase(
|
||||
void ropkg_version_set_unref_phase(
|
||||
struct ropkg_version *version,
|
||||
enum ropkg_version_release_phase phase)
|
||||
enum ropkg_version_unref_phase phase)
|
||||
{
|
||||
if (phase == ROPKG_VERSION_RELEASE_PHASE_RC) {
|
||||
return;
|
||||
}
|
||||
|
||||
version->v_release_phase = phase;
|
||||
version->v_unref_phase = phase;
|
||||
}
|
||||
|
||||
void ropkg_version_set_upstream_version(
|
||||
@@ -329,17 +328,17 @@ void ropkg_version_set_upstream_version(
|
||||
sizeof version->v_upstream_version);
|
||||
}
|
||||
|
||||
void ropkg_version_set_version_release_phase(
|
||||
void ropkg_version_set_version_unref_phase(
|
||||
struct ropkg_version *version,
|
||||
enum ropkg_version_release_phase phase,
|
||||
enum ropkg_version_unref_phase phase,
|
||||
unsigned int revision)
|
||||
{
|
||||
version->v_version_release_phase = phase;
|
||||
version->v_version_unref_phase = phase;
|
||||
|
||||
if (phase == ROPKG_VERSION_RELEASE_PHASE_RELEASE) {
|
||||
version->v_version_release_phase_revision = 1;
|
||||
version->v_version_unref_phase_revision = 1;
|
||||
} else {
|
||||
version->v_version_release_phase_revision = revision;
|
||||
version->v_version_unref_phase_revision = revision;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,8 +349,7 @@ void ropkg_version_set_package_revision(
|
||||
version->v_package_revision = revision;
|
||||
}
|
||||
|
||||
static const char *release_phase_to_string(
|
||||
enum ropkg_version_release_phase phase)
|
||||
static const char *release_phase_to_string(enum ropkg_version_unref_phase phase)
|
||||
{
|
||||
switch (phase) {
|
||||
case ROPKG_VERSION_RELEASE_PHASE_ALPHA:
|
||||
@@ -387,48 +385,60 @@ size_t ropkg_version_to_string(
|
||||
char *out,
|
||||
size_t max)
|
||||
{
|
||||
b_stringstream str;
|
||||
b_stringstream_begin(&str, out, max);
|
||||
fx_stringstream *str = fx_stringstream_create_with_buffer(out, max);
|
||||
|
||||
b_stringstream_add(
|
||||
&str,
|
||||
release_phase_to_string(version->v_release_phase));
|
||||
fx_stream_write_cstr(
|
||||
str,
|
||||
release_phase_to_string(version->v_unref_phase),
|
||||
NULL);
|
||||
|
||||
unsigned int version_length
|
||||
= upstream_version_length(version->v_upstream_version);
|
||||
|
||||
for (unsigned int i = 0; i < version_length; i++) {
|
||||
if (i > 0) {
|
||||
b_stringstream_add(&str, ".");
|
||||
fx_stream_write_char(str, '.');
|
||||
}
|
||||
|
||||
b_stringstream_addf(&str, "%u", version->v_upstream_version[i]);
|
||||
fx_stream_write_fmt(
|
||||
str,
|
||||
NULL,
|
||||
"%u",
|
||||
version->v_upstream_version[i]);
|
||||
}
|
||||
|
||||
if (version->v_version_release_phase
|
||||
if (version->v_version_unref_phase
|
||||
!= ROPKG_VERSION_RELEASE_PHASE_RELEASE) {
|
||||
b_stringstream_addf(
|
||||
&str,
|
||||
fx_stream_write_fmt(
|
||||
str,
|
||||
NULL,
|
||||
"~%s",
|
||||
release_phase_to_string(
|
||||
version->v_version_release_phase));
|
||||
version->v_version_unref_phase));
|
||||
|
||||
if (version->v_version_release_phase_revision > 1
|
||||
|| version->v_version_release_phase
|
||||
if (version->v_version_unref_phase_revision > 1
|
||||
|| version->v_version_unref_phase
|
||||
== ROPKG_VERSION_RELEASE_PHASE_RC) {
|
||||
b_stringstream_addf(
|
||||
&str,
|
||||
fx_stream_write_fmt(
|
||||
str,
|
||||
NULL,
|
||||
"%u",
|
||||
version->v_version_release_phase_revision);
|
||||
version->v_version_unref_phase_revision);
|
||||
}
|
||||
}
|
||||
|
||||
if (version->v_package_revision > 1) {
|
||||
b_stringstream_addf(&str, "-%u", version->v_package_revision);
|
||||
fx_stream_write_fmt(
|
||||
str,
|
||||
NULL,
|
||||
"-%u",
|
||||
version->v_package_revision);
|
||||
}
|
||||
|
||||
b_stringstream_end(&str);
|
||||
return b_stringstream_get_length(&str);
|
||||
size_t written = fx_stringstream_get_length(str);
|
||||
fx_stringstream_unref(str);
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
static int version_compare(
|
||||
@@ -443,14 +453,14 @@ static int version_compare(
|
||||
return 1; \
|
||||
} while (0)
|
||||
|
||||
COMPARE(left, right, v_release_phase);
|
||||
COMPARE(left, right, v_unref_phase);
|
||||
|
||||
for (int i = 0; i < ROPKG_VERSION_UPSTREAM_DIGIT_MAX; i++) {
|
||||
COMPARE(left, right, v_upstream_version[i]);
|
||||
}
|
||||
|
||||
COMPARE(left, right, v_version_release_phase);
|
||||
COMPARE(left, right, v_version_release_phase_revision);
|
||||
COMPARE(left, right, v_version_unref_phase);
|
||||
COMPARE(left, right, v_version_unref_phase_revision);
|
||||
COMPARE(left, right, v_package_revision);
|
||||
|
||||
#undef COMPARE
|
||||
|
||||
+3
-3
@@ -4,12 +4,12 @@
|
||||
#include <ropkg/version.h>
|
||||
|
||||
struct ropkg_version {
|
||||
enum ropkg_version_release_phase v_release_phase;
|
||||
enum ropkg_version_unref_phase v_unref_phase;
|
||||
|
||||
unsigned int v_upstream_version[ROPKG_VERSION_UPSTREAM_DIGIT_MAX];
|
||||
|
||||
enum ropkg_version_release_phase v_version_release_phase;
|
||||
unsigned int v_version_release_phase_revision;
|
||||
enum ropkg_version_unref_phase v_version_unref_phase;
|
||||
unsigned int v_version_unref_phase_revision;
|
||||
|
||||
unsigned int v_package_revision;
|
||||
};
|
||||
|
||||
+24
-24
@@ -1,12 +1,12 @@
|
||||
#include "tar.h"
|
||||
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <ropkg/writer.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct ropkg_writer {
|
||||
b_cstream *w_fp;
|
||||
fx_cstream *w_fp;
|
||||
|
||||
struct ustar_header w_file_header;
|
||||
size_t w_file_header_offset;
|
||||
@@ -15,7 +15,7 @@ struct ropkg_writer {
|
||||
|
||||
static const char zero_padding[512] = {0};
|
||||
|
||||
enum ropkg_status ropkg_writer_open(b_cstream *fp, struct ropkg_writer **out)
|
||||
enum ropkg_status ropkg_writer_open(fx_cstream *fp, struct ropkg_writer **out)
|
||||
{
|
||||
struct ropkg_writer *writer = malloc(sizeof *writer);
|
||||
if (!writer) {
|
||||
@@ -35,23 +35,23 @@ enum ropkg_status ropkg_writer_close(struct ropkg_writer *pkg)
|
||||
memset(&pkg->w_file_header, 0x0, sizeof pkg->w_file_header);
|
||||
|
||||
size_t nr_written;
|
||||
b_status status = b_cstream_write(
|
||||
fx_status status = fx_cstream_write(
|
||||
pkg->w_fp,
|
||||
&pkg->w_file_header,
|
||||
sizeof pkg->w_file_header,
|
||||
&nr_written);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
return ROPKG_ERR_IO_FAILURE;
|
||||
}
|
||||
|
||||
status = b_cstream_write(
|
||||
status = fx_cstream_write(
|
||||
pkg->w_fp,
|
||||
&pkg->w_file_header,
|
||||
sizeof pkg->w_file_header,
|
||||
&nr_written);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
return ROPKG_ERR_IO_FAILURE;
|
||||
}
|
||||
|
||||
@@ -108,12 +108,12 @@ enum ropkg_status ropkg_writer_begin_file(
|
||||
const char *path,
|
||||
const struct ropkg_writer_file_info *info)
|
||||
{
|
||||
if (b_cstream_in_compressed_section(pkg->w_fp)) {
|
||||
b_cstream_tx_bytes_uncompressed(
|
||||
if (fx_cstream_in_compressed_section(pkg->w_fp)) {
|
||||
fx_cstream_tx_bytes_uncompressed(
|
||||
pkg->w_fp,
|
||||
&pkg->w_file_header_offset);
|
||||
} else {
|
||||
b_cstream_tx_bytes(pkg->w_fp, &pkg->w_file_header_offset);
|
||||
fx_cstream_tx_bytes(pkg->w_fp, &pkg->w_file_header_offset);
|
||||
}
|
||||
|
||||
enum ropkg_status status
|
||||
@@ -123,13 +123,13 @@ enum ropkg_status ropkg_writer_begin_file(
|
||||
}
|
||||
|
||||
size_t nr_written;
|
||||
b_status status2 = b_cstream_write(
|
||||
fx_status status2 = fx_cstream_write(
|
||||
pkg->w_fp,
|
||||
&pkg->w_file_header,
|
||||
sizeof pkg->w_file_header,
|
||||
&nr_written);
|
||||
|
||||
if (!B_OK(status2)) {
|
||||
if (!FX_OK(status2)) {
|
||||
return ROPKG_ERR_IO_FAILURE;
|
||||
}
|
||||
|
||||
@@ -142,25 +142,25 @@ enum ropkg_status ropkg_writer_begin_file(
|
||||
|
||||
enum ropkg_status ropkg_writer_end_file(struct ropkg_writer *pkg)
|
||||
{
|
||||
b_status status;
|
||||
fx_status status;
|
||||
size_t written, file_length, pos;
|
||||
if (b_cstream_in_compressed_section(pkg->w_fp)) {
|
||||
b_cstream_tx_bytes_uncompressed(pkg->w_fp, &pos);
|
||||
if (fx_cstream_in_compressed_section(pkg->w_fp)) {
|
||||
fx_cstream_tx_bytes_uncompressed(pkg->w_fp, &pos);
|
||||
} else {
|
||||
b_cstream_tx_bytes(pkg->w_fp, &pos);
|
||||
fx_cstream_tx_bytes(pkg->w_fp, &pos);
|
||||
}
|
||||
|
||||
file_length
|
||||
= pos - pkg->w_file_header_offset - sizeof pkg->w_file_header;
|
||||
|
||||
size_t required_padding = 512 - (file_length % 512);
|
||||
status = b_cstream_write(
|
||||
status = fx_cstream_write(
|
||||
pkg->w_fp,
|
||||
zero_padding,
|
||||
required_padding,
|
||||
&written);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
return ROPKG_ERR_IO_FAILURE;
|
||||
}
|
||||
|
||||
@@ -170,16 +170,16 @@ enum ropkg_status ropkg_writer_end_file(struct ropkg_writer *pkg)
|
||||
sizeof pkg->w_file_header.tar_filesize);
|
||||
refresh_header_checksum(&pkg->w_file_header);
|
||||
|
||||
status = b_cstream_set_cursor_position(
|
||||
status = fx_cstream_set_cursor_position(
|
||||
pkg->w_fp,
|
||||
pkg->w_file_header_offset);
|
||||
if (B_OK(status)) {
|
||||
b_cstream_write(
|
||||
if (FX_OK(status)) {
|
||||
fx_cstream_write(
|
||||
pkg->w_fp,
|
||||
&pkg->w_file_header,
|
||||
sizeof pkg->w_file_header,
|
||||
&written);
|
||||
b_cstream_restore_cursor_position(pkg->w_fp);
|
||||
fx_cstream_restore_cursor_position(pkg->w_fp);
|
||||
}
|
||||
|
||||
return ROPKG_SUCCESS;
|
||||
@@ -191,8 +191,8 @@ enum ropkg_status ropkg_writer_write(
|
||||
size_t len,
|
||||
size_t *nr_written)
|
||||
{
|
||||
b_status status = b_cstream_write(pkg->w_fp, p, len, nr_written);
|
||||
if (!B_OK(status)) {
|
||||
fx_status status = fx_cstream_write(pkg->w_fp, p, len, nr_written);
|
||||
if (!FX_OK(status)) {
|
||||
return ROPKG_ERR_IO_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user