Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Support "hot-delete" of scripting files from the cache #4494

Open
3 tasks done
zach2good opened this issue Sep 13, 2023 · 1 comment
Open
3 tasks done

🔨 Support "hot-delete" of scripting files from the cache #4494

zach2good opened this issue Sep 13, 2023 · 1 comment
Assignees
Labels
enhancement New feature request help wanted Extra attention is needed

Comments

@zach2good
Copy link
Contributor

I affirm:

  • I understand that if I do not agree to the following points by completing the checkboxes my issue will be ignored.
  • I have read and understood the Contributing Guide and the Code of Conduct.
  • I have searched existing issues to see if the issue has already been opened, and I have checked the commit log to see if the issue has been resolved since my server was last updated.

Describe the feature

Inside filewatcher.cpp we only handle modifying files:

// cppcheck-suppress passedByValue
void Filewatcher::handleFileAction(efsw::WatchID watchid, std::string const& dir, std::string const& filename, efsw::Action action, std::string oldFilename)
{
    TracySetThreadName("Filewatcher Thread");
    TracyZoneScoped;
    std::filesystem::path fullPath = dir + "/" + filename;
    switch (action)
    {
        case efsw::Actions::Add:
            break;
        case efsw::Actions::Delete:
            break;
        case efsw::Actions::Modified:
            modifiedQueue.enqueue(fullPath);
            break;
        case efsw::Actions::Moved:
            break;
        default:
            break;
    }
}

luautils.cpp:

    void ReloadFilewatchList()
    {
        std::set<std::string> filenames; // For de-duping

        std::filesystem::path path;
        while (filewatcher->modifiedQueue.try_dequeue(path))
        {
            if (path.extension() == ".lua")
            {
                std::string filename = path.relative_path().generic_string();
                filenames.insert(filename);
            }
        }

        for (auto const& filename : filenames)
        {
            ShowInfo("[FileWatcher] %s", filename);
            CacheLuaObjectFromFile(filename, true);
        }
    }

We need to do something like:

modifiedQueue.enqueue({ fullPath, actionType(MODIFY/DELETE/WHATEVER) });

and then handle it on the other end (on the main thread) and wipe things from the cache if the relevant file was deleted

@zach2good zach2good added enhancement New feature request help wanted Extra attention is needed labels Sep 13, 2023
@zach2good
Copy link
Contributor Author

This will also need "debouncing" of the filewatcher event. The OS might deliver signals of a file being modified after it was deleted, so it needs to catch that sort of thing safely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant