This commit is contained in:
Scott E. Graves 2025-03-25 12:58:09 -05:00
parent 9a9986afe7
commit e8a2731bba
6 changed files with 42 additions and 22 deletions

View File

@ -22,6 +22,12 @@
#ifndef REPERTORY_INCLUDE_PLATFORM_PLATFORM_HPP_ #ifndef REPERTORY_INCLUDE_PLATFORM_PLATFORM_HPP_
#define REPERTORY_INCLUDE_PLATFORM_PLATFORM_HPP_ #define REPERTORY_INCLUDE_PLATFORM_PLATFORM_HPP_
#include "types/repertory.hpp"
namespace repertory {
[[nodiscard]] auto create_lock_id(provider_type prov, std::string unique_id);
}
#if defined(_WIN32) #if defined(_WIN32)
#include "platform/win32_platform.hpp" #include "platform/win32_platform.hpp"
#include "utils/windows.hpp" #include "utils/windows.hpp"

View File

@ -26,8 +26,6 @@
#include "types/repertory.hpp" #include "types/repertory.hpp"
namespace repertory { namespace repertory {
[[nodiscard]] auto create_lock_id(provider_type prov, std::string unique_id);
class i_provider; class i_provider;
class lock_data final { class lock_data final {

View File

@ -26,8 +26,6 @@
#include "types/repertory.hpp" #include "types/repertory.hpp"
namespace repertory { namespace repertory {
[[nodiscard]] auto create_lock_id(provider_type prov, std::string unique_id);
class i_provider; class i_provider;
class lock_data final { class lock_data final {
@ -42,7 +40,6 @@ public:
auto operator=(lock_data &&) -> lock_data & = delete; auto operator=(lock_data &&) -> lock_data & = delete;
private: private:
provider_type prov_;
std::string mutex_id_; std::string mutex_id_;
HANDLE mutex_handle_{INVALID_HANDLE_VALUE}; HANDLE mutex_handle_{INVALID_HANDLE_VALUE};
DWORD mutex_state_{WAIT_FAILED}; DWORD mutex_state_{WAIT_FAILED};

View File

@ -21,7 +21,7 @@
*/ */
#if !defined(_WIN32) #if !defined(_WIN32)
#include "platform/unix_platform.hpp" #include "platform/platform.hpp"
#include "app_config.hpp" #include "app_config.hpp"
#include "events/event_system.hpp" #include "events/event_system.hpp"
@ -36,11 +36,6 @@
#include "utils/unix.hpp" #include "utils/unix.hpp"
namespace repertory { namespace repertory {
auto create_lock_id(provider_type prov, std::string unique_id) {
return fmt::format("{}_{}_{}", REPERTORY_DATA_NAME,
app_config::get_provider_name(prov), unique_id);
}
lock_data::lock_data(const provider_type &prov, std::string unique_id) lock_data::lock_data(const provider_type &prov, std::string unique_id)
: mutex_id_(create_lock_id(prov, unique_id)) { : mutex_id_(create_lock_id(prov, unique_id)) {
lock_fd_ = open(get_lock_file().c_str(), O_CREAT | O_RDWR, S_IWUSR | S_IRUSR); lock_fd_ = open(get_lock_file().c_str(), O_CREAT | O_RDWR, S_IWUSR | S_IRUSR);

View File

@ -21,9 +21,8 @@
*/ */
#if defined(_WIN32) #if defined(_WIN32)
#include "platform/win32_platform.hpp" #include "platform/platform.hpp"
#include "app_config.hpp"
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/types/filesystem_item_added.hpp" #include "events/types/filesystem_item_added.hpp"
#include "providers/i_provider.hpp" #include "providers/i_provider.hpp"
@ -32,19 +31,13 @@
#include "utils/string.hpp" #include "utils/string.hpp"
namespace repertory { namespace repertory {
auto create_lock_id(provider_type prov, std::string unique_id) {
return fmt::format("{}_{}_{}", REPERTORY_DATA_NAME,
app_config::get_provider_name(prov), unique_id);
}
lock_data::~lock_data() { release(); }
lock_data::lock_data(provider_type prov, std::string unique_id) lock_data::lock_data(provider_type prov, std::string unique_id)
: prov_(prov), : mutex_id_(create_lock_id(prov, unique_id)),
mutex_id_(create_lock_id(prov, unique_id)),
mutex_handle_(::CreateMutex(nullptr, FALSE, mutex_handle_(::CreateMutex(nullptr, FALSE,
create_lock_id(prov, unique_id).c_str())) {} create_lock_id(prov, unique_id).c_str())) {}
lock_data::~lock_data() { release(); }
auto lock_data::get_current_mount_state(json &mount_state) -> bool { auto lock_data::get_current_mount_state(json &mount_state) -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();

View File

@ -0,0 +1,31 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "platform/platform.hpp"
#include "app_config.hpp"
namespace repertory {
auto create_lock_id(provider_type prov, std::string unique_id) {
return fmt::format("{}_{}_{}", REPERTORY_DATA_NAME,
app_config::get_provider_name(prov), unique_id);
}
} // namespace repertory