src/woof/woof.cc
// A method to signal the woof class to check for changes.
A method to signal the woof class to check for changes.
A method to signal the woof class to check for changes .
bool woof::check_files()
    {
        if (std::filesystem::is_regular_file(path))
        {
            int64_t last_write_time = std::filesystem::last_write_time(path).time_since_epoch().count();
            if (last_write_time != file_map[path])
            {
                file_map[path] = last_write_time;
                return true;
            }
            return false;
        }
        else
        {
            bool changed = false;
            for (std::pair<const std::string, int64_t> &file_entry : file_map)
            {
                std::string file = file_entry.first;
                int64_t last_write_time = file_entry.second;
                int64_t new_write_time = std::filesystem::last_write_time(file).time_since_epoch().count();
                if (!std::filesystem::exists(file))
                {
                    file_map.erase(file);
                    changed = true;
                }
                else if (last_write_time != new_write_time)
                {
                    file_map[file] = new_write_time;
                    changed = true;
                }
            }
            if (changed)
            {
                return true;
            }
            for (auto &path_entry : std::filesystem::recursive_directory_iterator(path))
            {
                if (path_entry.is_regular_file() && file_map.find(path_entry.path().string()) == file_map.end())
                {
                    file_map[path_entry.path().string()] = std::filesystem::last_write_time(path_entry.path().string()).time_since_epoch().count();
                    return true;
                }
            }
            return false;
        }
    }
bool woof :: check_files ( ) { if ( std :: filesystem :: is_regular_file ( path ) ) { int64_t last_write_time = std :: filesystem :: last_write_time ( path ) . time_since_epoch ( ) . count ( ) ; if ( last_write_time != file_map [ path ] ) { file_map [ path ] = last_write_time ; return true ; } return false ; } else { bool changed = false ; for ( std :: pair < const std :: string , int64_t > & file_entry : file_map ) { std :: string file = file_entry . first ; int64_t last_write_time = file_entry . second ; int64_t new_write_time = std :: filesystem :: last_write_time ( file ) . time_since_epoch ( ) . count ( ) ; if ( ! std :: filesystem :: exists ( file ) ) { file_map . erase ( file ) ; changed = true ; } else if ( last_write_time != new_write_time ) { file_map [ file ] = new_write_time ; changed = true ; } } if ( changed ) { return true ; } for ( auto & path_entry : std :: filesystem :: recursive_directory_iterator ( path ) ) { if ( path_entry . is_regular_file ( ) && file_map . find ( path_entry . path ( ) . string ( ) ) == file_map . end ( ) ) { file_map [ path_entry . path ( ) . string ( ) ] = std :: filesystem :: last_write_time ( path_entry . path ( ) . string ( ) ) . time_since_epoch ( ) . count ( ) ; return true ; } } return false ; } }
A method to signal the woof class to check for changes.
A method to signal the woof class to check for changes .
// We use a variable to store the result of the check // so that we can continue updating the file map after // finding a change. // For each file in the map, perform the following checks. // If the file doesn't exist, it was deleted. // If the file's last write time has changed, it was modified. // If no files in the map have changed, check whether any new files have been added. // Since this can be an expensive operation, we only do it if we know that no files in the map have changed.