Compare commits

..

No commits in common. "5729cbd6b421dd84b365641674673ab5dfc2dd4c" and "8fdb832c85a42dfa7c0236cf9899f8bdc8c8e636" have entirely different histories.

11 changed files with 36 additions and 39 deletions

1
.gitignore vendored
View File

@ -3,7 +3,6 @@ thumbs
*.cbp *.cbp
CMakeCache.txt CMakeCache.txt
CMakeFiles CMakeFiles
cmake-build-default-event-trace
cmake-build-debug cmake-build-debug
cmake_install.cmake cmake_install.cmake
Makefile Makefile

View File

@ -81,7 +81,7 @@ function humanDuration(sec_num) {
return `${seconds}s`; return `${seconds}s`;
} }
return "<1s"; return "<0s";
} }
export default { export default {
@ -134,7 +134,7 @@ export default {
duration: this.taskDuration(row), duration: this.taskDuration(row),
time: moment.utc(row.started).local().format("dd, MMM Do YYYY, HH:mm:ss"), time: moment.utc(row.started).local().format("dd, MMM Do YYYY, HH:mm:ss"),
logs: null, logs: null,
status: row.return_code === 0 ? "ok" : "failed", status: [0,1].includes(row.return_code) ? "ok" : "failed",
_row: row _row: row
})); }));
}); });

View File

@ -120,10 +120,6 @@ class Sist2Task:
logger.info(f"Started task {self.display_name}") logger.info(f"Started task {self.display_name}")
def set_pid(self, pid):
self.pid = pid
class Sist2ScanTask(Sist2Task): class Sist2ScanTask(Sist2Task):
@ -137,10 +133,13 @@ class Sist2ScanTask(Sist2Task):
else: else:
self.job.scan_options.output = None self.job.scan_options.output = None
return_code = sist2.scan(self.job.scan_options, logs_cb=self.log_callback, set_pid_cb=self.set_pid) def set_pid(pid):
self.pid = pid
return_code = sist2.scan(self.job.scan_options, logs_cb=self.log_callback, set_pid_cb=set_pid)
self.ended = datetime.utcnow() self.ended = datetime.utcnow()
is_ok = (return_code in (0, 1)) if "debug" in sist2.bin_path else (return_code == 0) is_ok = return_code in (0, 1)
if not is_ok: if not is_ok:
self._logger.error(json.dumps({"sist2-admin": f"Process returned non-zero exit code ({return_code})"})) self._logger.error(json.dumps({"sist2-admin": f"Process returned non-zero exit code ({return_code})"}))
@ -166,9 +165,6 @@ class Sist2ScanTask(Sist2Task):
self.job.previous_index_path = self.job.index_path self.job.previous_index_path = self.job.index_path
db["jobs"][self.job.name] = self.job db["jobs"][self.job.name] = self.job
if is_ok:
return 0
return return_code return return_code
@ -189,7 +185,7 @@ class Sist2IndexTask(Sist2Task):
logger.debug(f"Fetched search backend options for {self.job.index_options.search_backend}") logger.debug(f"Fetched search backend options for {self.job.index_options.search_backend}")
return_code = sist2.index(self.job.index_options, search_backend, logs_cb=self.log_callback, set_pid_cb=self.set_pid) return_code = sist2.index(self.job.index_options, search_backend, logs_cb=self.log_callback)
self.ended = datetime.utcnow() self.ended = datetime.utcnow()
duration = self.ended - self.started duration = self.ended - self.started
@ -253,7 +249,7 @@ class Sist2UserScriptTask(Sist2Task):
super().run(sist2, db) super().run(sist2, db)
try: try:
self.user_script.setup(self.log_callback, self.set_pid) self.user_script.setup(self.log_callback)
except Exception as e: except Exception as e:
logger.error(f"Setup for {self.user_script.name} failed: ") logger.error(f"Setup for {self.user_script.name} failed: ")
logger.exception(e) logger.exception(e)
@ -273,7 +269,7 @@ class Sist2UserScriptTask(Sist2Task):
self.log_callback({"sist2-admin": f"Starting user script with {executable=}, {index_path=}, {extra_args=}"}) self.log_callback({"sist2-admin": f"Starting user script with {executable=}, {index_path=}, {extra_args=}"})
proc = Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.user_script.script_dir()) proc = Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.user_script.script_dir())
self.set_pid(proc.pid) self.pid = proc.pid
t_stderr = Thread(target=self._consume_logs, args=(self.log_callback, proc, "stderr", False)) t_stderr = Thread(target=self._consume_logs, args=(self.log_callback, proc, "stderr", False))
t_stderr.start() t_stderr.start()
@ -320,7 +316,7 @@ class TaskQueue:
def _tasks_failed(self): def _tasks_failed(self):
done = set() done = set()
for row in self._db["task_done"].sql("WHERE return_code != 0"): for row in self._db["task_done"].sql("WHERE return_code NOT IN (0,1)"):
done.add(uuid.UUID(row["id"])) done.add(uuid.UUID(row["id"]))
return done return done

