Get rid of directory lock

We don't need it any more. Fixes issue #1633
This commit is contained in:
Howard Chu 2017-02-18 21:57:06 +00:00
parent 2e9136767e
commit bed2d9f231
No known key found for this signature in database
GPG Key ID: FD2A70B44AB11BA7
2 changed files with 0 additions and 58 deletions

View File

@ -219,40 +219,6 @@ namespace cryptonote
return m_blockchain_storage.get_alternative_blocks_count(); return m_blockchain_storage.get_alternative_blocks_count();
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::lock_db_directory(const boost::filesystem::path &path)
{
// boost doesn't like locking directories...
const boost::filesystem::path lock_path = path / ".daemon_lock";
try
{
// ensure the file exists
std::ofstream(lock_path.string(), std::ios::out).close();
db_lock = boost::interprocess::file_lock(lock_path.string().c_str());
LOG_PRINT_L1("Locking " << lock_path.string());
if (!db_lock.try_lock())
{
LOG_ERROR("Failed to lock " << lock_path.string());
return false;
}
return true;
}
catch (const std::exception &e)
{
LOG_ERROR("Error trying to lock " << lock_path.string() << ": " << e.what());
return false;
}
}
//-----------------------------------------------------------------------------------------------
bool core::unlock_db_directory()
{
db_lock.unlock();
db_lock = boost::interprocess::file_lock();
LOG_PRINT_L1("Blockchain directory successfully unlocked");
return true;
}
//-----------------------------------------------------------------------------------------------
bool core::init(const boost::program_options::variables_map& vm, const cryptonote::test_options *test_options) bool core::init(const boost::program_options::variables_map& vm, const cryptonote::test_options *test_options)
{ {
start_time = std::time(nullptr); start_time = std::time(nullptr);
@ -284,11 +250,6 @@ namespace cryptonote
// make sure the data directory exists, and try to lock it // make sure the data directory exists, and try to lock it
CHECK_AND_ASSERT_MES (boost::filesystem::exists(folder) || boost::filesystem::create_directories(folder), false, CHECK_AND_ASSERT_MES (boost::filesystem::exists(folder) || boost::filesystem::create_directories(folder), false,
std::string("Failed to create directory ").append(folder.string()).c_str()); std::string("Failed to create directory ").append(folder.string()).c_str());
if (!lock_db_directory (folder))
{
LOG_ERROR ("Failed to lock " << folder);
return false;
}
// check for blockchain.bin // check for blockchain.bin
try try
@ -440,7 +401,6 @@ namespace cryptonote
m_miner.stop(); m_miner.stop();
m_mempool.deinit(); m_mempool.deinit();
m_blockchain_storage.deinit(); m_blockchain_storage.deinit();
unlock_db_directory();
return true; return true;
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------

View File

@ -763,24 +763,6 @@ namespace cryptonote
*/ */
bool relay_txpool_transactions(); bool relay_txpool_transactions();
/**
* @brief locks a file in the BlockchainDB directory
*
* @param path the directory in which to place the file
*
* @return true if lock acquired successfully, otherwise false
*/
bool lock_db_directory(const boost::filesystem::path &path);
/**
* @brief unlocks the db directory
*
* @note see lock_db_directory()
*
* @return true
*/
bool unlock_db_directory();
bool m_test_drop_download = true; //!< whether or not to drop incoming blocks (for testing) bool m_test_drop_download = true; //!< whether or not to drop incoming blocks (for testing)
uint64_t m_test_drop_download_height = 0; //!< height under which to drop incoming blocks, if doing so uint64_t m_test_drop_download_height = 0; //!< height under which to drop incoming blocks, if doing so