MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / tryCreateSymlink

Method tryCreateSymlink

src/Databases/DatabaseAtomic.cpp:626–667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

624}
625
626void DatabaseAtomic::tryCreateSymlink(const StoragePtr & table, bool if_data_path_exist)
627{
628 auto db_disk = getDisk();
629
630 if (!db_disk->isSymlinkSupported())
631 return;
632
633 if (table->getDataPaths().empty())
634 return;
635
636 const auto table_data_path = fs::path(table->getDataPaths().front()).lexically_normal();
637
638 try
639 {
640 String table_name = table->getStorageID().getTableName();
641
642 if (!table->storesDataOnDisk())
643 throw Exception(ErrorCodes::LOGICAL_ERROR, "Table {} doesn't have data path to create symlink", table_name);
644
645 String link = path_to_table_symlinks / escapeForFileName(table_name);
646
647 LOG_DEBUG(
648 log,
649 "Trying to create a symlink for table {}, data_path {}, link {}",
650 table->getStorageID().getNameForLogs(),
651 table_data_path,
652 link);
653
654 /// If it already points where needed.
655 if (db_disk->equivalentNoThrow(table_data_path, link))
656 return;
657
658 if (if_data_path_exist && !db_disk->existsFileOrDirectory(data_path))
659 return;
660
661 db_disk->createDirectorySymlink(table_data_path, link);
662 }
663 catch (...)
664 {
665 LOG_WARNING(log, getCurrentExceptionMessageAndPattern(/* with_stacktrace */ true));
666 }
667}
668
669void DatabaseAtomic::tryRemoveSymlink(const String & table_name)
670{

Callers 1

DatabaseAtomic.cppFile · 0.80

Calls 14

escapeForFileNameFunction · 0.85
ExceptionClass · 0.50
isSymlinkSupportedMethod · 0.45
emptyMethod · 0.45
getDataPathsMethod · 0.45
frontMethod · 0.45
getTableNameMethod · 0.45
getStorageIDMethod · 0.45
storesDataOnDiskMethod · 0.45
getNameForLogsMethod · 0.45
equivalentNoThrowMethod · 0.45

Tested by

no test coverage detected