return r;
}
-/**
- * Process the given directory.
- *
- * This will add or update media found in the given directory or its children.
- *
- * @param lms previously allocated Light Media Scanner instance.
- * @param top_path top directory to scan.
- *
- * @return On success 0 is returned.
- */
-int
-lms_process(lms_t *lms, const char *top_path)
+static int
+_lms_process_check_valid(lms_t *lms, const char *path)
{
- struct pinfo pinfo;
- int r, len;
- char path[PATH_SIZE], *bname;
-
- if (!lms) {
- r = -1;
- goto end;
- }
+ if (!lms)
+ return -1;
- if (!top_path) {
- r = -2;
- goto end;
- }
+ if (!path)
+ return -2;
if (lms->is_processing) {
fprintf(stderr, "ERROR: is already processing.\n");
- r = -3;
- goto end;
+ return -3;
}
if (!lms->parsers) {
fprintf(stderr, "ERROR: no plugins registered.\n");
- r = -4;
- goto end;
+ return -4;
}
- pinfo.lms = lms;
-
- if (lms_create_pipes(&pinfo) != 0) {
- r = -5;
- goto end;
- }
+ return 0;
+}
- if (lms_create_slave(&pinfo, _slave_work) != 0) {
- r = -6;
- goto close_pipes;
- }
+static int
+_process_trigger(struct pinfo *pinfo, const char *top_path)
+{
+ char path[PATH_SIZE], *bname;
+ lms_t *lms = pinfo->lms;
+ int len;
+ int r;
if (realpath(top_path, path) == NULL) {
perror("realpath");
- r = -7;
- goto finish_slave;
+ return -1;
}
/* search '/' backwards, split dirname and basename, note realpath usage */
bname = strdup(path + len);
if (bname == NULL) {
perror("strdup");
- r = -8;
- goto finish_slave;
+ return -2;
}
lms->is_processing = 1;
lms->stop_processing = 0;
- r = _process_dir(&pinfo, len, path, bname);
+ r = _process_dir(pinfo, len, path, bname);
lms->is_processing = 0;
lms->stop_processing = 0;
free(bname);
- finish_slave:
+ return r;
+}
+
+/**
+ * Process the given directory.
+ *
+ * This will add or update media found in the given directory or its children.
+ *
+ * @param lms previously allocated Light Media Scanner instance.
+ * @param top_path top directory to scan.
+ *
+ * @return On success 0 is returned.
+ */
+int
+lms_process(lms_t *lms, const char *top_path)
+{
+ struct pinfo pinfo;
+ int r, len;
+
+ r = _lms_process_check_valid(lms, top_path);
+ if (r < 0)
+ return r;
+
+ pinfo.lms = lms;
+
+ if (lms_create_pipes(&pinfo) != 0) {
+ r = -1;
+ goto end;
+ }
+
+ if (lms_create_slave(&pinfo, _slave_work) != 0) {
+ r = -2;
+ goto close_pipes;
+ }
+
+ r = _process_trigger(&pinfo, top_path);
+
lms_finish_slave(&pinfo, _master_send_finish);
close_pipes:
lms_close_pipes(&pinfo);