2016-01-02 14:28:59 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2015-2016 Mnemosyne LLC
|
|
|
|
*
|
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
#include <string.h> /* strcmp() */
|
2016-01-02 14:28:59 +00:00
|
|
|
|
|
|
|
#include <event2/event.h>
|
|
|
|
#include <event2/util.h>
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#define LIBTRANSMISSION_WATCHDIR_MODULE
|
2016-01-02 14:28:59 +00:00
|
|
|
|
|
|
|
#include "transmission.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "error-types.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "ptrarray.h"
|
2017-06-08 07:24:12 +00:00
|
|
|
#include "tr-assert.h"
|
2016-01-02 14:28:59 +00:00
|
|
|
#include "utils.h"
|
|
|
|
#include "watchdir.h"
|
|
|
|
#include "watchdir-common.h"
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define log_debug(...) \
|
|
|
|
(!tr_logLevelIsActive(TR_LOG_DEBUG) ? (void)0 : tr_logAddMessage(__FILE__, __LINE__, TR_LOG_DEBUG, "watchdir", __VA_ARGS__))
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define log_error(...) \
|
|
|
|
(!tr_logLevelIsActive(TR_LOG_ERROR) ? (void)0 : tr_logAddMessage(__FILE__, __LINE__, TR_LOG_ERROR, "watchdir", __VA_ARGS__))
|
2016-01-02 14:28:59 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
struct tr_watchdir
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* path;
|
|
|
|
tr_watchdir_cb callback;
|
|
|
|
void* callback_user_data;
|
|
|
|
struct event_base* event_base;
|
|
|
|
tr_watchdir_backend* backend;
|
|
|
|
tr_ptrArray active_retries;
|
2016-01-02 14:28:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static bool is_regular_file(char const* dir, char const* name)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
char* const path = tr_buildPath(dir, name, nullptr);
|
2021-09-12 17:41:49 +00:00
|
|
|
auto path_info = tr_sys_path_info{};
|
2021-09-15 00:18:09 +00:00
|
|
|
tr_error* error = nullptr;
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2020-08-27 23:41:26 +00:00
|
|
|
bool const ret = tr_sys_path_get_info(path, 0, &path_info, &error) && (path_info.type == TR_SYS_PATH_IS_FILE);
|
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (error != nullptr)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!TR_ERROR_IS_ENOENT(error->code))
|
|
|
|
{
|
|
|
|
log_error("Failed to get type of \"%s\" (%d): %s", path, error->code, error->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_error_free(error);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_free(path);
|
|
|
|
return ret;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
static constexpr char const* watchdir_status_to_string(tr_watchdir_status status)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (status)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_WATCHDIR_ACCEPT:
|
2016-01-02 14:28:59 +00:00
|
|
|
return "accept";
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case TR_WATCHDIR_IGNORE:
|
2016-01-02 14:28:59 +00:00
|
|
|
return "ignore";
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case TR_WATCHDIR_RETRY:
|
2016-01-02 14:28:59 +00:00
|
|
|
return "retry";
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
default:
|
2016-01-02 14:28:59 +00:00
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static tr_watchdir_status tr_watchdir_process_impl(tr_watchdir_t handle, char const* name)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* File may be gone while we're retrying */
|
|
|
|
if (!is_regular_file(tr_watchdir_get_path(handle), name))
|
|
|
|
{
|
|
|
|
return TR_WATCHDIR_IGNORE;
|
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-05-01 15:47:49 +00:00
|
|
|
tr_watchdir_status const ret = (*handle->callback)(handle, name, handle->callback_user_data);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-06-08 07:24:12 +00:00
|
|
|
TR_ASSERT(ret == TR_WATCHDIR_ACCEPT || ret == TR_WATCHDIR_IGNORE || ret == TR_WATCHDIR_RETRY);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
log_debug("Callback decided to %s file \"%s\"", watchdir_status_to_string(ret), name);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return ret;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_watchdir_retry
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_t handle;
|
|
|
|
char* name;
|
2021-09-12 17:41:49 +00:00
|
|
|
size_t counter;
|
2017-04-19 12:04:45 +00:00
|
|
|
struct event* timer;
|
|
|
|
struct timeval interval;
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2016-01-02 14:28:59 +00:00
|
|
|
|
|
|
|
/* Non-static and mutable for unit tests */
|
2021-09-12 17:41:49 +00:00
|
|
|
auto tr_watchdir_retry_limit = size_t{ 3 };
|
|
|
|
auto tr_watchdir_retry_start_interval = timeval{ 1, 0 };
|
|
|
|
auto tr_watchdir_retry_max_interval = timeval{ 10, 0 };
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
#define tr_watchdir_retries_init(r) (void)0
|
2021-08-15 09:41:48 +00:00
|
|
|
#define tr_watchdir_retries_destroy(r) tr_ptrArrayDestruct((r), (PtrArrayForeachFunc)&tr_watchdir_retry_free)
|
2017-04-19 12:04:45 +00:00
|
|
|
#define tr_watchdir_retries_insert(r, v) tr_ptrArrayInsertSorted((r), (v), &compare_retry_names)
|
|
|
|
#define tr_watchdir_retries_remove(r, v) tr_ptrArrayRemoveSortedPointer((r), (v), &compare_retry_names)
|
|
|
|
#define tr_watchdir_retries_find(r, v) tr_ptrArrayFindSorted((r), (v), &compare_retry_names)
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static int compare_retry_names(void const* a, void const* b)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2020-11-05 22:46:21 +00:00
|
|
|
return strcmp(((tr_watchdir_retry const*)a)->name, ((tr_watchdir_retry const*)b)->name);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void tr_watchdir_retry_free(tr_watchdir_retry* retry);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-10-10 16:52:26 +00:00
|
|
|
static void tr_watchdir_on_retry_timer([[maybe_unused]] evutil_socket_t fd, [[maybe_unused]] short type, void* context)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(context != nullptr);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-09-12 17:41:49 +00:00
|
|
|
auto* const retry = static_cast<tr_watchdir_retry*>(context);
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_watchdir_t const handle = retry->handle;
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_watchdir_process_impl(handle, retry->name) == TR_WATCHDIR_RETRY)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (++retry->counter < tr_watchdir_retry_limit)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
evutil_timeradd(&retry->interval, &retry->interval, &retry->interval);
|
|
|
|
|
|
|
|
if (evutil_timercmp(&retry->interval, &tr_watchdir_retry_max_interval, >))
|
|
|
|
{
|
|
|
|
retry->interval = tr_watchdir_retry_max_interval;
|
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
evtimer_del(retry->timer);
|
|
|
|
evtimer_add(retry->timer, &retry->interval);
|
|
|
|
return;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
log_error("Failed to add (corrupted?) torrent file: %s", retry->name);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_retries_remove(&handle->active_retries, retry);
|
|
|
|
tr_watchdir_retry_free(retry);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static tr_watchdir_retry* tr_watchdir_retry_new(tr_watchdir_t handle, char const* name)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_retry* retry;
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
retry = tr_new0(tr_watchdir_retry, 1);
|
|
|
|
retry->handle = handle;
|
|
|
|
retry->name = tr_strdup(name);
|
|
|
|
retry->timer = evtimer_new(handle->event_base, &tr_watchdir_on_retry_timer, retry);
|
|
|
|
retry->interval = tr_watchdir_retry_start_interval;
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
evtimer_add(retry->timer, &retry->interval);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return retry;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void tr_watchdir_retry_free(tr_watchdir_retry* retry)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
if (retry == nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (retry->timer != nullptr)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
evtimer_del(retry->timer);
|
|
|
|
event_free(retry->timer);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_free(retry->name);
|
|
|
|
tr_free(retry);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void tr_watchdir_retry_restart(tr_watchdir_retry* retry)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(retry != nullptr);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
evtimer_del(retry->timer);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
retry->counter = 0;
|
|
|
|
retry->interval = tr_watchdir_retry_start_interval;
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
evtimer_add(retry->timer, &retry->interval);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_watchdir_t tr_watchdir_new(
|
|
|
|
char const* path,
|
|
|
|
tr_watchdir_cb callback,
|
|
|
|
void* callback_user_data,
|
|
|
|
struct event_base* event_base,
|
|
|
|
bool force_generic)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_t handle;
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
handle = tr_new0(struct tr_watchdir, 1);
|
|
|
|
handle->path = tr_strdup(path);
|
|
|
|
handle->callback = callback;
|
|
|
|
handle->callback_user_data = callback_user_data;
|
|
|
|
handle->event_base = event_base;
|
|
|
|
tr_watchdir_retries_init(&handle->active_retries);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (!force_generic && (handle->backend == nullptr))
|
2016-01-25 21:48:58 +00:00
|
|
|
{
|
2020-11-01 21:47:57 +00:00
|
|
|
#if defined(WITH_INOTIFY)
|
|
|
|
handle->backend = tr_watchdir_inotify_new(handle);
|
|
|
|
#elif defined(WITH_KQUEUE)
|
|
|
|
handle->backend = tr_watchdir_kqueue_new(handle);
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
handle->backend = tr_watchdir_win32_new(handle);
|
2016-01-02 14:28:59 +00:00
|
|
|
#endif
|
2016-01-25 21:48:58 +00:00
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (handle->backend == nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
handle->backend = tr_watchdir_generic_new(handle);
|
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (handle->backend == nullptr)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_free(handle);
|
2021-09-15 00:18:09 +00:00
|
|
|
handle = nullptr;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(handle->backend->free_func != nullptr);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return handle;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_watchdir_free(tr_watchdir_t handle)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
if (handle == nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_retries_destroy(&handle->active_retries);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (handle->backend != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
handle->backend->free_func(handle->backend);
|
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_free(handle->path);
|
|
|
|
tr_free(handle);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* tr_watchdir_get_path(tr_watchdir_t handle)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(handle != nullptr);
|
2017-06-13 02:24:09 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return handle->path;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_backend* tr_watchdir_get_backend(tr_watchdir_t handle)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(handle != nullptr);
|
2017-06-13 02:24:09 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return handle->backend;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct event_base* tr_watchdir_get_event_base(tr_watchdir_t handle)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(handle != nullptr);
|
2017-06-13 02:24:09 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return handle->event_base;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_watchdir_process(tr_watchdir_t handle, char const* name)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(handle != nullptr);
|
2017-06-13 02:24:09 +00:00
|
|
|
|
2021-09-12 17:41:49 +00:00
|
|
|
auto const search_key = tr_watchdir_retry{ {}, const_cast<char*>(name), {}, {}, {} };
|
|
|
|
auto* existing_retry = static_cast<tr_watchdir_retry*>(tr_watchdir_retries_find(&handle->active_retries, &search_key));
|
|
|
|
if (existing_retry != nullptr)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_retry_restart(existing_retry);
|
|
|
|
return;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_watchdir_process_impl(handle, name) == TR_WATCHDIR_RETRY)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_watchdir_retry* retry = tr_watchdir_retry_new(handle, name);
|
|
|
|
tr_watchdir_retries_insert(&handle->active_retries, retry);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 17:25:52 +00:00
|
|
|
void tr_watchdir_scan(tr_watchdir_t handle, std::unordered_set<std::string>* dir_entries)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_sys_dir_t dir;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* name;
|
2021-09-29 17:25:52 +00:00
|
|
|
auto new_dir_entries = std::unordered_set<std::string>{};
|
2021-09-15 00:18:09 +00:00
|
|
|
tr_error* error = nullptr;
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if ((dir = tr_sys_dir_open(handle->path, &error)) == TR_BAD_SYS_DIR)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
log_error("Failed to open directory \"%s\" (%d): %s", handle->path, error->code, error->message);
|
|
|
|
tr_error_free(error);
|
|
|
|
return;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
while ((name = tr_sys_dir_read_name(dir, &error)) != nullptr)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (dir_entries != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-09-29 17:25:52 +00:00
|
|
|
auto const namestr = std::string(name);
|
|
|
|
new_dir_entries.insert(namestr);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-09-29 17:25:52 +00:00
|
|
|
if (dir_entries->count(namestr) != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_watchdir_process(handle, name);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (error != nullptr)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
log_error("Failed to read directory \"%s\" (%d): %s", handle->path, error->code, error->message);
|
|
|
|
tr_error_free(error);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
tr_sys_dir_close(dir, nullptr);
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (dir_entries != nullptr)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
*dir_entries = new_dir_entries;
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
}
|