View File

@ -20,7 +20,7 @@ def set_executable(file):
os.chmod(file, os.stat(file).st_mode | stat.S_IEXEC) os.chmod(file, os.stat(file).st_mode | stat.S_IEXEC)
def _initialize_git_repository(url, path, log_cb, force_clone, set_pid_cb): def _initialize_git_repository(url, path, log_cb, force_clone):
log_cb({"sist2-admin": f"Cloning {url}"}) log_cb({"sist2-admin": f"Cloning {url}"})
if force_clone or not os.path.exists(os.path.join(path, ".git")): if force_clone or not os.path.exists(os.path.join(path, ".git")):
@ -36,18 +36,14 @@ def _initialize_git_repository(url, path, log_cb, force_clone, set_pid_cb):
log_cb({"sist2-admin": f"Executing setup script {setup_script}"}) log_cb({"sist2-admin": f"Executing setup script {setup_script}"})
set_executable(setup_script) set_executable(setup_script)
proc = subprocess.Popen([setup_script], cwd=path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) result = subprocess.run([setup_script], cwd=path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
set_pid_cb(proc.pid) for line in result.stdout.split(b"\n"):
proc.wait()
stdout = proc.stdout.read()
for line in stdout.split(b"\n"):
if line: if line:
log_cb({"stdout": line.decode()}) log_cb({"stdout": line.decode()})
log_cb({"stdout": f"Executed setup script {setup_script}, return code = {proc.returncode}"}) log_cb({"stdout": f"Executed setup script {setup_script}, return code = {result.returncode}"})
if proc.returncode != 0: if result.returncode != 0:
raise Exception("Error when running setup script!") raise Exception("Error when running setup script!")
log_cb({"sist2-admin": f"Initialized git repository in {path}"}) log_cb({"sist2-admin": f"Initialized git repository in {path}"})
@ -64,11 +60,11 @@ class UserScript(BaseModel):
def script_dir(self): def script_dir(self):
return os.path.join(SCRIPT_FOLDER, self.name) return os.path.join(SCRIPT_FOLDER, self.name)
def setup(self, log_cb, set_pid_cb): def setup(self, log_cb):
os.makedirs(self.script_dir(), exist_ok=True) os.makedirs(self.script_dir(), exist_ok=True)
if self.type == ScriptType.GIT: if self.type == ScriptType.GIT:
_initialize_git_repository(self.git_repository, self.script_dir(), log_cb, self.force_clone, set_pid_cb) _initialize_git_repository(self.git_repository, self.script_dir(), log_cb, self.force_clone)
self.force_clone = False self.force_clone = False
elif self.type == ScriptType.SIMPLE: elif self.type == ScriptType.SIMPLE:
self._setup_simple() self._setup_simple()

View File

@ -243,7 +243,7 @@ class Sist2:
self.bin_path = bin_path self.bin_path = bin_path
self._data_dir = data_directory self._data_dir = data_directory
def index(self, options: IndexOptions, search_backend: Sist2SearchBackend, logs_cb, set_pid_cb): def index(self, options: IndexOptions, search_backend: Sist2SearchBackend, logs_cb):
args = [ args = [
self.bin_path, self.bin_path,
@ -255,8 +255,6 @@ class Sist2:
logs_cb({"sist2-admin": f"Starting sist2 command with args {args}"}) logs_cb({"sist2-admin": f"Starting sist2 command with args {args}"})
proc = Popen(args, stdout=PIPE, stderr=PIPE) proc = Popen(args, stdout=PIPE, stderr=PIPE)
set_pid_cb(proc.pid)
t_stderr = Thread(target=self._consume_logs_stderr, args=(logs_cb, proc)) t_stderr = Thread(target=self._consume_logs_stderr, args=(logs_cb, proc))
t_stderr.start() t_stderr.start()

View File

@ -1,6 +1,8 @@
#include "ctx.h" #include "ctx.h"
ScanCtx_t ScanCtx = { ScanCtx_t ScanCtx = {
.stat_index_size = 0,
.stat_tn_size = 0,
.pool = NULL, .pool = NULL,
.index.path = {0,}, .index.path = {0,},
}; };

View File

@ -31,6 +31,9 @@ typedef struct {
int depth; int depth;
int calculate_checksums; int calculate_checksums;
size_t stat_tn_size;
size_t stat_index_size;
pcre *exclude; pcre *exclude;
pcre_extra *exclude_extra; pcre_extra *exclude_extra;
int fast; int fast;

View File

@ -149,7 +149,7 @@ void database_open(database_t *db) {
} }
#ifdef SIST_DEBUG #ifdef SIST_DEBUG
// CRASH_IF_NOT_SQLITE_OK(sqlite3_exec(db->db, "PRAGMA foreign_keys = ON;", NULL, NULL, NULL)); CRASH_IF_NOT_SQLITE_OK(sqlite3_exec(db->db, "PRAGMA foreign_keys = ON;", NULL, NULL, NULL));
#else #else
CRASH_IF_NOT_SQLITE_OK(sqlite3_exec(db->db, "PRAGMA ignore_check_constraints = ON;", NULL, NULL, NULL)); CRASH_IF_NOT_SQLITE_OK(sqlite3_exec(db->db, "PRAGMA ignore_check_constraints = ON;", NULL, NULL, NULL));
#endif #endif
@ -373,7 +373,7 @@ void database_open(database_t *db) {
} }
void database_close(database_t *db, int optimize) { void database_close(database_t *db, int optimize) {
LOG_DEBUGF("database.c", "Closing database %s (%p)", db->filename, db->db); LOG_DEBUGF("database.c", "Closing database %s", db->filename);
if (optimize) { if (optimize) {
LOG_DEBUG("database.c", "Optimizing database"); LOG_DEBUG("database.c", "Optimizing database");
@ -594,9 +594,8 @@ cJSON *database_document_iter(database_iterator_t *iter) {
cJSON *database_incremental_scan_begin(database_t *db) { cJSON *database_incremental_scan_begin(database_t *db) {
LOG_DEBUG("database.c", "Preparing database for incremental scan"); LOG_DEBUG("database.c", "Preparing database for incremental scan");
CRASH_IF_NOT_SQLITE_OK(sqlite3_exec(db->db, "DELETE FROM marked;", NULL, NULL, NULL)); CRASH_IF_NOT_SQLITE_OK(sqlite3_exec(db->db, "DELETE FROM marked;", NULL, NULL, NULL));
LOG_DEBUG("database.c", "Preparing database for incremental scan (create marked table)");
CRASH_IF_NOT_SQLITE_OK( CRASH_IF_NOT_SQLITE_OK(
sqlite3_exec(db->db, "INSERT INTO marked SELECT id, 0, mtime FROM document;", NULL, NULL, NULL)); sqlite3_exec(db->db, "INSERT INTO marked SELECT ROWID, 0, mtime FROM document;", NULL, NULL, NULL));
} }
cJSON *database_incremental_scan_end(database_t *db) { cJSON *database_incremental_scan_end(database_t *db) {

View File

@ -260,6 +260,9 @@ void sist2_scan(scan_args_t *args) {
tpool_wait(ScanCtx.pool); tpool_wait(ScanCtx.pool);
tpool_destroy(ScanCtx.pool); tpool_destroy(ScanCtx.pool);
LOG_DEBUGF("main.c", "Thumbnail store size: %lu", ScanCtx.stat_tn_size);
LOG_DEBUGF("main.c", "Index size: %lu", ScanCtx.stat_index_size);
database_t *db = database_create(args->output, INDEX_DATABASE); database_t *db = database_create(args->output, INDEX_DATABASE);
database_open(db); database_open(db);
@ -353,6 +356,7 @@ void sist2_sqlite_index(sqlite_index_args_t *args) {
database_fts_optimize(db); database_fts_optimize(db);
database_close(db, FALSE); database_close(db, FALSE);
database_close(search_db, FALSE);
} }
void sist2_web(web_args_t *args) { void sist2_web(web_args_t *args) {

View File

@ -55,7 +55,7 @@
static const char *const Version = VERSION; static const char *const Version = VERSION;
static const int VersionMajor = 3; static const int VersionMajor = 3;
static const int VersionMinor = 3; static const int VersionMinor = 3;
static const int VersionPatch = 1; static const int VersionPatch = 0;
#ifndef SIST_PLATFORM #ifndef SIST_PLATFORM
#define SIST_PLATFORM unknown #define SIST_PLATFORM unknown

View File

@ -110,11 +110,11 @@ static void worker_thread_loop(tpool_t *pool) {
if (LogCtx.json_logs) { if (LogCtx.json_logs) {
progress_bar_print_json(done, progress_bar_print_json(done,
count, count,
0, ScanCtx.stat_tn_size,
0, pool->shm->waiting); ScanCtx.stat_index_size, pool->shm->waiting);
} else { } else {
progress_bar_print((double) done / count, progress_bar_print((double) done / count,
0, 0); ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
} }
} }
@ -272,7 +272,7 @@ void tpool_wait(tpool_t *pool) {
} }
} }
if (pool->print_progress && !LogCtx.json_logs) { if (pool->print_progress && !LogCtx.json_logs) {
progress_bar_print(1.0, 0, 0); progress_bar_print(1.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
} }
pthread_mutex_unlock(&pool->shm->mutex); pthread_mutex_unlock(&pool->shm->mutex);