mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
check if a symlink exists more carefully
This commit is contained in:
parent
e23f624968
commit
f5cf039190
@ -383,6 +383,14 @@ bool isSymlink(const fs::path & path)
|
||||
return fs::is_symlink(path); /// STYLE_CHECK_ALLOW_STD_FS_SYMLINK
|
||||
}
|
||||
|
||||
bool isSymlinkNoThrow(const fs::path & path)
|
||||
{
|
||||
std::error_code dummy;
|
||||
if (path.filename().empty())
|
||||
return fs::is_symlink(path.parent_path(), dummy); /// STYLE_CHECK_ALLOW_STD_FS_SYMLINK
|
||||
return fs::is_symlink(path, dummy); /// STYLE_CHECK_ALLOW_STD_FS_SYMLINK
|
||||
}
|
||||
|
||||
fs::path readSymlink(const fs::path & path)
|
||||
{
|
||||
/// See the comment for isSymlink
|
||||
|
@ -95,6 +95,7 @@ void setModificationTime(const std::string & path, time_t time);
|
||||
time_t getChangeTime(const std::string & path);
|
||||
|
||||
bool isSymlink(const fs::path & path);
|
||||
bool isSymlinkNoThrow(const fs::path & path);
|
||||
fs::path readSymlink(const fs::path & path);
|
||||
|
||||
}
|
||||
|
@ -509,6 +509,9 @@ void DatabaseAtomic::tryCreateMetadataSymlink()
|
||||
{
|
||||
try
|
||||
{
|
||||
/// fs::exists could return false for broken symlink
|
||||
if (FS::isSymlinkNoThrow(metadata_symlink))
|
||||
fs::remove(metadata_symlink);
|
||||
fs::create_directory_symlink(metadata_path, path_to_metadata_symlink);
|
||||
}
|
||||
catch (...)
|
||||
|
Loading…
Reference in New Issue
Block a user