diff --git a/meson.build b/meson.build index a41bd3414023901a1ddadb6df2ee3cca52e391a8..ce0eda12d0b4f60978f3d3937063b9819df126e3 100644 --- a/meson.build +++ b/meson.build @@ -143,6 +143,5 @@ if dep_sdl.found() and dep_mpv.found() endif # Install -install_data('scripts/init.sql', install_dir: 'share/lektor') install_man('doc/lektord.1') meson.add_install_script('scripts/install.sh') diff --git a/scripts/init.sql b/scripts/init.sql index c7ae6a94c92a20c854a14fb823a52a60583f7523..9646d53ce0d21006a1649e5df133e0b5ec41857b 100644 --- a/scripts/init.sql +++ b/scripts/init.sql @@ -141,5 +141,3 @@ CREATE VIEW IF NOT EXISTS queue_ AS priority, queue.position AS old_position FROM queue; - -.exit diff --git a/src/database/open.c b/src/database/open.c index 35c2d6129c659bbef82950bbdd4f1a22753ac691..fcfbe69ce11a66dfeee240417cbcb883b9f5c9bb 100644 --- a/src/database/open.c +++ b/src/database/open.c @@ -186,6 +186,7 @@ database_init(const char *dbpath) GOTO_IF(SQLITE_OK != sqlite3_open(dbpath, &db), "Failed to open the database", error); SQLITE_EXEC(db, (const char *) ___scripts_init_sql, error); LOG_INFO_SCT("DB", "Initialized the 'disk' database successfully, path was '%s'", dbpath); + return true; error: LOG_ERROR_SCT("DB", "Failed to init the 'disk' database, path was '%s'", dbpath); return false; diff --git a/src/main/lktadm.c b/src/main/lktadm.c index f7b8e7b167afd0d449a264bcd1ea739da063ef52..352d21ed5ecb5a572a712216dec9d5b13264bc3f 100644 --- a/src/main/lktadm.c +++ b/src/main/lktadm.c @@ -63,29 +63,6 @@ open_db(void) fail("Not found database->init_script"); } -noreturn void -help(void) -{ - static const char *help__ = - "USAGE lktadm <COMMAND> [ARGS [...]]:\n" - "\n" - "COMMANDS:\n" - " init the init sub command\n" - " get <id> get the metadata of a kara from kurisu\n" - " download <id> <path> download\n" - " cat <path> display the metadata of a mkv file\n" - " conf prints the default config file to stdout\n" - "\n" - "INIT COMMANDS:\n" - " database write the default empty database\n" - " popualte populate the database from the filesystem\n" - " metadata write metadata to mkv files on the disk using theirs path\n" - " file <path> init the metadata for a single file by its path\n" - "\n"; - write(1, help__, strlen(help__)); - exit(EXIT_SUCCESS); -} - noreturn void conf__(struct lkt_cmd_args *args) { @@ -219,36 +196,8 @@ noreturn void init_database__(struct lkt_cmd_args *args) { UNUSED(args); - pid_t pid; - int wstatus, status, fd; open_db(); - char *sqlite_args[] = { sqlite3_bin, db_path, NULL }; - - if ((pid = fork()) == 0) { - if ((fd = open(init_script, O_RDONLY)) < 0) - fail("Can't open %s in O_RDONLY", init_script); - - if (dup2(fd, 0) < 0) - fail("Failed to duplicate %s to stdin", init_script); - - execvp(sqlite_args[0], sqlite_args); - fail("Failed to execute %s: %s", sqlite3_bin, strerror(errno)); - } - - else if (pid < 0) - fail("Failed to fork: %s", strerror(errno)); - - else { - do - if (waitpid(pid, &wstatus, WUNTRACED | WCONTINUED) == -1) - fail("Failed to wait children: %s\n", strerror(errno)); - while (!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus)); - - if ((status = WEXITSTATUS(wstatus))) - fail("Children failed with status %d\n", status); - } - - exit(EXIT_SUCCESS); + exit(!database_init(db_path)); } noreturn void @@ -290,7 +239,7 @@ static struct lkt_cmd_opt options_init[] = { noreturn void init__(struct lkt_cmd_args *args) { - lkt_cmd_parse(options_init, args->argc, args->argv, help); + lkt_cmd_parse(options_init, args->argc, args->argv, NULL); } static struct lkt_cmd_opt options[] = {