meta: replace bluelib with fx
This commit is contained in:
@@ -143,3 +143,4 @@ tags
|
||||
# End of https://www.toptal.com/developers/gitignore/api/linux,vim,c,cmake,macos
|
||||
|
||||
build/
|
||||
.cache
|
||||
|
||||
+2
-1
@@ -7,7 +7,8 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
|
||||
find_package(Bluelib COMPONENTS Core Object Io Term Cmd Compress REQUIRED)
|
||||
find_package(FX COMPONENTS fx.runtime fx.io fx.term fx.cmdline fx.compression REQUIRED)
|
||||
find_package(SQLite3 REQUIRED)
|
||||
|
||||
add_subdirectory(libropkg)
|
||||
add_subdirectory(ropkg)
|
||||
|
||||
@@ -1,189 +0,0 @@
|
||||
#[=======================================================================[.rst:
|
||||
FindBluelib
|
||||
------------
|
||||
|
||||
Find the Bluelib library and header directories
|
||||
|
||||
Imported Targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module defines the following :prop_tgt:`IMPORTED` target:
|
||||
|
||||
``Bluelib::Bluelib``
|
||||
The Bluelib library, if found
|
||||
|
||||
Result Variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module will set the following variables in your project:
|
||||
|
||||
``Bluelib_FOUND``
|
||||
true if the Bluelib C headers and libraries were found
|
||||
``Bluelib_INCLUDE_DIR``
|
||||
directories containing the Bluelib C headers.
|
||||
|
||||
``Bluelib_LIBRARY``
|
||||
the C library to link against
|
||||
|
||||
Hints
|
||||
^^^^^
|
||||
|
||||
The user may set the environment variable ``Bluelib_PREFIX`` to the root
|
||||
directory of a Bluelib library installation.
|
||||
#]=======================================================================]
|
||||
|
||||
set (Bluelib_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr/local/share
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
${Bluelib_PREFIX}
|
||||
$ENV{Bluelib_PREFIX})
|
||||
|
||||
if (Bluelib_STATIC)
|
||||
set(_lib_suffix "-s")
|
||||
endif ()
|
||||
|
||||
set(supported_components Core Object Term Cmd Io Serial Compress)
|
||||
set(components ${Bluelib_FIND_COMPONENTS})
|
||||
string(REPLACE ";" ", " supported_components_string_list "${supported_components}")
|
||||
|
||||
if (NOT components)
|
||||
set(components ${supported_components})
|
||||
endif ()
|
||||
|
||||
set(required_vars)
|
||||
|
||||
foreach (component ${components})
|
||||
if (NOT "${component}" IN_LIST supported_components)
|
||||
message(FATAL_ERROR "'${component}' is not a valid Bluelib module.\nSupported modules: ${supported_components_string_list}")
|
||||
endif ()
|
||||
|
||||
string(TOLOWER ${component} header_name)
|
||||
set(lib_name ${header_name}${_lib_suffix})
|
||||
|
||||
if (NOT Bluelib_${component}_INCLUDE_DIR)
|
||||
find_path(Bluelib_${component}_INCLUDE_DIR
|
||||
NAMES blue/${header_name}.h ${Bluelib_FIND_ARGS}
|
||||
PATH_SUFFIXES include
|
||||
PATHS ${Bluelib_SEARCH_PATHS})
|
||||
endif ()
|
||||
|
||||
if (NOT Bluelib_${component}_LIBRARY)
|
||||
find_library(Bluelib_${component}_LIBRARY
|
||||
NAMES blue-${lib_name} ${Bluelib_FIND_ARGS}
|
||||
PATH_SUFFIXES lib
|
||||
PATHS ${Bluelib_SEARCH_PATHS})
|
||||
else ()
|
||||
# on Windows, ensure paths are in canonical format (forward slahes):
|
||||
file(TO_CMAKE_PATH "${Bluelib_${component}_LIBRARY}" Bluelib_${component}_LIBRARY)
|
||||
endif()
|
||||
|
||||
list(APPEND required_vars Bluelib_${component}_INCLUDE_DIR Bluelib_${component}_LIBRARY)
|
||||
endforeach (component)
|
||||
|
||||
unset(Bluelib_FIND_ARGS)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(Bluelib
|
||||
REQUIRED_VARS ${required_vars})
|
||||
|
||||
if (Bluelib_FOUND)
|
||||
set(created_targets)
|
||||
foreach (component ${components})
|
||||
string(TOLOWER ${component} header_name)
|
||||
set(lib_name ${header_name}${_lib_suffix})
|
||||
|
||||
if(NOT TARGET Bluelib::${component})
|
||||
add_library(Bluelib::${component} UNKNOWN IMPORTED)
|
||||
set_target_properties(Bluelib::${component} PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${Bluelib_${component}_INCLUDE_DIR}")
|
||||
target_compile_definitions(Bluelib::${component} INTERFACE _CRT_SECURE_NO_WARNINGS=1)
|
||||
|
||||
if (Bluelib_STATIC)
|
||||
target_compile_definitions(Bluelib::${component} INTERFACE BLUELIB_STATIC=1)
|
||||
endif ()
|
||||
|
||||
set_target_properties(Bluelib::${component} PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${Bluelib_${component}_LIBRARY}")
|
||||
set(created_targets ${created_targets} ${component})
|
||||
endif ()
|
||||
endforeach (component)
|
||||
|
||||
foreach (component ${created_targets})
|
||||
if ("${component}" STREQUAL "Object")
|
||||
if (NOT TARGET Bluelib::Core)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Object' depends on 'Core', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Object INTERFACE Bluelib::Core)
|
||||
endif ()
|
||||
|
||||
if ("${component}" STREQUAL "Term")
|
||||
if (NOT TARGET Bluelib::Core)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Core', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
if (NOT TARGET Bluelib::Object)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Object', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Object)
|
||||
endif ()
|
||||
|
||||
if ("${component}" STREQUAL "Serial")
|
||||
if (NOT TARGET Bluelib::Core)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Core', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
if (NOT TARGET Bluelib::Object)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Object', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Object)
|
||||
endif ()
|
||||
|
||||
if ("${component}" STREQUAL "Cmd")
|
||||
if (NOT TARGET Bluelib::Core)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Core', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
if (NOT TARGET Bluelib::Object)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Object', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
if (NOT TARGET Bluelib::Term)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Term', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Object Bluelib::Term)
|
||||
endif ()
|
||||
|
||||
if ("${component}" STREQUAL "Io")
|
||||
if (NOT TARGET Bluelib::Core)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Core', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
if (NOT TARGET Bluelib::Object)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Object', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Object)
|
||||
endif ()
|
||||
|
||||
if ("${component}" STREQUAL "Compress")
|
||||
if (NOT TARGET Bluelib::Core)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Compress' depends on 'Core', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Object)
|
||||
endif ()
|
||||
endforeach (component)
|
||||
endif()
|
||||
@@ -0,0 +1,132 @@
|
||||
#[=======================================================================[.rst:
|
||||
FindFX
|
||||
------------
|
||||
|
||||
Find the FX library and header directories
|
||||
|
||||
Imported Targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module defines the following :prop_tgt:`IMPORTED` target:
|
||||
|
||||
``FX::FX``
|
||||
The FX library, if found
|
||||
|
||||
Result Variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module will set the following variables in your project:
|
||||
|
||||
``FX_FOUND``
|
||||
true if the FX C headers and libraries were found
|
||||
``FX_INCLUDE_DIR``
|
||||
directories containing the FX C headers.
|
||||
|
||||
``FX_LIBRARY``
|
||||
the C library to link against
|
||||
|
||||
Hints
|
||||
^^^^^
|
||||
|
||||
The user may set the environment variable ``FX_PREFIX`` to the root
|
||||
directory of a FX library installation.
|
||||
#]=======================================================================]
|
||||
|
||||
set (FX_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr/local/share
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
${FX_PREFIX}
|
||||
$ENV{FX_PREFIX})
|
||||
|
||||
if (FX_STATIC)
|
||||
set(_lib_suffix "-s")
|
||||
endif ()
|
||||
|
||||
set(assemblies ${FX_FIND_COMPONENTS})
|
||||
set(required_vars)
|
||||
set(in_tree FALSE)
|
||||
|
||||
foreach (assembly ${assemblies})
|
||||
string(TOLOWER ${assembly} header_name)
|
||||
string(REPLACE "." "_" macro_name ${assembly})
|
||||
string(TOUPPER ${macro_name} macro_name)
|
||||
|
||||
set(lib_name ${assembly}${_lib_suffix})
|
||||
|
||||
if (NOT ${macro_name}_LIBRARY)
|
||||
if (TARGET ${assembly})
|
||||
set (${macro_name}_LIBRARY ${assembly})
|
||||
set(in_tree TRUE)
|
||||
else ()
|
||||
find_library(${macro_name}_LIBRARY
|
||||
NAMES ${lib_name} ${FX_FIND_ARGS}
|
||||
PATH_SUFFIXES lib
|
||||
PATHS ${FX_SEARCH_PATHS})
|
||||
endif ()
|
||||
else ()
|
||||
# on Windows, ensure paths are in canonical format (forward slahes):
|
||||
file(TO_CMAKE_PATH "${${macro_name}_LIBRARY}" ${macro_name}_LIBRARY)
|
||||
endif()
|
||||
|
||||
list(APPEND required_vars ${macro_name}_LIBRARY)
|
||||
endforeach (assembly)
|
||||
|
||||
if (NOT FX_INCLUDE_DIR AND NOT in_tree)
|
||||
list(APPEND required_vars FX_INCLUDE_DIR)
|
||||
find_path(FX_INCLUDE_DIR
|
||||
NAMES fx/misc.h ${FX_FIND_ARGS}
|
||||
PATH_SUFFIXES include
|
||||
PATHS ${FX_SEARCH_PATHS})
|
||||
endif ()
|
||||
|
||||
unset(FX_FIND_ARGS)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(FX
|
||||
REQUIRED_VARS ${required_vars})
|
||||
|
||||
if (FX_FOUND)
|
||||
set(created_targets)
|
||||
foreach (assembly ${assemblies})
|
||||
set(target_name ${assembly})
|
||||
string(REPLACE "fx." "" target_name ${target_name})
|
||||
string(SUBSTRING ${target_name} 0 1 target_name_prefix)
|
||||
string(TOUPPER ${target_name_prefix} target_name_prefix)
|
||||
string(SUBSTRING ${target_name} 1 -1 target_name_suffix)
|
||||
set(target_name ${target_name_prefix}${target_name_suffix})
|
||||
|
||||
string(TOLOWER ${assembly} header_name)
|
||||
string(REPLACE "." "_" macro_name ${assembly})
|
||||
string(REPLACE "." "_" macro_name ${assembly})
|
||||
string(TOUPPER ${macro_name} macro_name)
|
||||
|
||||
set(lib_name ${assembly}${_lib_suffix})
|
||||
|
||||
if (NOT TARGET FX::${target_name})
|
||||
if (TARGET ${assembly})
|
||||
add_library(FX::${target_name} ALIAS ${assembly})
|
||||
else ()
|
||||
add_library(FX::${target_name} UNKNOWN IMPORTED)
|
||||
set_target_properties(FX::${target_name} PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${FX_INCLUDE_DIR}")
|
||||
target_compile_definitions(FX::${target_name} INTERFACE _CRT_SECURE_NO_WARNINGS=1)
|
||||
|
||||
if (FX_STATIC)
|
||||
target_compile_definitions(FX::${target_name} INTERFACE FX_STATIC=1)
|
||||
endif ()
|
||||
set_target_properties(FX::${target_name} PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${${macro_name}_LIBRARY}")
|
||||
endif ()
|
||||
set(created_targets ${created_targets} ${assembly})
|
||||
endif ()
|
||||
endforeach (assembly)
|
||||
endif()
|
||||
@@ -0,0 +1,21 @@
|
||||
client:
|
||||
|
||||
- status.rodb
|
||||
* contains the list of installed packages with metadata
|
||||
- packages.rodb
|
||||
* contains the list of available packages with metadata, and details of the repositories
|
||||
they are available from.
|
||||
|
||||
repo:
|
||||
|
||||
- meta.rodb
|
||||
* contains information about the repo itself, including name, description, available channels, target system, and available news items.
|
||||
* this is the database that will be downloaded when a client adds a repo
|
||||
or refreshes their repo database.
|
||||
|
||||
- channels/$channel/packages.rodb
|
||||
* contains the list of available packages with metadata.
|
||||
* when a client refreshes their repo database, it will download
|
||||
the packages.rodb file from every channel it has registered, and will
|
||||
merge the contents into its local copy of packages.rodb
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
Name: Sample Repository
|
||||
Description: Official Sample Repository
|
||||
System: sample
|
||||
Architectures: amd64 any
|
||||
Components: universe multiverse
|
||||
Channels: vanilla
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,4 @@ file(GLOB_RECURSE sources *.c *.h)
|
||||
add_executable(ropam ${sources})
|
||||
target_link_libraries(ropam
|
||||
libropkg
|
||||
Bluelib::Core Bluelib::Object Bluelib::Io Bluelib::Term Bluelib::Cmd)
|
||||
FX::Runtime FX::Io FX::Term FX::Cmdline)
|
||||
|
||||
+24
-22
@@ -1,6 +1,6 @@
|
||||
#include "commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <ropkg/instance.h>
|
||||
|
||||
enum {
|
||||
@@ -8,53 +8,55 @@ enum {
|
||||
};
|
||||
|
||||
static int bootstrap(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const char *root_path = NULL;
|
||||
b_status status = b_arglist_get_string(
|
||||
fx_status status = fx_arglist_get_string(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PATH,
|
||||
0,
|
||||
&root_path);
|
||||
if (!B_OK(status)) {
|
||||
b_arglist_report_missing_args(
|
||||
if (!FX_OK(status)) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PATH,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_instance *inst;
|
||||
b_result result = ropkg_instance_bootstrap(root_path, &inst);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
fx_result result = ropkg_instance_bootstrap(root_path, &inst);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ropkg_instance_close(inst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_BOOTSTRAP, CMD_ROOT)
|
||||
FX_COMMAND(CMD_BOOTSTRAP, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("bootstrap");
|
||||
B_COMMAND_DESC(
|
||||
FX_COMMAND_NAME("bootstrap");
|
||||
FX_COMMAND_DESC(
|
||||
"initialise a new Rosetta package manager instance. use this "
|
||||
"command to prepare a sysroot for the installation of Rosetta "
|
||||
"packages.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(bootstrap);
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(bootstrap);
|
||||
|
||||
B_COMMAND_ARG(ARG_PATH)
|
||||
FX_COMMAND_ARG(ARG_PATH)
|
||||
{
|
||||
B_ARG_NAME("sysroot");
|
||||
B_ARG_DESC(
|
||||
FX_ARG_NAME("sysroot");
|
||||
FX_ARG_DESC(
|
||||
"the path to the system root directory to initialise.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
+7
-7
@@ -20,21 +20,21 @@ enum {
|
||||
};
|
||||
|
||||
#define SYSROOT_OPTION \
|
||||
B_COMMAND_OPTION(OPT_SYSROOT) \
|
||||
FX_COMMAND_OPTION(OPT_SYSROOT) \
|
||||
{ \
|
||||
B_OPTION_SHORT_NAME('s'); \
|
||||
B_OPTION_LONG_NAME("sysroot"); \
|
||||
B_OPTION_DESC( \
|
||||
FX_OPTION_SHORT_NAME('s'); \
|
||||
FX_OPTION_LONG_NAME("sysroot"); \
|
||||
FX_OPTION_DESC( \
|
||||
"the system directory to use. if no " \
|
||||
"sysroot is specified, the root directory is used. " \
|
||||
"alternatively, the ROSETTA_SYSROOT environment " \
|
||||
"variable can be used to specify the system root " \
|
||||
"directory"); \
|
||||
\
|
||||
B_OPTION_ARG(OPT_SYSROOT_PATH) \
|
||||
FX_OPTION_ARG(OPT_SYSROOT_PATH) \
|
||||
{ \
|
||||
B_ARG_NAME("path"); \
|
||||
B_ARG_NR_VALUES(1); \
|
||||
FX_ARG_NAME("path"); \
|
||||
FX_ARG_NR_VALUES(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
+17
-17
@@ -1,37 +1,37 @@
|
||||
#include "commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/term/print.h>
|
||||
|
||||
B_COMMAND(CMD_ROOT, B_COMMAND_INVALID_ID)
|
||||
FX_COMMAND(CMD_ROOT, FX_COMMAND_INVALID_ID)
|
||||
{
|
||||
B_COMMAND_NAME("ropam");
|
||||
B_COMMAND_DESC(
|
||||
FX_COMMAND_NAME("ropam");
|
||||
FX_COMMAND_DESC(
|
||||
"Rosetta package manager. This tool is used to (un)install, "
|
||||
"upgrade, and otherwise manage packages on a system via a set "
|
||||
"of package vendors.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
SYSROOT_OPTION;
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_OPT(OPT_SYSROOT);
|
||||
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_OPT(OPT_SYSROOT);
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
b_set_error_report_function(
|
||||
b_enhanced_error_reporter,
|
||||
B_ERROR_REPORT_ALL);
|
||||
return b_command_dispatch(CMD_ROOT, argc, argv);
|
||||
fx_set_error_report_function(
|
||||
fx_enhanced_error_reporter,
|
||||
FX_ERROR_REPORT_ALL);
|
||||
return fx_command_dispatch(CMD_ROOT, argc, argv);
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,22 +1,22 @@
|
||||
#include "commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
static int query(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_QUERY, CMD_ROOT)
|
||||
FX_COMMAND(CMD_QUERY, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("query");
|
||||
B_COMMAND_SHORT_NAME('Q');
|
||||
B_COMMAND_DESC("query information about installed packages.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(query);
|
||||
FX_COMMAND_NAME("query");
|
||||
FX_COMMAND_SHORT_NAME('Q');
|
||||
FX_COMMAND_DESC("query information about installed packages.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(query);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
+17
-17
@@ -1,42 +1,42 @@
|
||||
#include "commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
enum {
|
||||
ARG_PACKAGE,
|
||||
};
|
||||
|
||||
static int remove(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_REMOVE, CMD_ROOT)
|
||||
FX_COMMAND(CMD_REMOVE, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("remove");
|
||||
B_COMMAND_SHORT_NAME('R');
|
||||
B_COMMAND_DESC(
|
||||
FX_COMMAND_NAME("remove");
|
||||
FX_COMMAND_SHORT_NAME('R');
|
||||
FX_COMMAND_DESC(
|
||||
"remove a set of Rosetta packages by name. any "
|
||||
"automatically installed dependencies will not be removed "
|
||||
"unless they are explicitly named in the list of packages to "
|
||||
"remove.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(remove);
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(remove);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_ARG(ARG_PACKAGE)
|
||||
FX_COMMAND_ARG(ARG_PACKAGE)
|
||||
{
|
||||
B_ARG_NAME("package-name");
|
||||
B_ARG_DESC("the names of the packages to remove.");
|
||||
B_ARG_NR_VALUES(B_ARG_1_OR_MORE_VALUES);
|
||||
FX_ARG_NAME("package-name");
|
||||
FX_ARG_DESC("the names of the packages to remove.");
|
||||
FX_ARG_NR_VALUES(FX_ARG_1_OR_MORE_VALUES);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_PACKAGE);
|
||||
FX_COMMAND_USAGE_ARG(ARG_PACKAGE);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,22 +1,22 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
static int repo_add(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_REPO_ADD, CMD_REPO)
|
||||
FX_COMMAND(CMD_REPO_ADD, CMD_REPO)
|
||||
{
|
||||
B_COMMAND_NAME("add");
|
||||
B_COMMAND_SHORT_NAME('A');
|
||||
B_COMMAND_DESC("add a new package repository to the system.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(repo_add);
|
||||
FX_COMMAND_NAME("add");
|
||||
FX_COMMAND_SHORT_NAME('A');
|
||||
FX_COMMAND_DESC("add a new package repository to the system.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(repo_add);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,22 +1,22 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
static int repo_list(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_REPO_LIST, CMD_REPO)
|
||||
FX_COMMAND(CMD_REPO_LIST, CMD_REPO)
|
||||
{
|
||||
B_COMMAND_NAME("list");
|
||||
B_COMMAND_SHORT_NAME('L');
|
||||
B_COMMAND_DESC("list all registered package repositories.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(repo_list);
|
||||
FX_COMMAND_NAME("list");
|
||||
FX_COMMAND_SHORT_NAME('L');
|
||||
FX_COMMAND_DESC("list all registered package repositories.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(repo_list);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,22 +1,22 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
static int repo_remove(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_REPO_REMOVE, CMD_REPO)
|
||||
FX_COMMAND(CMD_REPO_REMOVE, CMD_REPO)
|
||||
{
|
||||
B_COMMAND_NAME("remove");
|
||||
B_COMMAND_SHORT_NAME('R');
|
||||
B_COMMAND_DESC("remove a package repository from the system.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(repo_remove);
|
||||
FX_COMMAND_NAME("remove");
|
||||
FX_COMMAND_SHORT_NAME('R');
|
||||
FX_COMMAND_DESC("remove a package repository from the system.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(repo_remove);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,13 +1,13 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
B_COMMAND(CMD_REPO, CMD_ROOT)
|
||||
FX_COMMAND(CMD_REPO, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("repo");
|
||||
B_COMMAND_SHORT_NAME('V');
|
||||
B_COMMAND_DESC("package repository management commands.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_NAME("repo");
|
||||
FX_COMMAND_SHORT_NAME('V');
|
||||
FX_COMMAND_DESC("package repository management commands.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
+36
-25
@@ -1,6 +1,6 @@
|
||||
#include "commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
enum {
|
||||
OPT_SYNC_DB,
|
||||
@@ -10,63 +10,74 @@ enum {
|
||||
};
|
||||
|
||||
static int sync(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_SYNC, CMD_ROOT)
|
||||
FX_COMMAND(CMD_SYNC, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("sync");
|
||||
B_COMMAND_SHORT_NAME('S');
|
||||
B_COMMAND_DESC(
|
||||
FX_COMMAND_NAME("sync");
|
||||
FX_COMMAND_SHORT_NAME('S');
|
||||
FX_COMMAND_DESC(
|
||||
"synchronise your machine with the your registered package "
|
||||
"vendor(s). this command can be used to synchronise packages, "
|
||||
"installing them or updating them to the latest available "
|
||||
"version. all installed packages can be synchronised to update "
|
||||
"the whole system, or the package database itself can be "
|
||||
"synchronised to gain access to new and updated packages.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(sync);
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(sync);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_OPTION(OPT_SYNC_DB)
|
||||
FX_COMMAND_OPTION(OPT_SYNC_DB)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('y');
|
||||
B_OPTION_LONG_NAME("database");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('y');
|
||||
FX_OPTION_LONG_NAME("database");
|
||||
FX_OPTION_DESC(
|
||||
"synchronise the package database before synchronising "
|
||||
"any packages. this option can be specified without "
|
||||
"any package names to synchronise the package database "
|
||||
"on its own.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_SYNC_ALL)
|
||||
FX_COMMAND_OPTION(OPT_SYNC_ALL)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('u');
|
||||
B_OPTION_LONG_NAME("synchronise-all");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('u');
|
||||
FX_OPTION_LONG_NAME("synchronise-all");
|
||||
FX_OPTION_DESC(
|
||||
"synchronise all packages currently installed on the "
|
||||
"system, updating them to the latest available "
|
||||
"version.");
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_PACKAGE)
|
||||
FX_COMMAND_ARG(ARG_PACKAGE)
|
||||
{
|
||||
B_ARG_NAME("package-name");
|
||||
B_ARG_DESC(
|
||||
FX_ARG_NAME("package-name");
|
||||
FX_ARG_DESC(
|
||||
"the names of the packages to synchronise. if a named "
|
||||
"package is not installed, the latest version will be "
|
||||
"installed. otherwise, the already-installed package "
|
||||
"will be updated to the latest version.");
|
||||
B_ARG_NR_VALUES(B_ARG_1_OR_MORE_VALUES);
|
||||
FX_ARG_NR_VALUES(FX_ARG_0_OR_MORE_VALUES);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_PACKAGE);
|
||||
FX_COMMAND_USAGE_ARG(ARG_PACKAGE);
|
||||
}
|
||||
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
FX_COMMAND_USAGE_OPT(OPT_SYNC_DB);
|
||||
}
|
||||
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
FX_COMMAND_USAGE_OPT(OPT_SYNC_DB);
|
||||
FX_COMMAND_USAGE_OPT(OPT_SYNC_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ file(GLOB_RECURSE sources *.c *.h)
|
||||
add_executable(ropkg ${sources})
|
||||
target_link_libraries(ropkg
|
||||
libropkg
|
||||
Bluelib::Core Bluelib::Object Bluelib::Io Bluelib::Term Bluelib::Cmd)
|
||||
FX::Runtime FX::Io FX::Term FX::Cmdline)
|
||||
|
||||
+14
-14
@@ -1,29 +1,29 @@
|
||||
#include "commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/term/print.h>
|
||||
|
||||
B_COMMAND(CMD_ROOT, B_COMMAND_INVALID_ID)
|
||||
FX_COMMAND(CMD_ROOT, FX_COMMAND_INVALID_ID)
|
||||
{
|
||||
B_COMMAND_NAME("ropkg");
|
||||
B_COMMAND_DESC(
|
||||
FX_COMMAND_NAME("ropkg");
|
||||
FX_COMMAND_DESC(
|
||||
"Rosetta package manipulation tool. This tool is used to "
|
||||
"create, build, and otherwise manipulate individual Rosetta "
|
||||
"package files.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
b_set_error_report_function(
|
||||
b_enhanced_error_reporter,
|
||||
B_ERROR_REPORT_ALL);
|
||||
return b_command_dispatch(CMD_ROOT, argc, argv);
|
||||
fx_set_error_report_function(
|
||||
fx_enhanced_error_reporter,
|
||||
FX_ERROR_REPORT_ALL);
|
||||
return fx_command_dispatch(CMD_ROOT, argc, argv);
|
||||
}
|
||||
|
||||
+39
-39
@@ -1,6 +1,6 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <ropkg/pkg-expr.h>
|
||||
#include <ropkg/version.h>
|
||||
#include <stdio.h>
|
||||
@@ -15,92 +15,92 @@ enum {
|
||||
};
|
||||
|
||||
static int create(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const char *headers_path = NULL, *readme_path = NULL, *out_path = NULL;
|
||||
b_status status = b_arglist_get_string(
|
||||
fx_status status = fx_arglist_get_string(
|
||||
opt,
|
||||
OPT_HEADERS,
|
||||
OPT_HEADERS_PATH,
|
||||
0,
|
||||
&headers_path);
|
||||
if (!B_OK(status)) {
|
||||
b_arglist_report_missing_option(opt, OPT_HEADERS);
|
||||
if (!FX_OK(status)) {
|
||||
fx_arglist_report_missing_option(opt, OPT_HEADERS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = b_arglist_get_string(
|
||||
status = fx_arglist_get_string(
|
||||
opt,
|
||||
OPT_README,
|
||||
OPT_README_PATH,
|
||||
0,
|
||||
&headers_path);
|
||||
if (!B_OK(status)) {
|
||||
b_arglist_report_missing_option(opt, OPT_README);
|
||||
if (!FX_OK(status)) {
|
||||
fx_arglist_report_missing_option(opt, OPT_README);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_arglist_get_string(opt, OPT_OUTPATH, OPT_OUTPATH_PATH, 0, &out_path);
|
||||
fx_arglist_get_string(opt, OPT_OUTPATH, OPT_OUTPATH_PATH, 0, &out_path);
|
||||
|
||||
FILE *headers, *readme, *out;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_MANIFEST_CREATE, CMD_MANIFEST)
|
||||
FX_COMMAND(CMD_MANIFEST_CREATE, CMD_MANIFEST)
|
||||
{
|
||||
B_COMMAND_NAME("create");
|
||||
B_COMMAND_SHORT_NAME('C');
|
||||
B_COMMAND_DESC("create a manifest file.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(create);
|
||||
FX_COMMAND_NAME("create");
|
||||
FX_COMMAND_SHORT_NAME('C');
|
||||
FX_COMMAND_DESC("create a manifest file.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(create);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_OPTION(OPT_HEADERS)
|
||||
FX_COMMAND_OPTION(OPT_HEADERS)
|
||||
{
|
||||
B_OPTION_LONG_NAME("headers");
|
||||
B_OPTION_SHORT_NAME('H');
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_LONG_NAME("headers");
|
||||
FX_OPTION_SHORT_NAME('H');
|
||||
FX_OPTION_DESC(
|
||||
"The path to a json file describing the package "
|
||||
"manifest headers.");
|
||||
|
||||
B_OPTION_ARG(OPT_HEADERS_PATH)
|
||||
FX_OPTION_ARG(OPT_HEADERS_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_README)
|
||||
FX_COMMAND_OPTION(OPT_README)
|
||||
{
|
||||
B_OPTION_LONG_NAME("readme");
|
||||
B_OPTION_SHORT_NAME('R');
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_LONG_NAME("readme");
|
||||
FX_OPTION_SHORT_NAME('R');
|
||||
FX_OPTION_DESC(
|
||||
"The path to a plaintext file describing the package.");
|
||||
|
||||
B_OPTION_ARG(OPT_README_PATH)
|
||||
FX_OPTION_ARG(OPT_README_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_OUTPATH)
|
||||
FX_COMMAND_OPTION(OPT_OUTPATH)
|
||||
{
|
||||
B_OPTION_LONG_NAME("out");
|
||||
B_OPTION_SHORT_NAME('o');
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_LONG_NAME("out");
|
||||
FX_OPTION_SHORT_NAME('o');
|
||||
FX_OPTION_DESC(
|
||||
"The path to write the new manifest file to. If no "
|
||||
"path is specified, the manifest will be written to "
|
||||
"standard out.");
|
||||
|
||||
B_OPTION_ARG(OPT_OUTPATH_PATH)
|
||||
FX_OPTION_ARG(OPT_OUTPATH_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,19 +1,19 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/term/print.h>
|
||||
|
||||
B_COMMAND(CMD_MANIFEST, CMD_ROOT)
|
||||
FX_COMMAND(CMD_MANIFEST, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("manifest");
|
||||
B_COMMAND_SHORT_NAME('M');
|
||||
B_COMMAND_DESC("Package manifest inspection and manipulation.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_NAME("manifest");
|
||||
FX_COMMAND_SHORT_NAME('M');
|
||||
FX_COMMAND_DESC("Package manifest inspection and manipulation.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
|
||||
+52
-51
@@ -1,7 +1,7 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/manifest.h>
|
||||
#include <ropkg/pkg-expr.h>
|
||||
#include <ropkg/status.h>
|
||||
@@ -113,32 +113,33 @@ static void print_pkg_expr(const struct ropkg_pkg_expr *expr)
|
||||
}
|
||||
}
|
||||
|
||||
static b_result validate_pkg_expr_value(
|
||||
static fx_result validate_pkg_expr_value(
|
||||
const struct ropkg_manifest_value *value)
|
||||
{
|
||||
const char *value_str = ropkg_manifest_value_get_string(value);
|
||||
if (!value_str) {
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_MANIFEST_FORMAT);
|
||||
}
|
||||
|
||||
struct ropkg_pkg_expr *pkg_expr = NULL;
|
||||
b_result result = ropkg_pkg_expr_parse(value_str, &pkg_expr);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
fx_result result = ropkg_pkg_expr_parse(value_str, &pkg_expr);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
print_pkg_expr(pkg_expr);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result validate_version_value(const struct ropkg_manifest_value *value)
|
||||
static fx_result validate_version_value(
|
||||
const struct ropkg_manifest_value *value)
|
||||
{
|
||||
const char *value_str = ropkg_manifest_value_get_string(value);
|
||||
if (!value_str) {
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_MANIFEST_FORMAT);
|
||||
}
|
||||
@@ -146,12 +147,12 @@ static b_result validate_version_value(const struct ropkg_manifest_value *value)
|
||||
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, value_str);
|
||||
if (b_result_is_error(result)) {
|
||||
return b_result_propagate(result);
|
||||
fx_result result = ropkg_version_parse(version, value_str);
|
||||
if (fx_result_is_error(result)) {
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
char temp[128];
|
||||
@@ -160,54 +161,54 @@ static b_result validate_version_value(const struct ropkg_manifest_value *value)
|
||||
|
||||
printf("%s", temp);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result validate_string_value(const struct ropkg_manifest_value *value)
|
||||
static fx_result validate_string_value(const struct ropkg_manifest_value *value)
|
||||
{
|
||||
const char *value_str = ropkg_manifest_value_get_string(value);
|
||||
if (!value_str) {
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_MANIFEST_FORMAT);
|
||||
}
|
||||
|
||||
printf("%s", value_str);
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static b_result validate_int_value(const struct ropkg_manifest_value *value)
|
||||
static fx_result validate_int_value(const struct ropkg_manifest_value *value)
|
||||
{
|
||||
if (ropkg_manifest_value_get_type(value)
|
||||
!= ROPKG_MANIFEST_VALUE_T_INT) {
|
||||
return b_error_with_code(
|
||||
return fx_error_with_code(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_INVALID_MANIFEST_FORMAT);
|
||||
}
|
||||
|
||||
printf("%zu", ropkg_manifest_value_get_int(value));
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int validate(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const char *manifest_path;
|
||||
b_status status = b_arglist_get_string(
|
||||
fx_status status = fx_arglist_get_string(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_MANIFEST,
|
||||
0,
|
||||
&manifest_path);
|
||||
if (!B_OK(status)) {
|
||||
b_arglist_report_missing_args(
|
||||
if (!FX_OK(status)) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_MANIFEST,
|
||||
0);
|
||||
return -1;
|
||||
@@ -215,26 +216,26 @@ static int validate(
|
||||
|
||||
FILE *fp = fopen(manifest_path, "r");
|
||||
if (!fp) {
|
||||
b_throw_error_code(ROPKG_ERROR_VENDOR, ROPKG_ERR_NO_ENTRY);
|
||||
fx_throw_error_code(ROPKG_ERROR_VENDOR, ROPKG_ERR_NO_ENTRY);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_manifest *manifest;
|
||||
enum ropkg_status status2 = ropkg_manifest_create(&manifest);
|
||||
if (status2 != ROPKG_SUCCESS) {
|
||||
b_throw_error_code(ROPKG_ERROR_VENDOR, status2);
|
||||
fx_throw_error_code(ROPKG_ERROR_VENDOR, status2);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_result result = ropkg_manifest_parse(fp, manifest);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
fx_result result = ropkg_manifest_parse(fp, manifest);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const struct ropkg_manifest_value *value
|
||||
= ropkg_manifest_get_first_value(manifest);
|
||||
while (value && b_result_is_success(result)) {
|
||||
while (value && fx_result_is_success(result)) {
|
||||
const char *name = ropkg_manifest_value_get_name(value);
|
||||
enum ropkg_manifest_value_type type
|
||||
= ropkg_manifest_value_get_type(value);
|
||||
@@ -275,33 +276,33 @@ static int validate(
|
||||
value = ropkg_manifest_get_next_value(manifest, value);
|
||||
}
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_MANIFEST_VALIDATE, CMD_MANIFEST)
|
||||
FX_COMMAND(CMD_MANIFEST_VALIDATE, CMD_MANIFEST)
|
||||
{
|
||||
B_COMMAND_NAME("validate");
|
||||
B_COMMAND_SHORT_NAME('V');
|
||||
B_COMMAND_DESC("check a manifest file for errors.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(validate);
|
||||
FX_COMMAND_NAME("validate");
|
||||
FX_COMMAND_SHORT_NAME('V');
|
||||
FX_COMMAND_DESC("check a manifest file for errors.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(validate);
|
||||
|
||||
B_COMMAND_ARG(ARG_MANIFEST)
|
||||
FX_COMMAND_ARG(ARG_MANIFEST)
|
||||
{
|
||||
B_ARG_NAME("manifest-path");
|
||||
B_ARG_DESC("the manifest file to validate");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("manifest-path");
|
||||
FX_ARG_DESC("the manifest file to validate");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_MANIFEST);
|
||||
FX_COMMAND_USAGE_ARG(ARG_MANIFEST);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,19 +1,19 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/term/print.h>
|
||||
|
||||
B_COMMAND(CMD_NEWS, CMD_ROOT)
|
||||
FX_COMMAND(CMD_NEWS, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("news");
|
||||
B_COMMAND_SHORT_NAME('N');
|
||||
B_COMMAND_DESC("News file inspection and manipulation.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_NAME("news");
|
||||
FX_COMMAND_SHORT_NAME('N');
|
||||
FX_COMMAND_DESC("News file inspection and manipulation.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
|
||||
+42
-42
@@ -1,6 +1,6 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
enum {
|
||||
OPT_OUTPATH,
|
||||
@@ -17,86 +17,86 @@ enum {
|
||||
};
|
||||
|
||||
static int build(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_BUILD, CMD_PACKAGE)
|
||||
FX_COMMAND(CMD_PACKAGE_BUILD, CMD_PACKAGE)
|
||||
{
|
||||
B_COMMAND_NAME("build");
|
||||
B_COMMAND_SHORT_NAME('B');
|
||||
B_COMMAND_DESC("build a Rosetta package from a recipe");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(build);
|
||||
FX_COMMAND_NAME("build");
|
||||
FX_COMMAND_SHORT_NAME('B');
|
||||
FX_COMMAND_DESC("build a Rosetta package from a recipe");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(build);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_OPTION(OPT_OUTPATH)
|
||||
FX_COMMAND_OPTION(OPT_OUTPATH)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('o');
|
||||
B_OPTION_LONG_NAME("out");
|
||||
B_OPTION_DESC("the path to save the new package file to");
|
||||
FX_OPTION_SHORT_NAME('o');
|
||||
FX_OPTION_LONG_NAME("out");
|
||||
FX_OPTION_DESC("the path to save the new package file to");
|
||||
|
||||
B_OPTION_ARG(OPT_OUTPATH_PATH)
|
||||
FX_OPTION_ARG(OPT_OUTPATH_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_SOURCE_DIRECTORY)
|
||||
FX_COMMAND_OPTION(OPT_SOURCE_DIRECTORY)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('s');
|
||||
B_OPTION_LONG_NAME("source-dir");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('s');
|
||||
FX_OPTION_LONG_NAME("source-dir");
|
||||
FX_OPTION_DESC(
|
||||
"the source directory to build the package from. if no "
|
||||
"source directory is specified, the recipe will "
|
||||
"download the sources automatically.");
|
||||
|
||||
B_OPTION_ARG(OPT_SOURCE_DIRECTORY_PATH)
|
||||
FX_OPTION_ARG(OPT_SOURCE_DIRECTORY_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_EXT_SOURCE_DIRECTORY)
|
||||
FX_COMMAND_OPTION(OPT_EXT_SOURCE_DIRECTORY)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('S');
|
||||
B_OPTION_LONG_NAME("named-source-dir");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('S');
|
||||
FX_OPTION_LONG_NAME("named-source-dir");
|
||||
FX_OPTION_DESC(
|
||||
"a source directory to build the package from. if no "
|
||||
"source directory is specified, the recipe will "
|
||||
"download the sources automatically. use this option "
|
||||
"if the recipe requires more than one separate source "
|
||||
"directory.");
|
||||
|
||||
B_OPTION_ARG(OPT_EXT_SOURCE_DIRECTORY_NAME)
|
||||
FX_OPTION_ARG(OPT_EXT_SOURCE_DIRECTORY_NAME)
|
||||
{
|
||||
B_ARG_NAME("name");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("name");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_OPTION_ARG(OPT_EXT_SOURCE_DIRECTORY_PATH)
|
||||
FX_OPTION_ARG(OPT_EXT_SOURCE_DIRECTORY_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_RECIPE)
|
||||
FX_COMMAND_ARG(ARG_RECIPE)
|
||||
{
|
||||
B_ARG_NAME("recipe");
|
||||
B_ARG_DESC("the recipe to build the package from.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("recipe");
|
||||
FX_ARG_DESC("the recipe to build the package from.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_OPT(OPT_OUTPATH);
|
||||
B_COMMAND_USAGE_ARG(ARG_RECIPE);
|
||||
FX_COMMAND_USAGE_OPT(OPT_OUTPATH);
|
||||
FX_COMMAND_USAGE_ARG(ARG_RECIPE);
|
||||
}
|
||||
}
|
||||
|
||||
+149
-145
@@ -1,12 +1,12 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <blue/compress/function.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/io/directory.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <errno.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <fx/compression/zstd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <fx/term/print.h>
|
||||
#include <ropkg/manifest.h>
|
||||
#include <ropkg/writer.h>
|
||||
#include <stdio.h>
|
||||
@@ -38,28 +38,28 @@ enum {
|
||||
|
||||
static int add_file_to_archive_ex(
|
||||
struct ropkg_writer *writer,
|
||||
b_directory *src_dir,
|
||||
const b_path *src,
|
||||
fx_directory *src_dir,
|
||||
const fx_path *src,
|
||||
const char *dest)
|
||||
{
|
||||
b_file *fp;
|
||||
b_result result = b_file_open(
|
||||
fx_file *fp;
|
||||
fx_result result = fx_file_open(
|
||||
src_dir,
|
||||
src,
|
||||
B_FILE_READ_ONLY | B_FILE_BINARY,
|
||||
FX_FILE_READ_ONLY | FX_FILE_BINARY,
|
||||
&fp);
|
||||
if (!fp) {
|
||||
b_throw_error_with_template_caused_by_error(
|
||||
fx_throw_error_with_template_caused_by_error(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DIR_OPEN_FAILED,
|
||||
result,
|
||||
B_ERROR_PARAM("filepath", b_path_ptr(src)));
|
||||
FX_ERROR_PARAM("filepath", fx_path_get_cstr(src)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_writer_file_info file = {0};
|
||||
|
||||
b_file_size(fp, &file.f_length);
|
||||
fx_file_size(fp, &file.f_length);
|
||||
|
||||
ropkg_writer_begin_file(writer, dest, &file);
|
||||
|
||||
@@ -68,8 +68,9 @@ static int add_file_to_archive_ex(
|
||||
int c;
|
||||
while (1) {
|
||||
size_t r;
|
||||
b_status status = b_file_read(fp, offset, sizeof buf, buf, &r);
|
||||
if (!B_OK(status)) {
|
||||
fx_status status
|
||||
= fx_file_read(fp, offset, sizeof buf, buf, &r);
|
||||
if (!FX_OK(status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ static int add_file_to_archive_ex(
|
||||
}
|
||||
}
|
||||
|
||||
b_file_release(fp);
|
||||
fx_file_unref(fp);
|
||||
ropkg_writer_end_file(writer);
|
||||
return 0;
|
||||
}
|
||||
@@ -93,43 +94,43 @@ static int add_file_to_archive(
|
||||
const char *src,
|
||||
const char *dest)
|
||||
{
|
||||
b_path *src_path = b_path_create_from_cstr(src);
|
||||
fx_path *src_path = fx_path_create_from_cstr(src);
|
||||
int ret = add_file_to_archive_ex(writer, NULL, src_path, dest);
|
||||
b_path_release(src_path);
|
||||
fx_path_unref(src_path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int add_data_archive(
|
||||
const b_arglist *args,
|
||||
struct b_cstream *stream,
|
||||
const fx_arglist *args,
|
||||
fx_cstream *stream,
|
||||
struct ropkg_writer *pkg)
|
||||
{
|
||||
const char *data_path_cstr;
|
||||
b_status bstatus = b_arglist_get_string(
|
||||
fx_status bstatus = fx_arglist_get_string(
|
||||
args,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_SOURCE_DIR,
|
||||
0,
|
||||
&data_path_cstr);
|
||||
if (!B_OK(bstatus)) {
|
||||
b_arglist_report_missing_args(
|
||||
if (!FX_OK(bstatus)) {
|
||||
fx_arglist_report_missing_args(
|
||||
args,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_SOURCE_DIR,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_path *data_path = b_path_create_from_cstr(data_path_cstr);
|
||||
b_directory *data_dir;
|
||||
b_result result = b_directory_open(NULL, data_path, 0, &data_dir);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw_error_with_template_caused_by_error(
|
||||
fx_path *data_path = fx_path_create_from_cstr(data_path_cstr);
|
||||
fx_directory *data_dir;
|
||||
fx_result result = fx_directory_open(NULL, data_path, 0, &data_dir);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw_error_with_template_caused_by_error(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_DIR_OPEN_FAILED,
|
||||
result,
|
||||
B_ERROR_PARAM("filepath", data_path_cstr));
|
||||
FX_ERROR_PARAM("filepath", data_path_cstr));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -137,38 +138,43 @@ static int add_data_archive(
|
||||
struct ropkg_writer_file_info file = {0};
|
||||
ropkg_writer_begin_file(pkg, ROPKG_PATH_DATA ".zst", &file);
|
||||
|
||||
b_cstream_begin_compressed_section(stream, NULL);
|
||||
fx_cstream_begin_compressed_section(stream, NULL);
|
||||
enum ropkg_status status = ropkg_writer_open(stream, &data);
|
||||
|
||||
int ret = 0;
|
||||
b_directory_iterator it;
|
||||
b_directory_foreach(&it, data_dir, B_DIRECTORY_ITERATE_PARENT_FIRST)
|
||||
fx_iterator *it = fx_directory_begin(
|
||||
data_dir,
|
||||
FX_DIRECTORY_ITERATE_PARENT_FIRST);
|
||||
fx_foreach(v, it)
|
||||
{
|
||||
if (!(it.info.attrib & B_FILE_ATTRIB_NORMAL)) {
|
||||
fx_directory_entry *entry = NULL;
|
||||
fx_value_get_pointer(v, (void **)&entry);
|
||||
if (!(entry->info.attrib & FX_FILE_ATTRIB_NORMAL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = add_file_to_archive_ex(
|
||||
data,
|
||||
data_dir,
|
||||
it.filepath,
|
||||
b_path_ptr(it.filepath));
|
||||
entry->filepath,
|
||||
fx_path_get_cstr(entry->filepath));
|
||||
|
||||
if (ret != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fx_iterator_unref(it);
|
||||
|
||||
ropkg_writer_close(data);
|
||||
b_cstream_end_compressed_section(stream, NULL, NULL);
|
||||
fx_cstream_end_compressed_section(stream, NULL, NULL);
|
||||
ropkg_writer_end_file(pkg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int add_control_archive(
|
||||
const b_arglist *args,
|
||||
b_cstream *stream,
|
||||
const fx_arglist *args,
|
||||
fx_cstream *stream,
|
||||
struct ropkg_writer *pkg)
|
||||
{
|
||||
int ret;
|
||||
@@ -177,15 +183,15 @@ static int add_control_archive(
|
||||
struct ropkg_writer_file_info file = {0};
|
||||
ropkg_writer_begin_file(pkg, ROPKG_PATH_CONTROL ".zst", &file);
|
||||
|
||||
b_cstream_begin_compressed_section(stream, NULL);
|
||||
fx_cstream_begin_compressed_section(stream, NULL);
|
||||
enum ropkg_status status = ropkg_writer_open(stream, &control);
|
||||
|
||||
b_arglist_option_iterator it;
|
||||
b_arglist_option_foreach_filtered(&it, args, OPT_SCRIPT)
|
||||
fx_arglist_option_iterator it;
|
||||
fx_arglist_option_foreach_filtered(&it, args, OPT_SCRIPT)
|
||||
{
|
||||
struct b_arglist_value *type, *path;
|
||||
b_arglist_option_get_value(it.opt, OPT_SCRIPT_NAME, 0, &type);
|
||||
b_arglist_option_get_value(it.opt, OPT_SCRIPT_PATH, 0, &path);
|
||||
struct fx_arglist_value *type, *path;
|
||||
fx_arglist_option_get_value(it.opt, OPT_SCRIPT_NAME, 0, &type);
|
||||
fx_arglist_option_get_value(it.opt, OPT_SCRIPT_PATH, 0, &path);
|
||||
|
||||
ret = add_file_to_archive(
|
||||
control,
|
||||
@@ -200,57 +206,57 @@ static int add_control_archive(
|
||||
|
||||
ropkg_writer_close(control);
|
||||
|
||||
b_cstream_end_compressed_section(stream, NULL, NULL);
|
||||
fx_cstream_end_compressed_section(stream, NULL, NULL);
|
||||
|
||||
ropkg_writer_end_file(pkg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static b_result validate_manifest(const char *path)
|
||||
static fx_result validate_manifest(const char *path)
|
||||
{
|
||||
FILE *fp = fopen(path, "r");
|
||||
if (!fp) {
|
||||
return b_error_with_template(
|
||||
return fx_error_with_template(
|
||||
ROPKG_ERROR_VENDOR,
|
||||
ROPKG_ERR_FILE_OPEN_FAILED,
|
||||
B_ERROR_PARAM("filepath", path));
|
||||
FX_ERROR_PARAM("filepath", path));
|
||||
}
|
||||
|
||||
struct ropkg_manifest *manifest;
|
||||
enum ropkg_status status = ropkg_manifest_create(&manifest);
|
||||
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_manifest_parse(fp, manifest);
|
||||
fx_result result = ropkg_manifest_parse(fp, manifest);
|
||||
|
||||
ropkg_manifest_destroy(manifest);
|
||||
fclose(fp);
|
||||
|
||||
return b_result_propagate(result);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
static int add_meta_archive(
|
||||
const b_arglist *args,
|
||||
b_cstream *stream,
|
||||
const fx_arglist *args,
|
||||
fx_cstream *stream,
|
||||
struct ropkg_writer *pkg)
|
||||
{
|
||||
const char *manifest_path, *news_path;
|
||||
b_status bstatus = b_arglist_get_string(
|
||||
fx_status bstatus = fx_arglist_get_string(
|
||||
args,
|
||||
OPT_MANIFEST,
|
||||
OPT_MANIFEST_PATH,
|
||||
0,
|
||||
&manifest_path);
|
||||
if (!B_OK(bstatus)) {
|
||||
b_arglist_report_missing_option(args, OPT_MANIFEST);
|
||||
if (!FX_OK(bstatus)) {
|
||||
fx_arglist_report_missing_option(args, OPT_MANIFEST);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_result result = validate_manifest(manifest_path);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
fx_result result = validate_manifest(manifest_path);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -260,16 +266,16 @@ static int add_meta_archive(
|
||||
struct ropkg_writer_file_info file = {0};
|
||||
ropkg_writer_begin_file(pkg, ROPKG_PATH_META ".zst", &file);
|
||||
|
||||
b_cstream_begin_compressed_section(stream, NULL);
|
||||
fx_cstream_begin_compressed_section(stream, NULL);
|
||||
enum ropkg_status status = ropkg_writer_open(stream, &meta);
|
||||
|
||||
bstatus = b_arglist_get_string(
|
||||
bstatus = fx_arglist_get_string(
|
||||
args,
|
||||
OPT_NEWS,
|
||||
OPT_NEWS_PATH,
|
||||
1,
|
||||
&news_path);
|
||||
if (B_OK(bstatus)) {
|
||||
if (FX_OK(bstatus)) {
|
||||
ret = add_file_to_archive(meta, news_path, "news");
|
||||
if (ret != 0) {
|
||||
ropkg_writer_close(meta);
|
||||
@@ -285,7 +291,7 @@ static int add_meta_archive(
|
||||
|
||||
ropkg_writer_close(meta);
|
||||
|
||||
b_cstream_end_compressed_section(stream, NULL, NULL);
|
||||
fx_cstream_end_compressed_section(stream, NULL, NULL);
|
||||
|
||||
ropkg_writer_end_file(pkg);
|
||||
|
||||
@@ -293,34 +299,32 @@ static int add_meta_archive(
|
||||
}
|
||||
|
||||
static int create(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const b_compression_function *zstd
|
||||
= b_compression_function_get_by_id(B_COMPRESSOR_FUNCTION_ZSTD);
|
||||
struct ropkg_writer *pkg, *subpkg;
|
||||
enum ropkg_status status;
|
||||
|
||||
const char *out_path;
|
||||
b_status bstatus = b_arglist_get_string(
|
||||
fx_status bstatus = fx_arglist_get_string(
|
||||
opt,
|
||||
OPT_OUTPATH,
|
||||
OPT_OUTPATH_PATH,
|
||||
0,
|
||||
&out_path);
|
||||
if (!B_OK(bstatus)) {
|
||||
b_arglist_report_missing_option(opt, OPT_OUTPATH);
|
||||
if (!FX_OK(bstatus)) {
|
||||
fx_arglist_report_missing_option(opt, OPT_OUTPATH);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(out_path, "wb");
|
||||
b_stream *fp_stream = b_stream_open_fp(fp);
|
||||
b_cstream *cstream;
|
||||
bstatus = b_cstream_open(
|
||||
fx_stream *fp_stream = fx_stream_open_fp(fp);
|
||||
fx_cstream *cstream;
|
||||
bstatus = fx_cstream_open(
|
||||
fp_stream,
|
||||
zstd,
|
||||
B_COMPRESSION_MODE_COMPRESS,
|
||||
FX_TYPE_ZSTD_COMPRESSOR,
|
||||
FX_COMPRESSOR_MODE_COMPRESS,
|
||||
&cstream);
|
||||
|
||||
status = ropkg_writer_open(cstream, &pkg);
|
||||
@@ -345,114 +349,114 @@ static int create(
|
||||
end:
|
||||
ropkg_writer_close(pkg);
|
||||
|
||||
b_cstream_close(cstream);
|
||||
b_stream_close(fp_stream);
|
||||
fx_cstream_unref(cstream);
|
||||
fx_stream_unref(fp_stream);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_CREATE, CMD_PACKAGE)
|
||||
FX_COMMAND(CMD_PACKAGE_CREATE, CMD_PACKAGE)
|
||||
{
|
||||
B_COMMAND_NAME("create");
|
||||
B_COMMAND_SHORT_NAME('C');
|
||||
B_COMMAND_DESC("create a Rosetta package from a directory");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(create);
|
||||
FX_COMMAND_NAME("create");
|
||||
FX_COMMAND_SHORT_NAME('C');
|
||||
FX_COMMAND_DESC("create a Rosetta package from a directory");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(create);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_OPTION(OPT_OUTPATH)
|
||||
FX_COMMAND_OPTION(OPT_OUTPATH)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('o');
|
||||
B_OPTION_LONG_NAME("out");
|
||||
B_OPTION_DESC("the path to save the new package file to");
|
||||
FX_OPTION_SHORT_NAME('o');
|
||||
FX_OPTION_LONG_NAME("out");
|
||||
FX_OPTION_DESC("the path to save the new package file to");
|
||||
|
||||
B_OPTION_ARG(OPT_OUTPATH_PATH)
|
||||
FX_OPTION_ARG(OPT_OUTPATH_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_MANIFEST)
|
||||
FX_COMMAND_OPTION(OPT_MANIFEST)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('m');
|
||||
B_OPTION_LONG_NAME("manifest");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('m');
|
||||
FX_OPTION_LONG_NAME("manifest");
|
||||
FX_OPTION_DESC(
|
||||
"the path to a manifest file describing the "
|
||||
"package to be created.");
|
||||
B_OPTION_ARG(OPT_MANIFEST_PATH)
|
||||
FX_OPTION_ARG(OPT_MANIFEST_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_NEWS)
|
||||
FX_COMMAND_OPTION(OPT_NEWS)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('n');
|
||||
B_OPTION_LONG_NAME("news");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('n');
|
||||
FX_OPTION_LONG_NAME("news");
|
||||
FX_OPTION_DESC(
|
||||
"the path to a news file to be included in the "
|
||||
"package.");
|
||||
B_OPTION_ARG(OPT_NEWS_PATH)
|
||||
FX_OPTION_ARG(OPT_NEWS_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
B_COMMAND_OPTION(OPT_CONTROL)
|
||||
FX_COMMAND_OPTION(OPT_CONTROL)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('c');
|
||||
B_OPTION_LONG_NAME("control");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('c');
|
||||
FX_OPTION_LONG_NAME("control");
|
||||
FX_OPTION_DESC(
|
||||
"the path to a control directory containing package "
|
||||
"scripts. this option cannot be used with "
|
||||
"-s/--script.");
|
||||
B_OPTION_ARG(OPT_CONTROL_PATH)
|
||||
FX_OPTION_ARG(OPT_CONTROL_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
B_COMMAND_OPTION(OPT_SCRIPT)
|
||||
FX_COMMAND_OPTION(OPT_SCRIPT)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('s');
|
||||
B_OPTION_LONG_NAME("script");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('s');
|
||||
FX_OPTION_LONG_NAME("script");
|
||||
FX_OPTION_DESC(
|
||||
"a control script to be run at a certain point "
|
||||
"in the "
|
||||
"package (un)installation process.");
|
||||
|
||||
B_OPTION_ARG(OPT_SCRIPT_NAME)
|
||||
FX_OPTION_ARG(OPT_SCRIPT_NAME)
|
||||
{
|
||||
B_ARG_NAME("event");
|
||||
B_ARG_NR_VALUES(1);
|
||||
B_ARG_ALLOWED_VALUES(
|
||||
FX_ARG_NAME("event");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
FX_ARG_ALLOWED_VALUES(
|
||||
"pre-install",
|
||||
"post-install",
|
||||
"pre-uninstall",
|
||||
"post-uninstall");
|
||||
}
|
||||
|
||||
B_OPTION_ARG(OPT_SCRIPT_PATH)
|
||||
FX_OPTION_ARG(OPT_SCRIPT_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_PARAMETER)
|
||||
FX_COMMAND_OPTION(OPT_PARAMETER)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('p');
|
||||
B_OPTION_LONG_NAME("parameter");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('p');
|
||||
FX_OPTION_LONG_NAME("parameter");
|
||||
FX_OPTION_DESC(
|
||||
"a parameter to use when creating the new "
|
||||
"file. "
|
||||
"if a parameter EXAMPLE is defined, any "
|
||||
@@ -463,34 +467,34 @@ B_COMMAND(CMD_PACKAGE_CREATE, CMD_PACKAGE)
|
||||
"be "
|
||||
"replaced with the specified parameter value.");
|
||||
|
||||
B_OPTION_ARG(OPT_PARAMETER_NAME)
|
||||
FX_OPTION_ARG(OPT_PARAMETER_NAME)
|
||||
{
|
||||
B_ARG_NAME("name");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("name");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_OPTION_ARG(OPT_PARAMETER_VALUE)
|
||||
FX_OPTION_ARG(OPT_PARAMETER_VALUE)
|
||||
{
|
||||
B_ARG_NAME("value");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("value");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_SOURCE_DIR)
|
||||
FX_COMMAND_ARG(ARG_SOURCE_DIR)
|
||||
{
|
||||
B_ARG_NAME("source-dir");
|
||||
B_ARG_DESC(
|
||||
FX_ARG_NAME("source-dir");
|
||||
FX_ARG_DESC(
|
||||
"the directory to package. the specified "
|
||||
"directory "
|
||||
"will become the root of the newly created "
|
||||
"package.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_OPT(OPT_OUTPATH);
|
||||
B_COMMAND_USAGE_OPT_PLACEHOLDER();
|
||||
B_COMMAND_USAGE_ARG(ARG_SOURCE_DIR);
|
||||
FX_COMMAND_USAGE_OPT(OPT_OUTPATH);
|
||||
FX_COMMAND_USAGE_OPT_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_ARG(ARG_SOURCE_DIR);
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -1,6 +1,6 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
enum {
|
||||
OPT_OUTPATH,
|
||||
@@ -10,46 +10,46 @@ enum {
|
||||
};
|
||||
|
||||
static int extract(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_EXTRACT, CMD_PACKAGE)
|
||||
FX_COMMAND(CMD_PACKAGE_EXTRACT, CMD_PACKAGE)
|
||||
{
|
||||
B_COMMAND_NAME("extract");
|
||||
B_COMMAND_SHORT_NAME('X');
|
||||
B_COMMAND_DESC("extract the contents of a Rosetta package");
|
||||
// B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(extract);
|
||||
FX_COMMAND_NAME("extract");
|
||||
FX_COMMAND_SHORT_NAME('X');
|
||||
FX_COMMAND_DESC("extract the contents of a Rosetta package");
|
||||
// FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(extract);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_OPTION(OPT_OUTPATH)
|
||||
FX_COMMAND_OPTION(OPT_OUTPATH)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('o');
|
||||
B_OPTION_LONG_NAME("out");
|
||||
B_OPTION_DESC("the path to extract the package contents to");
|
||||
FX_OPTION_SHORT_NAME('o');
|
||||
FX_OPTION_LONG_NAME("out");
|
||||
FX_OPTION_DESC("the path to extract the package contents to");
|
||||
|
||||
B_OPTION_ARG(OPT_OUTPATH_PATH)
|
||||
FX_OPTION_ARG(OPT_OUTPATH_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_PACKAGE)
|
||||
FX_COMMAND_ARG(ARG_PACKAGE)
|
||||
{
|
||||
B_ARG_NAME("package");
|
||||
B_ARG_DESC("the package to extract.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("package");
|
||||
FX_ARG_DESC("the package to extract.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_OPT(OPT_OUTPATH);
|
||||
B_COMMAND_USAGE_ARG(ARG_PACKAGE);
|
||||
FX_COMMAND_USAGE_OPT(OPT_OUTPATH);
|
||||
FX_COMMAND_USAGE_ARG(ARG_PACKAGE);
|
||||
}
|
||||
}
|
||||
|
||||
+56
-24
@@ -1,6 +1,8 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/instance.h>
|
||||
|
||||
enum {
|
||||
OPT_SYSROOT,
|
||||
@@ -10,50 +12,80 @@ enum {
|
||||
};
|
||||
|
||||
static int install(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const char *sysroot_path = NULL;
|
||||
fx_status status = fx_arglist_get_string(
|
||||
opt,
|
||||
OPT_SYSROOT,
|
||||
OPT_SYSROOT_PATH,
|
||||
0,
|
||||
&sysroot_path);
|
||||
if (!FX_OK(status)) {
|
||||
sysroot_path = "/";
|
||||
}
|
||||
|
||||
struct ropkg_instance *inst;
|
||||
fx_result result = ropkg_instance_open(sysroot_path, &inst);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* install steps:
|
||||
* - open and lock the instance
|
||||
* - read the 'installed', and 'available' package databases
|
||||
* - determine the current system state (i.e. installed packages, their
|
||||
* versions, and dependencies)
|
||||
* - find a new system state that includes the requested packages and
|
||||
* their dependencies, without breaking already existing packages.
|
||||
* - if such a state can be found, re-configure the system to match
|
||||
* this new state.
|
||||
*/
|
||||
|
||||
ropkg_instance_close(inst);
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_INSTALL, CMD_PACKAGE)
|
||||
FX_COMMAND(CMD_PACKAGE_INSTALL, CMD_PACKAGE)
|
||||
{
|
||||
B_COMMAND_NAME("install");
|
||||
B_COMMAND_SHORT_NAME('I');
|
||||
B_COMMAND_DESC("install a Rosetta package.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(install);
|
||||
FX_COMMAND_NAME("install");
|
||||
FX_COMMAND_SHORT_NAME('I');
|
||||
FX_COMMAND_DESC("install a Rosetta package.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(install);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_OPTION(OPT_SYSROOT)
|
||||
FX_COMMAND_OPTION(OPT_SYSROOT)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('s');
|
||||
B_OPTION_LONG_NAME("sysroot");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('s');
|
||||
FX_OPTION_LONG_NAME("sysroot");
|
||||
FX_OPTION_DESC(
|
||||
"the system directory to install the package to. if no "
|
||||
"sysroot is specified, the root directory is used. "
|
||||
"alternatively, the ROSETTA_SYSROOT environment "
|
||||
"variable can be used to specify the system root "
|
||||
"directory");
|
||||
|
||||
B_OPTION_ARG(OPT_SYSROOT_PATH)
|
||||
FX_OPTION_ARG(OPT_SYSROOT_PATH)
|
||||
{
|
||||
B_ARG_NAME("path");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_PACKAGE)
|
||||
FX_COMMAND_ARG(ARG_PACKAGE)
|
||||
{
|
||||
B_ARG_NAME("package-path");
|
||||
B_ARG_DESC("the path to the package to install.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("package-path");
|
||||
FX_ARG_DESC("the filepath(s) of the package(s) to install.");
|
||||
FX_ARG_NR_VALUES(FX_ARG_1_OR_MORE_VALUES);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_PACKAGE);
|
||||
FX_COMMAND_USAGE_ARG(ARG_PACKAGE);
|
||||
}
|
||||
}
|
||||
|
||||
+47
-49
@@ -1,9 +1,9 @@
|
||||
#include "../../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <blue/compress/function.h>
|
||||
#include <blue/core/bitop.h>
|
||||
#include <fx/bitop.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <fx/compression/zstd.h>
|
||||
#include <ropkg/manifest.h>
|
||||
#include <ropkg/reader.h>
|
||||
|
||||
@@ -53,39 +53,37 @@ static int print_file_list(
|
||||
}
|
||||
|
||||
static int query_list(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const b_compression_function *zstd
|
||||
= b_compression_function_get_by_id(B_COMPRESSOR_FUNCTION_ZSTD);
|
||||
struct ropkg_reader *pkg;
|
||||
enum ropkg_status status;
|
||||
|
||||
const char *in_path;
|
||||
b_status bstatus = b_arglist_get_string(
|
||||
fx_status bstatus = fx_arglist_get_string(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0,
|
||||
&in_path);
|
||||
if (!B_OK(bstatus)) {
|
||||
b_arglist_report_missing_args(
|
||||
if (!FX_OK(bstatus)) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sections = 0;
|
||||
if (b_arglist_get_count(opt, OPT_DATA, B_COMMAND_INVALID_ID) > 0) {
|
||||
if (fx_arglist_get_count(opt, OPT_DATA, FX_COMMAND_INVALID_ID) > 0) {
|
||||
sections |= OPT_DATA;
|
||||
}
|
||||
if (b_arglist_get_count(opt, OPT_META, B_COMMAND_INVALID_ID) > 0) {
|
||||
if (fx_arglist_get_count(opt, OPT_META, FX_COMMAND_INVALID_ID) > 0) {
|
||||
sections |= OPT_META;
|
||||
}
|
||||
if (b_arglist_get_count(opt, OPT_CONTROL, B_COMMAND_INVALID_ID) > 0) {
|
||||
if (fx_arglist_get_count(opt, OPT_CONTROL, FX_COMMAND_INVALID_ID) > 0) {
|
||||
sections |= OPT_CONTROL;
|
||||
}
|
||||
|
||||
@@ -93,15 +91,15 @@ static int query_list(
|
||||
sections = OPT_DATA;
|
||||
}
|
||||
|
||||
bool show_headers = b_popcountl(sections) > 1;
|
||||
bool show_headers = fx_popcountl(sections) > 1;
|
||||
|
||||
FILE *fp = fopen(in_path, "rb");
|
||||
b_stream *fp_stream = b_stream_open_fp(fp);
|
||||
b_cstream *cstream;
|
||||
bstatus = b_cstream_open(
|
||||
fx_stream *fp_stream = fx_stream_open_fp(fp);
|
||||
fx_cstream *cstream;
|
||||
bstatus = fx_cstream_open(
|
||||
fp_stream,
|
||||
zstd,
|
||||
B_COMPRESSION_MODE_DECOMPRESS,
|
||||
FX_TYPE_ZSTD_COMPRESSOR,
|
||||
FX_COMPRESSOR_MODE_DECOMPRESS,
|
||||
&cstream);
|
||||
|
||||
status = ropkg_reader_open(cstream, &pkg);
|
||||
@@ -129,11 +127,11 @@ static int query_list(
|
||||
}
|
||||
|
||||
struct ropkg_reader *subpkg = NULL;
|
||||
b_cstream_begin_compressed_section(cstream, NULL);
|
||||
fx_cstream_begin_compressed_section(cstream, NULL);
|
||||
status = ropkg_reader_open(cstream, &subpkg);
|
||||
print_file_list(section, show_headers, subpkg);
|
||||
ropkg_reader_close(subpkg);
|
||||
b_cstream_end_compressed_section(cstream, NULL, NULL);
|
||||
fx_cstream_end_compressed_section(cstream, NULL, NULL);
|
||||
|
||||
status = ropkg_reader_move_next(pkg);
|
||||
}
|
||||
@@ -141,53 +139,53 @@ static int query_list(
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_QUERY_LIST, CMD_PACKAGE_QUERY)
|
||||
FX_COMMAND(CMD_PACKAGE_QUERY_LIST, CMD_PACKAGE_QUERY)
|
||||
{
|
||||
B_COMMAND_NAME("list");
|
||||
B_COMMAND_SHORT_NAME('L');
|
||||
B_COMMAND_DESC("list the contents of a package");
|
||||
B_COMMAND_FUNCTION(query_list);
|
||||
FX_COMMAND_NAME("list");
|
||||
FX_COMMAND_SHORT_NAME('L');
|
||||
FX_COMMAND_DESC("list the contents of a package");
|
||||
FX_COMMAND_FUNCTION(query_list);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
FX_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
{
|
||||
B_ARG_NAME("package");
|
||||
B_ARG_DESC("the package to query.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("package");
|
||||
FX_ARG_DESC("the package to query.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_DATA)
|
||||
FX_COMMAND_OPTION(OPT_DATA)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('d');
|
||||
B_OPTION_LONG_NAME("data");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('d');
|
||||
FX_OPTION_LONG_NAME("data");
|
||||
FX_OPTION_DESC(
|
||||
"list all data files contained within a "
|
||||
"package. if no "
|
||||
"options are specified, this behaviour is the "
|
||||
"default.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_META)
|
||||
FX_COMMAND_OPTION(OPT_META)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('m');
|
||||
B_OPTION_LONG_NAME("meta");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('m');
|
||||
FX_OPTION_LONG_NAME("meta");
|
||||
FX_OPTION_DESC(
|
||||
"list all metadata files contained within a "
|
||||
"package.");
|
||||
}
|
||||
|
||||
B_COMMAND_OPTION(OPT_CONTROL)
|
||||
FX_COMMAND_OPTION(OPT_CONTROL)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('c');
|
||||
B_OPTION_LONG_NAME("control");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('c');
|
||||
FX_OPTION_LONG_NAME("control");
|
||||
FX_OPTION_DESC(
|
||||
"list all control files contained within a "
|
||||
"package.");
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_PACKAGE_PATH);
|
||||
FX_COMMAND_USAGE_ARG(ARG_PACKAGE_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
+116
-17
@@ -1,38 +1,137 @@
|
||||
#include "../../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <fx/compression/zstd.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <ropkg/manifest.h>
|
||||
#include <ropkg/package.h>
|
||||
#include <ropkg/reader.h>
|
||||
|
||||
enum {
|
||||
ARG_PACKAGE_PATH,
|
||||
};
|
||||
|
||||
static int query_manifest(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
#if 0
|
||||
const fx_compression_function *zstd
|
||||
= fx_compression_function_get_by_id(FX_COMPRESSOR_FUNCTION_ZSTD);
|
||||
struct ropkg_reader *pkg;
|
||||
enum ropkg_status status;
|
||||
|
||||
const char *in_path;
|
||||
fx_status bstatus = fx_arglist_get_string(
|
||||
opt,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0,
|
||||
&in_path);
|
||||
|
||||
if (!FX_OK(bstatus)) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(in_path, "rb");
|
||||
fx_stream *fp_stream = fx_stream_open_fp(fp);
|
||||
fx_cstream *cstream;
|
||||
bstatus = fx_cstream_open(
|
||||
fp_stream,
|
||||
zstd,
|
||||
FX_COMPRESSION_MODE_DECOMPRESS,
|
||||
&cstream);
|
||||
|
||||
status = ropkg_reader_open(cstream, &pkg);
|
||||
if (status != ROPKG_SUCCESS) {
|
||||
printf("cannot open package\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fx_directory *dest;
|
||||
fx_directory_open(
|
||||
NULL,
|
||||
FX_RV_PATH("data"),
|
||||
FX_DIRECTORY_OPEN_CREATE | FX_DIRECTORY_OPEN_DELETE_ON_CLOSE,
|
||||
&dest);
|
||||
|
||||
fx_result result = ropkg_extract_metadata(pkg, dest);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
}
|
||||
|
||||
fx_file *readme = NULL;
|
||||
fx_file_open(
|
||||
dest,
|
||||
FX_RV_PATH("meta/manifest"),
|
||||
FX_FILE_READ_ONLY,
|
||||
&readme);
|
||||
if (!readme) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
char buf[1024];
|
||||
while (1) {
|
||||
size_t nr_read = 0;
|
||||
fx_status bstatus = fx_file_read(
|
||||
readme,
|
||||
FX_OFFSET_CURRENT,
|
||||
sizeof buf,
|
||||
buf,
|
||||
&nr_read);
|
||||
if (!FX_OK(bstatus)) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nr_read; i++) {
|
||||
fputc(buf[i], stdout);
|
||||
}
|
||||
|
||||
if (nr_read < sizeof buf) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fputc('\n', stdout);
|
||||
|
||||
fx_file_unref(readme);
|
||||
end:
|
||||
fx_directory_unref(dest);
|
||||
ropkg_reader_close(pkg);
|
||||
fx_cstream_close(cstream);
|
||||
fx_stream_close(fp_stream);
|
||||
fclose(fp);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_QUERY_MANIFEST, CMD_PACKAGE_QUERY)
|
||||
FX_COMMAND(CMD_PACKAGE_QUERY_MANIFEST, CMD_PACKAGE_QUERY)
|
||||
{
|
||||
B_COMMAND_NAME("manifest");
|
||||
B_COMMAND_SHORT_NAME('M');
|
||||
B_COMMAND_DESC("print the manifest of a package");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(query_manifest);
|
||||
FX_COMMAND_NAME("manifest");
|
||||
FX_COMMAND_SHORT_NAME('M');
|
||||
FX_COMMAND_DESC("print the manifest of a package");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(query_manifest);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
FX_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
{
|
||||
B_ARG_NAME("package");
|
||||
B_ARG_DESC("the package to query.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("package");
|
||||
FX_ARG_DESC("the package to query.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_PACKAGE_PATH);
|
||||
FX_COMMAND_USAGE_ARG(ARG_PACKAGE_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
+110
-17
@@ -1,38 +1,131 @@
|
||||
#include "../../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <fx/compression/zstd.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <ropkg/manifest.h>
|
||||
#include <ropkg/package.h>
|
||||
#include <ropkg/reader.h>
|
||||
|
||||
enum {
|
||||
ARG_PACKAGE_PATH,
|
||||
};
|
||||
|
||||
static int query_readme(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
#if 0
|
||||
const fx_compression_function *zstd
|
||||
= fx_compression_function_get_by_id(FX_COMPRESSOR_FUNCTION_ZSTD);
|
||||
struct ropkg_reader *pkg;
|
||||
enum ropkg_status status;
|
||||
|
||||
const char *in_path;
|
||||
fx_status bstatus = fx_arglist_get_string(
|
||||
opt,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0,
|
||||
&in_path);
|
||||
|
||||
if (!FX_OK(bstatus)) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(in_path, "rb");
|
||||
fx_stream *fp_stream = fx_stream_open_fp(fp);
|
||||
fx_cstream *cstream;
|
||||
bstatus = fx_cstream_open(
|
||||
fp_stream,
|
||||
zstd,
|
||||
FX_COMPRESSION_MODE_DECOMPRESS,
|
||||
&cstream);
|
||||
|
||||
status = ropkg_reader_open(cstream, &pkg);
|
||||
if (status != ROPKG_SUCCESS) {
|
||||
printf("cannot open package\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fx_directory *dest;
|
||||
fx_directory_open(
|
||||
NULL,
|
||||
FX_RV_PATH("data"),
|
||||
FX_DIRECTORY_OPEN_CREATE | FX_DIRECTORY_OPEN_DELETE_ON_CLOSE,
|
||||
&dest);
|
||||
|
||||
fx_result result = ropkg_extract_metadata(pkg, dest);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
}
|
||||
|
||||
fx_file *readme = NULL;
|
||||
fx_file_open(dest, FX_RV_PATH("meta/readme"), FX_FILE_READ_ONLY, &readme);
|
||||
if (!readme) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
char buf[1024];
|
||||
while (1) {
|
||||
size_t nr_read = 0;
|
||||
fx_status bstatus = fx_file_read(
|
||||
readme,
|
||||
FX_OFFSET_CURRENT,
|
||||
sizeof buf,
|
||||
buf,
|
||||
&nr_read);
|
||||
if (!FX_OK(bstatus)) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nr_read; i++) {
|
||||
fputc(buf[i], stdout);
|
||||
}
|
||||
|
||||
if (nr_read < sizeof buf) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fx_file_unref(readme);
|
||||
end:
|
||||
fx_directory_unref(dest);
|
||||
ropkg_reader_close(pkg);
|
||||
fx_cstream_close(cstream);
|
||||
fx_stream_close(fp_stream);
|
||||
fclose(fp);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_QUERY_README, CMD_PACKAGE_QUERY)
|
||||
FX_COMMAND(CMD_PACKAGE_QUERY_README, CMD_PACKAGE_QUERY)
|
||||
{
|
||||
B_COMMAND_NAME("readme");
|
||||
B_COMMAND_SHORT_NAME('R');
|
||||
B_COMMAND_DESC("print the readme of a package");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(query_readme);
|
||||
FX_COMMAND_NAME("readme");
|
||||
FX_COMMAND_SHORT_NAME('R');
|
||||
FX_COMMAND_DESC("print the readme of a package");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(query_readme);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
FX_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
{
|
||||
B_ARG_NAME("package");
|
||||
B_ARG_DESC("the package to query.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("package");
|
||||
FX_ARG_DESC("the package to query.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_PACKAGE_PATH);
|
||||
FX_COMMAND_USAGE_ARG(ARG_PACKAGE_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "../../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_QUERY, CMD_PACKAGE)
|
||||
FX_COMMAND(CMD_PACKAGE_QUERY, CMD_PACKAGE)
|
||||
{
|
||||
B_COMMAND_NAME("query");
|
||||
B_COMMAND_SHORT_NAME('Q');
|
||||
B_COMMAND_DESC("query information about a Rosetta package");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_NAME("query");
|
||||
FX_COMMAND_SHORT_NAME('Q');
|
||||
FX_COMMAND_DESC("query information about a Rosetta package");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#include "../../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <blue/compress/function.h>
|
||||
#include <blue/io/directory.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/compression/cstream.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <ropkg/manifest.h>
|
||||
#include <ropkg/package.h>
|
||||
#include <ropkg/reader.h>
|
||||
@@ -13,39 +12,47 @@ enum {
|
||||
};
|
||||
|
||||
static int query_summary(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const b_compression_function *zstd
|
||||
= b_compression_function_get_by_id(B_COMPRESSOR_FUNCTION_ZSTD);
|
||||
const char *in_path;
|
||||
fx_status bstatus = fx_arglist_get_string(
|
||||
opt,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0,
|
||||
&in_path);
|
||||
#if 0
|
||||
const fx_compression_function *zstd
|
||||
= fx_compression_function_get_by_id(FX_COMPRESSOR_FUNCTION_ZSTD);
|
||||
struct ropkg_reader *pkg;
|
||||
enum ropkg_status status;
|
||||
|
||||
const char *in_path;
|
||||
b_status bstatus = b_arglist_get_string(
|
||||
fx_status bstatus = fx_arglist_get_string(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0,
|
||||
&in_path);
|
||||
|
||||
if (!B_OK(bstatus)) {
|
||||
b_arglist_report_missing_args(
|
||||
if (!FX_OK(bstatus)) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_PACKAGE_PATH,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(in_path, "rb");
|
||||
b_stream *fp_stream = b_stream_open_fp(fp);
|
||||
b_cstream *cstream;
|
||||
bstatus = b_cstream_open(
|
||||
fx_stream *fp_stream = fx_stream_open_fp(fp);
|
||||
fx_cstream *cstream;
|
||||
bstatus = fx_cstream_open(
|
||||
fp_stream,
|
||||
zstd,
|
||||
B_COMPRESSION_MODE_DECOMPRESS,
|
||||
FX_COMPRESSION_MODE_DECOMPRESS,
|
||||
&cstream);
|
||||
|
||||
status = ropkg_reader_open(cstream, &pkg);
|
||||
@@ -54,46 +61,54 @@ static int query_summary(
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_directory *dest;
|
||||
b_directory_open(
|
||||
fx_directory *dest;
|
||||
fx_directory_open(
|
||||
NULL,
|
||||
B_RV_PATH("data"),
|
||||
B_DIRECTORY_OPEN_CREATE | B_DIRECTORY_OPEN_DELETE_ON_CLOSE,
|
||||
FX_RV_PATH("data"),
|
||||
FX_DIRECTORY_OPEN_CREATE | FX_DIRECTORY_OPEN_DELETE_ON_CLOSE,
|
||||
&dest);
|
||||
|
||||
b_result result = ropkg_extract_metadata(pkg, dest);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
fx_result result = ropkg_extract_metadata(pkg, dest);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
}
|
||||
|
||||
b_directory_release(dest);
|
||||
fx_directory_unref(dest);
|
||||
ropkg_reader_close(pkg);
|
||||
b_cstream_close(cstream);
|
||||
b_stream_close(fp_stream);
|
||||
fx_cstream_close(cstream);
|
||||
fx_stream_close(fp_stream);
|
||||
fclose(fp);
|
||||
#endif
|
||||
struct ropkg_package *pkg;
|
||||
fx_result result = ropkg_package_open(NULL, in_path, &pkg);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ropkg_package_close(pkg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_PACKAGE_QUERY_SUMMARY, CMD_PACKAGE_QUERY)
|
||||
FX_COMMAND(CMD_PACKAGE_QUERY_SUMMARY, CMD_PACKAGE_QUERY)
|
||||
{
|
||||
B_COMMAND_NAME("summary");
|
||||
B_COMMAND_SHORT_NAME('S');
|
||||
B_COMMAND_DESC("print a summary of information about a package");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(query_summary);
|
||||
FX_COMMAND_NAME("summary");
|
||||
FX_COMMAND_SHORT_NAME('S');
|
||||
FX_COMMAND_DESC("print a summary of information about a package");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(query_summary);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
FX_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
{
|
||||
B_ARG_NAME("package");
|
||||
B_ARG_DESC("the package to query.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("package");
|
||||
FX_ARG_DESC("the package to query.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_PACKAGE_PATH);
|
||||
FX_COMMAND_USAGE_ARG(ARG_PACKAGE_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,19 +1,19 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/term/print.h>
|
||||
|
||||
B_COMMAND(CMD_PACKAGE, CMD_ROOT)
|
||||
FX_COMMAND(CMD_PACKAGE, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("package");
|
||||
B_COMMAND_SHORT_NAME('P');
|
||||
B_COMMAND_DESC("Package inspection and manipulation.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_NAME("package");
|
||||
FX_COMMAND_SHORT_NAME('P');
|
||||
FX_COMMAND_DESC("Package inspection and manipulation.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
|
||||
+54
-54
@@ -1,7 +1,7 @@
|
||||
#include "../commands.h"
|
||||
#include "ropkg/version.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum {
|
||||
@@ -35,91 +35,91 @@ static enum ropkg_status comparison_op_from_string(
|
||||
}
|
||||
|
||||
static int compare_version(
|
||||
const b_command *self,
|
||||
const b_arglist *opt,
|
||||
const b_array *args)
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
int ret = -1;
|
||||
bool verbose = false;
|
||||
|
||||
struct ropkg_version *left = NULL, *right = NULL;
|
||||
enum ropkg_status status = ropkg_version_create(&left);
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
status = ropkg_version_create(&right);
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
const char *left_string = NULL, *right_string = NULL, *op_string = NULL;
|
||||
b_arglist_get_string(
|
||||
fx_arglist_get_string(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_VERSION_LEFT,
|
||||
0,
|
||||
&left_string);
|
||||
b_arglist_get_string(
|
||||
fx_arglist_get_string(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_VERSION_RIGHT,
|
||||
0,
|
||||
&right_string);
|
||||
b_arglist_get_string(
|
||||
fx_arglist_get_string(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_OPERATOR,
|
||||
0,
|
||||
&op_string);
|
||||
verbose = b_arglist_get_count(opt, OPT_VERBOSE, B_COMMAND_INVALID_ID)
|
||||
verbose = fx_arglist_get_count(opt, OPT_VERBOSE, FX_COMMAND_INVALID_ID)
|
||||
> 0;
|
||||
|
||||
if (!left_string) {
|
||||
b_arglist_report_missing_args(
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_VERSION_LEFT,
|
||||
0);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!right_string) {
|
||||
b_arglist_report_missing_args(
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_VERSION_RIGHT,
|
||||
0);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!op_string) {
|
||||
b_arglist_report_missing_args(
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_OPERATOR,
|
||||
0);
|
||||
goto end;
|
||||
}
|
||||
|
||||
b_result result = ropkg_version_parse(left, left_string);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
fx_result result = ropkg_version_parse(left, left_string);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
goto end;
|
||||
}
|
||||
|
||||
result = ropkg_version_parse(right, right_string);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
goto end;
|
||||
}
|
||||
|
||||
enum ropkg_comparison_op op;
|
||||
status = comparison_op_from_string(op_string, &op);
|
||||
if (status != ROPKG_SUCCESS) {
|
||||
b_arglist_report_invalid_arg_value(
|
||||
fx_arglist_report_invalid_arg_value(
|
||||
opt,
|
||||
B_COMMAND_INVALID_ID,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_OPERATOR,
|
||||
op_string);
|
||||
goto end;
|
||||
@@ -175,37 +175,37 @@ end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_VERSION_COMPARE, CMD_VERSION)
|
||||
FX_COMMAND(CMD_VERSION_COMPARE, CMD_VERSION)
|
||||
{
|
||||
B_COMMAND_NAME("compare");
|
||||
B_COMMAND_SHORT_NAME('C');
|
||||
B_COMMAND_DESC("compare two package version identifiers.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_FUNCTION(compare_version);
|
||||
FX_COMMAND_NAME("compare");
|
||||
FX_COMMAND_SHORT_NAME('C');
|
||||
FX_COMMAND_DESC("compare two package version identifiers.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(compare_version);
|
||||
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_OPTION(OPT_VERBOSE)
|
||||
FX_COMMAND_OPTION(OPT_VERBOSE)
|
||||
{
|
||||
B_OPTION_SHORT_NAME('v');
|
||||
B_OPTION_LONG_NAME("verbose");
|
||||
B_OPTION_DESC(
|
||||
FX_OPTION_SHORT_NAME('v');
|
||||
FX_OPTION_LONG_NAME("verbose");
|
||||
FX_OPTION_DESC(
|
||||
"print the result of the comparison to "
|
||||
"standard out.");
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_VERSION_LEFT)
|
||||
FX_COMMAND_ARG(ARG_VERSION_LEFT)
|
||||
{
|
||||
B_ARG_NAME("left-version");
|
||||
B_ARG_DESC("the left-side of the comparison operation.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("left-version");
|
||||
FX_ARG_DESC("the left-side of the comparison operation.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_OPERATOR)
|
||||
FX_COMMAND_ARG(ARG_OPERATOR)
|
||||
{
|
||||
B_ARG_NAME("operator");
|
||||
B_ARG_DESC("the comparison operator to use.");
|
||||
B_ARG_ALLOWED_VALUES(
|
||||
FX_ARG_NAME("operator");
|
||||
FX_ARG_DESC("the comparison operator to use.");
|
||||
FX_ARG_ALLOWED_VALUES(
|
||||
"==",
|
||||
"!=",
|
||||
"<",
|
||||
@@ -218,20 +218,20 @@ B_COMMAND(CMD_VERSION_COMPARE, CMD_VERSION)
|
||||
"le",
|
||||
"gt",
|
||||
"ge");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_ARG(ARG_VERSION_RIGHT)
|
||||
FX_COMMAND_ARG(ARG_VERSION_RIGHT)
|
||||
{
|
||||
B_ARG_NAME("right-version");
|
||||
B_ARG_DESC("the right-side of the comparison operation.");
|
||||
B_ARG_NR_VALUES(1);
|
||||
FX_ARG_NAME("right-version");
|
||||
FX_ARG_DESC("the right-side of the comparison operation.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_ARG(ARG_VERSION_LEFT);
|
||||
B_COMMAND_USAGE_ARG(ARG_OPERATOR);
|
||||
B_COMMAND_USAGE_ARG(ARG_VERSION_RIGHT);
|
||||
FX_COMMAND_USAGE_ARG(ARG_VERSION_LEFT);
|
||||
FX_COMMAND_USAGE_ARG(ARG_OPERATOR);
|
||||
FX_COMMAND_USAGE_ARG(ARG_VERSION_RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,19 +1,19 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/term/print.h>
|
||||
|
||||
B_COMMAND(CMD_VERSION, CMD_ROOT)
|
||||
FX_COMMAND(CMD_VERSION, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("version");
|
||||
B_COMMAND_SHORT_NAME('V');
|
||||
B_COMMAND_DESC("Version identifier inspection and manipulation.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_HELP_OPTION();
|
||||
FX_COMMAND_NAME("version");
|
||||
FX_COMMAND_SHORT_NAME('V');
|
||||
FX_COMMAND_DESC("Version identifier inspection and manipulation.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
B_COMMAND_USAGE()
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
file(GLOB sources *.c *.h)
|
||||
file(GLOB_RECURSE sources *.c *.h)
|
||||
|
||||
add_executable(rovem ${sources})
|
||||
target_link_libraries(rovem Bluelib::Core Bluelib::Object Bluelib::Io Bluelib::Term Bluelib::Cmd)
|
||||
target_link_libraries(rovem
|
||||
libropkg
|
||||
FX::Runtime FX::Io FX::Term FX::Cmdline)
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/repo-mgmt.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum {
|
||||
OPT_CHANNEL,
|
||||
OPT_CHANNEL_VALUE,
|
||||
OPT_COMPONENT,
|
||||
OPT_COMPONENT_VALUE,
|
||||
OPT_DESCRIPTION,
|
||||
OPT_DESCRIPTION_VALUE,
|
||||
OPT_REPO,
|
||||
OPT_REPO_PATH,
|
||||
};
|
||||
|
||||
static int channel_add_component(
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const char *root_path = NULL;
|
||||
const char *channel_name = NULL;
|
||||
const char *component_name = NULL;
|
||||
|
||||
fx_arglist_get_string(opt, OPT_REPO, OPT_REPO_PATH, 0, &root_path);
|
||||
fx_arglist_get_string(
|
||||
opt,
|
||||
OPT_CHANNEL,
|
||||
OPT_CHANNEL_VALUE,
|
||||
0,
|
||||
&channel_name);
|
||||
fx_arglist_get_string(
|
||||
opt,
|
||||
OPT_COMPONENT,
|
||||
OPT_COMPONENT_VALUE,
|
||||
0,
|
||||
&component_name);
|
||||
|
||||
if (!root_path) {
|
||||
fx_arglist_report_missing_args(opt, OPT_REPO, OPT_REPO_PATH, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!channel_name) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
OPT_CHANNEL,
|
||||
OPT_CHANNEL_VALUE,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!component_name) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
OPT_COMPONENT,
|
||||
OPT_COMPONENT_VALUE,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt *repo = NULL;
|
||||
fx_result result = ropkg_repo_mgmt_open(root_path, &repo);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt_channel *channel = NULL;
|
||||
result = ropkg_repo_mgmt_open_channel(repo, channel_name, &channel);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt_component *component = NULL;
|
||||
result = ropkg_repo_mgmt_channel_open_component(
|
||||
channel,
|
||||
component_name,
|
||||
&component);
|
||||
if (fx_result_is(result, ROPKG_ERROR_VENDOR, ROPKG_ERR_NO_COMPONENT)) {
|
||||
fx_error_discard(result);
|
||||
} else if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
} else {
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
fprintf(stderr,
|
||||
"component %s/%s already exists\n",
|
||||
channel_name,
|
||||
component_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = ropkg_repo_mgmt_channel_create_component(
|
||||
channel,
|
||||
component_name,
|
||||
&component);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ropkg_repo_mgmt_component_close(component);
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FX_COMMAND(CMD_CHANNEL_ADD_COMPONENT, CMD_CHANNEL)
|
||||
{
|
||||
FX_COMMAND_NAME("add-component");
|
||||
FX_COMMAND_DESC("add a component to a repository channel.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(channel_add_component);
|
||||
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_OPTION(OPT_REPO)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("repo");
|
||||
FX_OPTION_SHORT_NAME('r');
|
||||
FX_OPTION_DESC(
|
||||
"the path to the root of the repository to add "
|
||||
"the "
|
||||
"package(s) to.");
|
||||
|
||||
FX_OPTION_ARG(OPT_REPO_PATH)
|
||||
{
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_DESC("the path to the repository root.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_CHANNEL)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("channel");
|
||||
FX_OPTION_SHORT_NAME('C');
|
||||
FX_OPTION_DESC(
|
||||
"the name of the channel to add the new "
|
||||
"component to.");
|
||||
|
||||
FX_OPTION_ARG(OPT_CHANNEL_VALUE)
|
||||
{
|
||||
FX_ARG_NAME("name");
|
||||
FX_ARG_DESC(
|
||||
"the name of the channel to add the "
|
||||
"new "
|
||||
"component to.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_COMPONENT)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("component");
|
||||
FX_OPTION_SHORT_NAME('c');
|
||||
FX_OPTION_DESC("the name of the new component.");
|
||||
|
||||
FX_OPTION_ARG(OPT_COMPONENT_VALUE)
|
||||
{
|
||||
FX_ARG_NAME("name");
|
||||
FX_ARG_DESC("the name of the new component.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/repo-mgmt.h>
|
||||
|
||||
enum {
|
||||
OPT_NAME,
|
||||
OPT_NAME_VALUE,
|
||||
OPT_DESCRIPTION,
|
||||
OPT_DESCRIPTION_VALUE,
|
||||
OPT_REPO,
|
||||
OPT_REPO_PATH,
|
||||
};
|
||||
|
||||
static int channel_add(
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const char *root_path = NULL;
|
||||
const char *channel_name = NULL;
|
||||
|
||||
fx_arglist_get_string(opt, OPT_REPO, OPT_REPO_PATH, 0, &root_path);
|
||||
fx_arglist_get_string(opt, OPT_NAME, OPT_NAME_VALUE, 0, &channel_name);
|
||||
|
||||
if (!root_path) {
|
||||
fx_arglist_report_missing_args(opt, OPT_REPO, OPT_REPO_PATH, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!channel_name) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
OPT_NAME,
|
||||
OPT_NAME_VALUE,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt *repo = NULL;
|
||||
fx_result result = ropkg_repo_mgmt_open(root_path, &repo);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt_channel *channel = NULL;
|
||||
result = ropkg_repo_mgmt_create_channel(repo, channel_name, &channel);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FX_COMMAND(CMD_CHANNEL_ADD, CMD_CHANNEL)
|
||||
{
|
||||
FX_COMMAND_NAME("add");
|
||||
FX_COMMAND_SHORT_NAME('A');
|
||||
FX_COMMAND_DESC("add a channel to a repository.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(channel_add);
|
||||
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_OPTION(OPT_REPO)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("repo");
|
||||
FX_OPTION_SHORT_NAME('r');
|
||||
FX_OPTION_DESC(
|
||||
"the path to the repository to create the channel in.");
|
||||
|
||||
FX_OPTION_ARG(OPT_REPO_PATH)
|
||||
{
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_DESC(
|
||||
"the path to the repository to create the "
|
||||
"channel in.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_NAME)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("name");
|
||||
FX_OPTION_SHORT_NAME('n');
|
||||
FX_OPTION_DESC("the name of the channel to create.");
|
||||
|
||||
FX_OPTION_ARG(OPT_NAME_VALUE)
|
||||
{
|
||||
FX_ARG_NAME("name");
|
||||
FX_ARG_DESC("the name of the channel to create.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_DESCRIPTION)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("description");
|
||||
FX_OPTION_SHORT_NAME('d');
|
||||
FX_OPTION_DESC(
|
||||
"a human-readable description of the new channel.");
|
||||
|
||||
FX_OPTION_ARG(OPT_DESCRIPTION_VALUE)
|
||||
{
|
||||
FX_ARG_NAME("description");
|
||||
FX_ARG_DESC(
|
||||
"a human-readable description of the new "
|
||||
"channel.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
enum {
|
||||
OPT_REPO,
|
||||
OPT_REPO_PATH,
|
||||
OPT_LOCATION,
|
||||
OPT_LOCATION_CHANNEL,
|
||||
OPT_LOCATION_COMPONENT,
|
||||
|
||||
ARG_PACKAGE_PATH,
|
||||
};
|
||||
|
||||
static int package_add(
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
FX_COMMAND(CMD_PACKAGE_ADD, CMD_PACKAGE)
|
||||
{
|
||||
FX_COMMAND_NAME("add");
|
||||
FX_COMMAND_SHORT_NAME('A');
|
||||
FX_COMMAND_DESC("add a package to a repository.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(package_add);
|
||||
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_OPTION(OPT_LOCATION)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("location");
|
||||
FX_OPTION_SHORT_NAME('L');
|
||||
FX_OPTION_DESC(
|
||||
"the channel and component to add the package to.");
|
||||
|
||||
FX_OPTION_ARG(OPT_LOCATION_CHANNEL)
|
||||
{
|
||||
FX_ARG_NAME("channel");
|
||||
FX_ARG_DESC("the channel to add the package to.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
FX_OPTION_ARG(OPT_LOCATION_COMPONENT)
|
||||
{
|
||||
FX_ARG_NAME("component");
|
||||
FX_ARG_DESC(
|
||||
"the channel component to add the package to.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_REPO)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("repo");
|
||||
FX_OPTION_SHORT_NAME('R');
|
||||
FX_OPTION_DESC(
|
||||
"the path to the root of the repository to add the "
|
||||
"package(s) to.");
|
||||
|
||||
FX_OPTION_ARG(OPT_REPO_PATH)
|
||||
{
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_DESC("the path to the repository root.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
{
|
||||
FX_ARG_NAME("package");
|
||||
FX_ARG_DESC("the path to the package(s) to add.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
enum {
|
||||
OPT_REPO,
|
||||
OPT_REPO_PATH,
|
||||
OPT_LOCATION,
|
||||
OPT_LOCATION_CHANNEL,
|
||||
OPT_LOCATION_COMPONENT,
|
||||
|
||||
ARG_PACKAGE_PATH,
|
||||
};
|
||||
|
||||
static int package_add(
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
FX_COMMAND(CMD_PACKAGE_ADD, CMD_PACKAGE)
|
||||
{
|
||||
FX_COMMAND_NAME("add");
|
||||
FX_COMMAND_SHORT_NAME('A');
|
||||
FX_COMMAND_DESC("add a package to a repository.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(package_add);
|
||||
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_OPTION(OPT_LOCATION)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("location");
|
||||
FX_OPTION_SHORT_NAME('L');
|
||||
FX_OPTION_DESC(
|
||||
"the channel and component to add the package to.");
|
||||
|
||||
FX_OPTION_ARG(OPT_LOCATION_CHANNEL)
|
||||
{
|
||||
FX_ARG_NAME("channel");
|
||||
FX_ARG_DESC("the channel to add the package to.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
FX_OPTION_ARG(OPT_LOCATION_COMPONENT)
|
||||
{
|
||||
FX_ARG_NAME("component");
|
||||
FX_ARG_DESC(
|
||||
"the channel component to add the package to.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_REPO)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("repo");
|
||||
FX_OPTION_SHORT_NAME('R');
|
||||
FX_OPTION_DESC(
|
||||
"the path to the root of the repository to add the "
|
||||
"package(s) to.");
|
||||
|
||||
FX_OPTION_ARG(OPT_REPO_PATH)
|
||||
{
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_DESC("the path to the repository root.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
{
|
||||
FX_ARG_NAME("package");
|
||||
FX_ARG_DESC("the path to the package(s) to add.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/term/print.h>
|
||||
|
||||
FX_COMMAND(CMD_CHANNEL, CMD_ROOT)
|
||||
{
|
||||
FX_COMMAND_NAME("channel");
|
||||
FX_COMMAND_SHORT_NAME('C');
|
||||
FX_COMMAND_DESC("Repository channel inspection and manipulation.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -5,8 +5,16 @@ enum {
|
||||
CMD_ROOT,
|
||||
CMD_CREATE,
|
||||
CMD_QUERY,
|
||||
CMD_ADD_PACKAGE,
|
||||
CMD_REMOVE_PACKAGE,
|
||||
|
||||
CMD_PACKAGE,
|
||||
CMD_PACKAGE_ADD,
|
||||
CMD_PACKAGE_REMOVE,
|
||||
|
||||
CMD_CHANNEL,
|
||||
CMD_CHANNEL_ADD,
|
||||
CMD_CHANNEL_REMOVE,
|
||||
CMD_CHANNEL_ADD_COMPONENT,
|
||||
CMD_CHANNEL_REMOVE_COMPONENT,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#include "commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <ropkg/repo-mgmt.h>
|
||||
|
||||
enum {
|
||||
OPT_NAME,
|
||||
OPT_NAME_VALUE,
|
||||
OPT_DESCRIPTION,
|
||||
OPT_DESCRIPTION_VALUE,
|
||||
|
||||
ARG_REPO_PATH,
|
||||
};
|
||||
|
||||
static int create(
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const char *root_path = NULL;
|
||||
fx_arglist_get_string(
|
||||
opt,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_REPO_PATH,
|
||||
0,
|
||||
&root_path);
|
||||
|
||||
if (!root_path) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
FX_COMMAND_INVALID_ID,
|
||||
ARG_REPO_PATH,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt *repo = NULL;
|
||||
fx_result result = ropkg_repo_mgmt_create(root_path, &repo);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
FX_COMMAND(CMD_CREATE, CMD_ROOT)
|
||||
{
|
||||
FX_COMMAND_NAME("create");
|
||||
FX_COMMAND_SHORT_NAME('N');
|
||||
FX_COMMAND_DESC("create a new repository.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(create);
|
||||
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_OPTION(OPT_NAME)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("name");
|
||||
FX_OPTION_SHORT_NAME('n');
|
||||
FX_OPTION_DESC("the human-readable name of the repository");
|
||||
FX_OPTION_ARG(OPT_NAME_VALUE)
|
||||
{
|
||||
FX_ARG_NAME("name");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_DESCRIPTION)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("description");
|
||||
FX_OPTION_SHORT_NAME('d');
|
||||
FX_OPTION_DESC(
|
||||
"a human-readable description of the repository");
|
||||
FX_OPTION_ARG(OPT_DESCRIPTION_VALUE)
|
||||
{
|
||||
FX_ARG_NAME("description");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_ARG(ARG_REPO_PATH)
|
||||
{
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_DESC("the path to create the repository at.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -1,19 +1,19 @@
|
||||
#include "commands.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
B_COMMAND(CMD_ROOT, B_COMMAND_INVALID_ID)
|
||||
FX_COMMAND(CMD_ROOT, FX_COMMAND_INVALID_ID)
|
||||
{
|
||||
B_COMMAND_NAME("rovem");
|
||||
B_COMMAND_DESC(
|
||||
FX_COMMAND_NAME("rovem");
|
||||
FX_COMMAND_DESC(
|
||||
"Rosetta package vendor management tool. This tool is used to "
|
||||
"create and manage a Rosetta package vendor, from which "
|
||||
"packages can be retrieved and installed by clients.");
|
||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
B_COMMAND_HELP_OPTION();
|
||||
"create and manage a Rosetta package vendor, from which "
|
||||
"packages can be retrieved and installed by clients.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
return b_command_dispatch(CMD_ROOT, argc, argv);
|
||||
return fx_command_dispatch(CMD_ROOT, argc, argv);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
|
||||
enum {
|
||||
OPT_REPO,
|
||||
OPT_REPO_PATH,
|
||||
OPT_LOCATION,
|
||||
OPT_LOCATION_CHANNEL,
|
||||
OPT_LOCATION_COMPONENT,
|
||||
|
||||
ARG_PACKAGE_PATH,
|
||||
};
|
||||
|
||||
static int package_add(
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
FX_COMMAND(CMD_PACKAGE_ADD, CMD_PACKAGE)
|
||||
{
|
||||
FX_COMMAND_NAME("add");
|
||||
FX_COMMAND_SHORT_NAME('A');
|
||||
FX_COMMAND_DESC("add a package to a repository.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(package_add);
|
||||
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_OPTION(OPT_LOCATION)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("location");
|
||||
FX_OPTION_SHORT_NAME('L');
|
||||
FX_OPTION_DESC(
|
||||
"the channel and component to add the package to.");
|
||||
|
||||
FX_OPTION_ARG(OPT_LOCATION_CHANNEL)
|
||||
{
|
||||
FX_ARG_NAME("channel");
|
||||
FX_ARG_DESC("the channel to add the package to.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
|
||||
FX_OPTION_ARG(OPT_LOCATION_COMPONENT)
|
||||
{
|
||||
FX_ARG_NAME("component");
|
||||
FX_ARG_DESC(
|
||||
"the channel component to add the package to.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_REPO)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("repo");
|
||||
FX_OPTION_SHORT_NAME('R');
|
||||
FX_OPTION_DESC(
|
||||
"the path to the root of the repository to add the "
|
||||
"package(s) to.");
|
||||
|
||||
FX_OPTION_ARG(OPT_REPO_PATH)
|
||||
{
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_DESC("the path to the repository root.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_ARG(ARG_PACKAGE_PATH)
|
||||
{
|
||||
FX_ARG_NAME("package");
|
||||
FX_ARG_DESC("the path to the package(s) to add.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/term/print.h>
|
||||
|
||||
FX_COMMAND(CMD_PACKAGE, CMD_ROOT)
|
||||
{
|
||||
FX_COMMAND_NAME("package");
|
||||
FX_COMMAND_SHORT_NAME('P');
|
||||
FX_COMMAND_DESC("Repository package inspection and manipulation.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_USAGE()
|
||||
{
|
||||
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user