MCPcopy Create free account
hub / github.com/crownengine/crown / file_monitor_callback_single

Method file_monitor_callback_single

src/resource/data_compiler.cpp:1548–1634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1546}
1547
1548void DataCompiler::file_monitor_callback_single(FileMonitorEvent::Enum fme, bool is_dir, const char *path, const char *path_renamed)
1549{
1550 TempAllocator512 ta;
1551 DynamicString source_dir(ta);
1552 DynamicString resource_path(ta); // Same as resource_name but with OS-dependent directory separators
1553 DynamicString resource_name(ta);
1554
1555 // Find source directory by matching mapped
1556 // directory prefix with `path`.
1557 auto cur = hash_map::begin(_source_dirs);
1558 auto end = hash_map::end(_source_dirs);
1559 for (; cur != end; ++cur) {
1560 HASH_MAP_SKIP_HOLE(_source_dirs, cur);
1561
1562 path::join(source_dir, cur->second.c_str(), cur->first.c_str());
1563 if (str_has_prefix(path, source_dir.c_str()))
1564 break;
1565 }
1566
1567 if (cur != end) {
1568 // All events received must refer to directories
1569 // mapped with map_source_dir().
1570 const char *filename = &path[source_dir.length() + 1];
1571 path::join(resource_path, cur->first.c_str(), filename);
1572 resource_path_to_resource_name(resource_name, resource_path);
1573
1574 logd(DATA_COMPILER, "file_monitor_callback_single:");
1575 logd(DATA_COMPILER, " source_dir : %s", source_dir.c_str());
1576 logd(DATA_COMPILER, " filename : %s", filename);
1577 logd(DATA_COMPILER, " resource_path: %s", resource_path.c_str());
1578 logd(DATA_COMPILER, " resource_name: %s", resource_name.c_str());
1579
1580 if (strcmp(filename, CROWN_DATAFENCE) == 0 && fme == FileMonitorEvent::CREATED) {
1581 _datafence_mutex.lock();
1582 _datafence_created = true;
1583 _datafence_condition.signal();
1584 _datafence_mutex.unlock();
1585 return;
1586 }
1587
1588 switch (fme) {
1589 case FileMonitorEvent::CREATED:
1590 if (!is_dir)
1591 add_file(resource_name.c_str());
1592 else
1593 add_tree(resource_name.c_str());
1594 break;
1595
1596 case FileMonitorEvent::DELETED:
1597 remove_file_or_tree(resource_name.c_str());
1598 break;
1599
1600 case FileMonitorEvent::RENAMED: {
1601 DynamicString resource_path_renamed(ta); // See resource_path
1602 DynamicString resource_name_renamed(ta);
1603 path::join(resource_path_renamed, cur->first.c_str(), &path_renamed[source_dir.length() + 1]);
1604 resource_path_to_resource_name(resource_name_renamed, resource_path_renamed);
1605

Callers

nothing calls this directly

Calls 14

strcmpFunction · 0.85
setClass · 0.85
notify_change_fileFunction · 0.85
signalMethod · 0.80
set_prefixMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
joinFunction · 0.50
c_strMethod · 0.45
lengthMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected