Skip to content

Commit 2882468

Browse files
Update hook behaviour to play nicer with indexer
1 parent 44fcd81 commit 2882468

4 files changed

Lines changed: 30 additions & 28 deletions

File tree

extractor/main.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,24 @@ void index_file(char *path, char* filename, bool new) {
243243
free(fileType);
244244
}
245245

246+
// Create JSON objects
247+
cJSON* json = cJSON_CreateObject();
248+
if (!json) {
249+
fprintf(stderr, "Failed to create a JSON object");
250+
return;
251+
}
252+
253+
generateChangeRequest(json, full_path, uuid, header.name, header.author, header.icon, new);
254+
255+
256+
const int result = scanner_post_change(json);
257+
char* stringJSON = cJSON_Print(json);
258+
Log("Indexing json:\n%s\n\n", stringJSON);
259+
free(stringJSON);
260+
Log("ccat error: %d\n", result);
261+
cJSON_Delete(json);
262+
263+
// Run install hook AFTER index to prevent re-running on some failure modes
246264
if (header.useHooks) {
247265
Log("Script uses hooks!");
248266
// If the file is functional, run install hook
@@ -288,28 +306,6 @@ void index_file(char *path, char* filename, bool new) {
288306
free(sdr_path);
289307
}
290308

291-
292-
// Create JSON objects
293-
cJSON* json = cJSON_CreateObject();
294-
if (!json) {
295-
fprintf(stderr, "Failed to create a JSON object");
296-
return;
297-
}
298-
299-
generateChangeRequest(json, full_path, uuid, header.name, header.author, header.icon, new);
300-
301-
302-
const int result = scanner_post_change(json);
303-
char* stringJSON = cJSON_Print(json);
304-
Log("Indexing json:\n%s\n\n", stringJSON);
305-
free(stringJSON);
306-
Log("ccat error: %d\n", result);
307-
//printf("Json: %s\n", cJSON_Print(json));
308-
309-
if (json)
310-
{
311-
cJSON_Delete(json);
312-
}
313309
// Can you believe that cJSON deleting causes issues
314310
freeScriptHeader(&header);
315311
free(full_path);
@@ -331,6 +327,9 @@ void remove_file(const char* path, const char* filename, char* uuid) {
331327
readScriptHeader(file, &header);
332328
fclose(file);
333329

330+
Log("Removing ccat entry.");
331+
scanner_delete_ccat_entry(uuid);
332+
334333
// If the file is uses hooks, run removal hook
335334
if (header.useHooks) {
336335
Log("Script uses hooks!");
@@ -363,6 +362,11 @@ void remove_file(const char* path, const char* filename, char* uuid) {
363362
freeScriptHeader(&header);
364363
Log("Removing: %s\n", sdrPath);
365364
}
365+
else
366+
{
367+
Log("Removing ccat entry.");
368+
scanner_delete_ccat_entry(uuid);
369+
}
366370

367371
if (access(sdrPath, R_OK|W_OK) == F_OK)
368372
{
@@ -372,8 +376,6 @@ void remove_file(const char* path, const char* filename, char* uuid) {
372376

373377
free(sdrPath);
374378
free(sdrScriptPath);
375-
Log("Removing ccat entry.");
376-
scanner_delete_ccat_entry(uuid);
377379
}
378380

379381
int extractor(const struct scanner_event* event) {
@@ -406,7 +408,7 @@ int extractor(const struct scanner_event* event) {
406408
}
407409

408410
__attribute__((__visibility__("default"))) int load_extractor(ScannerEventHandler** handler, int *unk1) {
409-
Log("sh_integration extractor v4.0.0 initialised\n");
411+
Log("sh_integration extractor v4.1.0 initialised\n");
410412
*handler = extractor;
411413
*unk1 = 0;
412414
return 0;

launcher/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data)
160160
#ifndef LAUNCHER_TESTING
161161
int main(void) {
162162
openlog(SERVICE_NAME, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_USER);
163-
Log("sh_integration launcher v4.0.0");
163+
Log("sh_integration launcher v4.1.0");
164164
LIPCcode code;
165165
LIPC* lipc = LipcOpenEx(SERVICE_NAME, &code);
166166
if (code != LIPC_OK)

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project('sh_integration', 'c', version : '4.0.0', default_options: ['warning_level=everything', 'c_std=gnu23'])
1+
project('sh_integration', 'c', version : '4.1.0', default_options: ['warning_level=everything', 'c_std=gnu23'])
22

33
arch = meson.get_external_property('arch', 'armhf')
44
if arch == 'armhf'

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SH_Integration
2-
SH_Integration v4.0.0
2+
SH_Integration v4.1.0
33

44
<a href='https://ko-fi.com/H2H0R8K8K' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi3.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
55

0 commit comments

Comments
 (0)