![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include "system/mem_alloc.h"#include "common/paths.h"#include "common/folder_survey.h"#include "control/settings.h"#include <glib/gstdio.h>#include "common/image_extensions.h"#include "common/datetime.h"#include "common/file_location.h"#include "common/conf.h"#include "control/control.h"#include "control/jobs.h"#include "control/jobs/import_jobs.h"#include <gio/gio.h>#include "common/utility.h"#include "common/logging.h"
Include dependency graph for folder_survey.c:Go to the source code of this file.
Data Structures | |
| struct | dt_folder_survey_entry_t |
| struct | dt_folder_survey_observation_t |
| struct | dt_folder_survey_job_t |
| struct | dt_folder_survey_t |
Macros | |
| #define | DT_FOLDER_SURVEY_STATE_FILE "folder-survey-state.ini" |
Typedefs | |
| typedef enum dt_folder_survey_file_state_t | dt_folder_survey_file_state_t |
| typedef struct dt_folder_survey_entry_t | dt_folder_survey_entry_t |
| typedef struct dt_folder_survey_observation_t | dt_folder_survey_observation_t |
| typedef struct dt_folder_survey_job_t | dt_folder_survey_job_t |
| typedef struct dt_folder_survey_t | dt_folder_survey_t |
Enumerations | |
| enum | dt_folder_survey_file_state_t { DT_FOLDER_SURVEY_FILE_PENDING = 0 , DT_FOLDER_SURVEY_FILE_QUEUED , DT_FOLDER_SURVEY_FILE_DONE } |
Functions | |
| static int | _folder_survey_save_locked () |
| Persist the complete survey baseline while the survey lock is held. | |
| static int | _folder_survey_load_locked () |
| Load the previous file list and convert interrupted imports to retries. | |
| static int | _folder_survey_collect (const char *folder, GHashTable *observed) |
| Recursively collect supported images and their stability metadata. | |
| static GList * | _folder_survey_styles_for_import () |
| Read the ordered auto-apply style list from conf. | |
| static void | _folder_survey_imported (const char *source, const gboolean success, gpointer user_data) |
| Update one persisted entry when its asynchronous import completes. | |
| static int32_t | _folder_survey_job_run (dt_job_t *job) |
| Compare the current directory contents with the prior survey loop. | |
| static void | _folder_survey_job_cleanup (void *data) |
| Release one scan job and allow the next periodic scan to start. | |
| static gboolean | _folder_survey_scan (gpointer user_data) |
| Queue one background scan without overlapping the previous scan. | |
| static gboolean | _folder_survey_scan_once (gpointer user_data) |
| Run the immediate post-configuration scan only once. | |
| static void | _folder_survey_reschedule () |
| Recreate the periodic source after a frequency or state change. | |
| static void | _folder_survey_deactivate () |
| Stop periodic scans without discarding the persisted comparison state. | |
| char * | dt_folder_survey_destination_preview () |
| Build the expanded destination path of a sample file from the current configuration, for GUI preview purposes. | |
| gboolean | dt_folder_survey_can_start (const char **message) |
| Check, without any side effect, whether the persisted configuration has everything dt_folder_survey_start() requires to succeed. | |
| void | dt_folder_survey_init () |
| Initialize the folder survey state from the persisted configuration. | |
| void | dt_folder_survey_set_confirm_import_handler (dt_folder_survey_confirm_import_handler_t handler) |
| static void | _folder_survey_offer_pending_import () |
| int | dt_folder_survey_start () |
| Validate the persisted configuration and start monitoring. | |
| void | dt_folder_survey_halt () |
| User-requested stop: end monitoring and clear the persisted session marker so the next application start does not propose to resume. | |
| gboolean | dt_folder_survey_is_active () |
| TRUE while the periodic folder scan is running. | |
| gboolean | dt_folder_survey_session_was_active () |
| TRUE when the previous application session quit while monitoring. | |
| int | dt_folder_survey_count_new_files () |
| Count files in the surveyed folder that are unknown to the persisted baseline, i.e. files that appeared while the application was closed. | |
| void | dt_folder_survey_absorb_new_files () |
| Record every file currently in the surveyed folder as already handled, so restarting the survey will not import them. | |
| gboolean | dt_folder_survey_take_session_marker () |
| Consume the "a session was monitoring when we last closed" marker. | |
| void | dt_folder_survey_forget_session () |
| Persist the cleared session marker, so resume is not proposed again. | |
| void | dt_folder_survey_cleanup () |
| Release folder survey state after control workers have stopped. | |
| void | dt_folder_survey_stop () |
| Stop new scans before control workers begin shutting down. | |
Variables | |
| static dt_folder_survey_t | _folder_survey = { 0 } |
| static dt_folder_survey_confirm_import_handler_t | _confirm_import_handler = NULL |
| #define DT_FOLDER_SURVEY_STATE_FILE "folder-survey-state.ini" |
Definition at line 34 of file folder_survey.c.
| typedef struct dt_folder_survey_entry_t dt_folder_survey_entry_t |
| typedef struct dt_folder_survey_job_t dt_folder_survey_job_t |
| typedef struct dt_folder_survey_observation_t dt_folder_survey_observation_t |
| typedef struct dt_folder_survey_t dt_folder_survey_t |
| Enumerator | |
|---|---|
| DT_FOLDER_SURVEY_FILE_PENDING | |
| DT_FOLDER_SURVEY_FILE_QUEUED | |
| DT_FOLDER_SURVEY_FILE_DONE | |
Definition at line 36 of file folder_survey.c.
|
static |
Recursively collect supported images and their stability metadata.
The loop looks only for regular image files. Directories are traversed in place so a selected ingest root behaves like selecting a folder in Import.
Definition at line 198 of file folder_survey.c.
References dt_free, dt_supported_image(), error(), folder, IS_NULL_PTR, dt_folder_survey_observation_t::mtime, dt_folder_survey_observation_t::size, and type.
Referenced by _folder_survey_job_run(), dt_folder_survey_absorb_new_files(), and dt_folder_survey_count_new_files().
|
static |
Stop periodic scans without discarding the persisted comparison state.
Imports already queued are allowed to finish. Starting again in the same session resumes comparison from the last saved file list.
Definition at line 582 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), dt_folder_survey_t::active, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::immediate_scan, dt_folder_survey_t::lock, and dt_folder_survey_t::timer.
Referenced by dt_folder_survey_halt().
|
static |
Update one persisted entry when its asynchronous import completes.
Definition at line 306 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), DT_FOLDER_SURVEY_FILE_DONE, DT_FOLDER_SURVEY_FILE_PENDING, dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::files, dt_folder_survey_t::generation, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_entry_t::stable_scans, and dt_folder_survey_entry_t::state.
Referenced by _folder_survey_job_run().
Release one scan job and allow the next periodic scan to start.
Definition at line 478 of file folder_survey.c.
References _folder_survey, dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, and dt_folder_survey_t::scan_running.
Referenced by _folder_survey_scan().
|
static |
Compare the current directory contents with the prior survey loop.
New files are first recorded as pending. An unchanged size and modification time on the following loop proves that the producer has stopped writing before the import job receives the file.
Definition at line 334 of file folder_survey.c.
References _folder_survey, _folder_survey_collect(), _folder_survey_imported(), _folder_survey_save_locked(), _folder_survey_styles_for_import(), dt_folder_survey_t::active, dt_folder_survey_t::baseline_initialized, dt_conf_get_bool(), dt_conf_get_int(), dt_conf_get_string(), dt_control_import(), dt_control_job_get_params(), dt_control_log(), DT_FOLDER_SURVEY_FILE_DONE, DT_FOLDER_SURVEY_FILE_PENDING, DT_FOLDER_SURVEY_FILE_QUEUED, dt_free, dt_free_gpointer(), DT_IMPORT_ONCONFLICT_SKIP, DT_IMPORT_ONCONFLICT_UNIQUE, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_string_to_datetime(), dt_folder_survey_t::files, dt_folder_survey_t::generation, dt_control_import_t::imgs, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_entry_t::mtime, dt_folder_survey_observation_t::mtime, dt_folder_survey_t::shutting_down, dt_folder_survey_entry_t::size, dt_folder_survey_observation_t::size, dt_folder_survey_entry_t::stable_scans, dt_folder_survey_entry_t::state, and TRUE.
Referenced by _folder_survey_scan().
|
static |
Load the previous file list and convert interrupted imports to retries.
Definition at line 137 of file folder_survey.c.
References _folder_survey, dt_folder_survey_t::baseline_initialized, DT_FOLDER_SURVEY_FILE_DONE, DT_FOLDER_SURVEY_FILE_PENDING, DT_FOLDER_SURVEY_FILE_QUEUED, dt_free, error(), dt_folder_survey_t::files, dt_folder_survey_t::folder, groups(), IS_NULL_PTR, k, dt_folder_survey_entry_t::mtime, dt_folder_survey_entry_t::size, dt_folder_survey_entry_t::stable_scans, dt_folder_survey_entry_t::state, state, dt_folder_survey_t::state_path, and dt_folder_survey_t::was_active_last_session.
Referenced by dt_folder_survey_init().
|
static |
Definition at line 821 of file folder_survey.c.
References _confirm_import_handler, _folder_survey, _folder_survey_save_locked(), dt_folder_survey_t::baseline_initialized, DT_DEBUG_CONTROL, dt_folder_survey_absorb_new_files(), dt_folder_survey_count_new_files(), dt_print(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, dt_folder_survey_t::lock, and TRUE.
Referenced by dt_folder_survey_start().
|
static |
Recreate the periodic source after a frequency or state change.
Definition at line 554 of file folder_survey.c.
References _folder_survey, _folder_survey_scan(), _folder_survey_scan_once(), dt_folder_survey_t::active, dt_conf_get_int(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::immediate_scan, dt_folder_survey_t::lock, dt_folder_survey_t::shutting_down, and dt_folder_survey_t::timer.
Referenced by dt_folder_survey_start().
|
static |
Persist the complete survey baseline while the survey lock is held.
The state file is replaced as one transaction so a crash cannot leave a partially-written list that would cause old files to be treated as new.
Definition at line 89 of file folder_survey.c.
References _folder_survey, dt_folder_survey_t::active, dt_folder_survey_t::baseline_initialized, dt_free, error(), FALSE, dt_folder_survey_t::files, dt_folder_survey_t::folder, key, dt_folder_survey_entry_t::mtime, dt_folder_survey_entry_t::size, dt_folder_survey_entry_t::stable_scans, dt_folder_survey_entry_t::state, state, dt_folder_survey_t::state_path, and value.
Referenced by _folder_survey_deactivate(), _folder_survey_imported(), _folder_survey_job_run(), _folder_survey_offer_pending_import(), dt_folder_survey_absorb_new_files(), dt_folder_survey_cleanup(), dt_folder_survey_forget_session(), dt_folder_survey_init(), dt_folder_survey_start(), and dt_folder_survey_stop().
|
static |
Queue one background scan without overlapping the previous scan.
Definition at line 493 of file folder_survey.c.
References _folder_survey, _folder_survey_job_cleanup(), _folder_survey_job_run(), dt_folder_survey_t::active, dt_conf_get_string(), dt_control_add_job(), dt_control_get_global(), dt_control_job_create(), dt_control_job_set_params(), dt_free, DT_JOB_QUEUE_SYSTEM_BG, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, folder, dt_folder_survey_t::generation, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_t::scan_running, dt_folder_survey_t::shutting_down, and TRUE.
Referenced by _folder_survey_reschedule(), and _folder_survey_scan_once().
|
static |
Run the immediate post-configuration scan only once.
Definition at line 544 of file folder_survey.c.
References _folder_survey, _folder_survey_scan(), and dt_folder_survey_t::immediate_scan.
Referenced by _folder_survey_reschedule().
|
static |
Read the ordered auto-apply style list from conf.
Styles are a Studio Capture feature, the survey runs in the background regardless of the active view, so styles are applied even if the user has switched away from Studio Capture while a session keeps monitoring.
Definition at line 281 of file folder_survey.c.
References dt_conf_get_string(), DT_FOLDER_SURVEY_STYLES_CONF_KEY, DT_FOLDER_SURVEY_STYLES_SEPARATOR, dt_free, dt_view_manager_get_current_view(), dt_view_manager_get_global(), IS_NULL_PTR, name, names, and view.
Referenced by _folder_survey_job_run().
| void dt_folder_survey_absorb_new_files | ( | ) |
Record every file currently in the surveyed folder as already handled, so restarting the survey will not import them.
Definition at line 983 of file folder_survey.c.
References _folder_survey, _folder_survey_collect(), _folder_survey_save_locked(), dt_folder_survey_t::baseline_initialized, dt_conf_get_string(), DT_FOLDER_SURVEY_FILE_DONE, dt_free, dt_free_gpointer(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::files, folder, dt_folder_survey_t::initialized, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_entry_t::mtime, dt_folder_survey_observation_t::mtime, dt_folder_survey_entry_t::size, dt_folder_survey_observation_t::size, dt_folder_survey_entry_t::state, TRUE, and value.
Referenced by _folder_survey_offer_pending_import().
| gboolean dt_folder_survey_can_start | ( | const char ** | message | ) |
Check, without any side effect, whether the persisted configuration has everything dt_folder_survey_start() requires to succeed.
| message | receives a translated, static explanation when the configuration is incomplete or invalid; left untouched otherwise. Safe to display directly in the GUI (e.g. as a status label or tooltip). |
Definition at line 694 of file folder_survey.c.
References dt_conf_get_bool(), dt_conf_get_string_const(), dt_datetime_entry_to_exif(), DT_DATETIME_LENGTH, dt_folder_survey_destination_preview(), dt_free, dt_util_test_writable_dir(), FALSE, folder, IS_NULL_PTR, preview, and TRUE.
Referenced by _studio_import_update_state(), and dt_folder_survey_start().
| void dt_folder_survey_cleanup | ( | ) |
Release folder survey state after control workers have stopped.
Definition at line 1041 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), dt_folder_survey_stop(), dt_free, dt_pthread_mutex_destroy(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::files, dt_folder_survey_t::folder, dt_folder_survey_t::generation, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, and dt_folder_survey_t::state_path.
Referenced by dt_cleanup().
| int dt_folder_survey_count_new_files | ( | ) |
Count files in the surveyed folder that are unknown to the persisted baseline, i.e. files that appeared while the application was closed.
Definition at line 941 of file folder_survey.c.
References _folder_survey, _folder_survey_collect(), dt_folder_survey_t::baseline_initialized, dt_conf_get_string(), DT_FOLDER_SURVEY_FILE_DONE, dt_free, dt_free_gpointer(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::files, folder, dt_folder_survey_t::initialized, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_entry_t::state, and value.
Referenced by _folder_survey_offer_pending_import().
| char * dt_folder_survey_destination_preview | ( | ) |
Build the expanded destination path of a sample file from the current configuration, for GUI preview purposes.
Definition at line 601 of file folder_survey.c.
References dt_alloc_align(), dt_build_filename_from_pattern(), dt_conf_get_bool(), dt_conf_get_string(), dt_control_import_data_free(), dt_datetime_entry_to_exif(), DT_DATETIME_LENGTH, dt_free, dt_free_align, dt_image_init(), dt_string_to_datetime(), dt_util_test_writable_dir(), folder, dt_control_import_t::imgs, IS_NULL_PTR, and TRUE.
Referenced by _studio_import_update_preview(), and dt_folder_survey_can_start().
| void dt_folder_survey_forget_session | ( | ) |
Persist the cleared session marker, so resume is not proposed again.
Definition at line 1034 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), and dt_folder_survey_t::lock.
Referenced by dt_folder_survey_propose_resume().
| void dt_folder_survey_halt | ( | ) |
User-requested stop: end monitoring and clear the persisted session marker so the next application start does not propose to resume.
Definition at line 910 of file folder_survey.c.
References _folder_survey, _folder_survey_deactivate(), dt_folder_survey_t::active, dt_control_log(), dt_control_signal_get_global(), DT_DEBUG_CONTROL_SIGNAL_RAISE, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), DT_SIGNAL_FOLDER_SURVEY_CHANGED, dt_folder_survey_t::initialized, and dt_folder_survey_t::lock.
Referenced by _studio_import_toggle_callback().
| void dt_folder_survey_init | ( | ) |
Initialize the folder survey state from the persisted configuration.
Monitoring is NOT started: it must be requested with dt_folder_survey_start() or through dt_folder_survey_propose_resume().
Definition at line 770 of file folder_survey.c.
References _folder_survey, _folder_survey_load_locked(), _folder_survey_save_locked(), dt_folder_survey_t::baseline_initialized, dt_conf_get_string(), dt_conf_set_string(), DT_FOLDER_SURVEY_STATE_FILE, dt_free, dt_free_gpointer(), dt_loc_get_user_config_dir(), DT_PATH_MAX, dt_pthread_mutex_init(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::files, dt_folder_survey_t::folder, dt_folder_survey_t::initialized, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_t::state_path, and TRUE.
Referenced by dt_folder_survey_start(), and dt_init().
| gboolean dt_folder_survey_is_active | ( | ) |
TRUE while the periodic folder scan is running.
Definition at line 926 of file folder_survey.c.
References _folder_survey, dt_folder_survey_t::active, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::initialized, and dt_folder_survey_t::lock.
Referenced by _studio_import_update_state().
| gboolean dt_folder_survey_session_was_active | ( | ) |
TRUE when the previous application session quit while monitoring.
Definition at line 936 of file folder_survey.c.
References _folder_survey, dt_folder_survey_t::initialized, and dt_folder_survey_t::was_active_last_session.
Referenced by dt_folder_survey_take_session_marker(), and dt_init().
| void dt_folder_survey_set_confirm_import_handler | ( | dt_folder_survey_confirm_import_handler_t | handler | ) |
Install the handler that asks about pending imports. NULL removes it.
Definition at line 816 of file folder_survey.c.
References _confirm_import_handler.
Referenced by dt_folder_survey_gui_register_handlers().
| int dt_folder_survey_start | ( | ) |
Validate the persisted configuration and start monitoring.
All settings are read from the folder_survey conf keys. Validation failures are reported through dt_control_log().
Definition at line 856 of file folder_survey.c.
References _folder_survey, _folder_survey_offer_pending_import(), _folder_survey_reschedule(), _folder_survey_save_locked(), dt_folder_survey_t::active, dt_folder_survey_t::baseline_initialized, dt_conf_get_bool(), dt_conf_get_string(), dt_conf_set_string(), dt_control_log(), dt_control_signal_get_global(), DT_DEBUG_CONTROL_SIGNAL_RAISE, dt_folder_survey_can_start(), dt_folder_survey_init(), dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), DT_SIGNAL_FOLDER_SURVEY_CHANGED, FALSE, dt_folder_survey_t::files, dt_folder_survey_t::folder, dt_folder_survey_t::generation, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, and TRUE.
Referenced by _studio_import_toggle_callback(), and dt_folder_survey_propose_resume().
| void dt_folder_survey_stop | ( | ) |
Stop new scans before control workers begin shutting down.
The persisted session marker keeps its current state so an active session can be proposed for resume on the next start.
Definition at line 1060 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::immediate_scan, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, dt_folder_survey_t::shutting_down, dt_folder_survey_t::timer, and TRUE.
Referenced by dt_cleanup(), and dt_folder_survey_cleanup().
| gboolean dt_folder_survey_take_session_marker | ( | ) |
Consume the "a session was monitoring when we last closed" marker.
Returns TRUE when the previous run quit while monitoring, and clears the in-memory marker either way, so the resume question is asked at most once per start. Persist the cleared marker with dt_folder_survey_forget_session() if the user declines; accepting leads to dt_folder_survey_start(), which persists it itself.
Definition at line 1025 of file folder_survey.c.
References _folder_survey, dt_folder_survey_session_was_active(), FALSE, TRUE, and dt_folder_survey_t::was_active_last_session.
Referenced by dt_folder_survey_propose_resume().
|
static |
Definition at line 814 of file folder_survey.c.
Referenced by _folder_survey_offer_pending_import(), and dt_folder_survey_set_confirm_import_handler().
|
static |
Definition at line 81 of file folder_survey.c.
Referenced by _folder_survey_deactivate(), _folder_survey_imported(), _folder_survey_job_cleanup(), _folder_survey_job_run(), _folder_survey_load_locked(), _folder_survey_offer_pending_import(), _folder_survey_reschedule(), _folder_survey_save_locked(), _folder_survey_scan(), _folder_survey_scan_once(), dt_folder_survey_absorb_new_files(), dt_folder_survey_cleanup(), dt_folder_survey_count_new_files(), dt_folder_survey_forget_session(), dt_folder_survey_halt(), dt_folder_survey_init(), dt_folder_survey_is_active(), dt_folder_survey_session_was_active(), dt_folder_survey_start(), dt_folder_survey_stop(), and dt_folder_survey_take_session_marker().