help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
ruby-calculator
/
node_modules
/
@hotwired
/
turbo
/
dist
/
types
/
elements
RSK World
ruby-calculator
Ruby Calculator Pro - Interactive Calculator with 8 Types + Mathematical Functions + Rails MVC + Modern Web Interface + API Integration + Educational Design
elements
  • frame_element.d.ts1.8 KB
  • index.d.ts108 B
  • stream_element.d.ts990 B
  • stream_source_element.d.ts238 B
legacy.ccWasmBackend.cc
node_modules/@parcel/watcher/src/unix/legacy.cc
Raw Download
Find: Go to:
#include <string>

// weird error on linux
#ifdef __THROW
#undef __THROW
#endif
#define __THROW

#ifdef _LIBC
# include <include/sys/stat.h>
#else
# include <sys/stat.h>
#endif
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>

#include "../DirTree.hh"
#include "../shared/BruteForceBackend.hh"

#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)
#if __APPLE__
#define st_mtim st_mtimespec
#endif
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))

void iterateDir(WatcherRef watcher, const std::shared_ptr <DirTree> tree, const char *relative, int parent_fd, const std::string &dirname) {
    int open_flags = (O_RDONLY | O_CLOEXEC | O_DIRECTORY | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW);
    int new_fd = openat(parent_fd, relative, open_flags);
    if (new_fd == -1) {
        if (errno == EACCES) {
            return; // ignore insufficient permissions
        }

        throw WatcherError(strerror(errno), watcher);
    }

    struct stat rootAttributes;
    fstatat(new_fd, ".", &rootAttributes, AT_SYMLINK_NOFOLLOW);
    tree->add(dirname, CONVERT_TIME(rootAttributes.st_mtim), true);

    if (DIR *dir = fdopendir(new_fd)) {
        while (struct dirent *ent = (errno = 0, readdir(dir))) {
            if (ISDOT(ent->d_name)) continue;

            std::string fullPath = dirname + "/" + ent->d_name;

            if (!watcher->isIgnored(fullPath)) {
                struct stat attrib;
                fstatat(new_fd, ent->d_name, &attrib, AT_SYMLINK_NOFOLLOW);
                bool isDir = ent->d_type == DT_DIR;

                if (isDir) {
                    iterateDir(watcher, tree, ent->d_name, new_fd, fullPath);
                } else {
                    tree->add(fullPath, CONVERT_TIME(attrib.st_mtim), isDir);
                }
            }
        }

        closedir(dir);
    } else {
        close(new_fd);
    }

    if (errno) {
        throw WatcherError(strerror(errno), watcher);
    }
}

void BruteForceBackend::readTree(WatcherRef watcher, std::shared_ptr <DirTree> tree) {
    int fd = open(watcher->mDir.c_str(), O_RDONLY);
    if (fd) {
        iterateDir(watcher, tree, ".", fd, watcher->mDir);
        close(fd);
    }
}
78 lines•2.2 KB
cpp
node_modules/@parcel/watcher/src/wasm/WasmBackend.cc
Raw Download
Find: Go to:
#include <sys/stat.h>
#include "WasmBackend.hh"

#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)

void WasmBackend::start() {
  notifyStarted();
}

void WasmBackend::subscribe(WatcherRef watcher) {
  // Build a full directory tree recursively, and watch each directory.
  std::shared_ptr<DirTree> tree = getTree(watcher);

  for (auto it = tree->entries.begin(); it != tree->entries.end(); it++) {
    if (it->second.isDir) {
      watchDir(watcher, it->second.path, tree);
    }
  }
}

void WasmBackend::watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree) {
  int wd = wasm_backend_add_watch(path.c_str(), (void *)this);
  std::shared_ptr<WasmSubscription> sub = std::make_shared<WasmSubscription>();
  sub->tree = tree;
  sub->path = path;
  sub->watcher = watcher;
  mSubscriptions.emplace(wd, sub);
}

extern "C" void wasm_backend_event_handler(void *backend, int wd, int type, char *filename) {
  WasmBackend *b = (WasmBackend *)(backend);
  b->handleEvent(wd, type, filename);
}

void WasmBackend::handleEvent(int wd, int type, char *filename) {
  // Find the subscriptions for this watch descriptor
  auto range = mSubscriptions.equal_range(wd);
  std::unordered_set<std::shared_ptr<WasmSubscription>> set;
  for (auto it = range.first; it != range.second; it++) {
    set.insert(it->second);
  }

  for (auto it = set.begin(); it != set.end(); it++) {
    if (handleSubscription(type, filename, *it)) {
      (*it)->watcher->notify();
    }
  }
}

bool WasmBackend::handleSubscription(int type, char *filename, std::shared_ptr<WasmSubscription> sub) {
  // Build full path and check if its in our ignore list.
  WatcherRef watcher = sub->watcher;
  std::string path = std::string(sub->path);

  if (filename[0] != '\0') {
    path += "/" + std::string(filename);
  }

  if (watcher->isIgnored(path)) {
    return false;
  }

  if (type == 1) {
    struct stat st;
    stat(path.c_str(), &st);
    sub->tree->update(path, CONVERT_TIME(st.st_mtim));
    watcher->mEvents.update(path);
  } else if (type == 2) {
    // Determine if this is a create or delete depending on if the file exists or not.
    struct stat st;
    if (lstat(path.c_str(), &st)) {
      // If the entry being deleted/moved is a directory, remove it from the list of subscriptions
      DirEntry *entry = sub->tree->find(path);
      if (!entry) {
        return false;
      }

      if (entry->isDir) {
        std::string pathStart = path + DIR_SEP;
        for (auto it = mSubscriptions.begin(); it != mSubscriptions.end();) {
          if (it->second->path == path || it->second->path.rfind(pathStart, 0) == 0) {
            wasm_backend_remove_watch(it->first);
            it = mSubscriptions.erase(it);
          } else {
            ++it;
          }
        }

        // Remove all sub-entries
        for (auto it = sub->tree->entries.begin(); it != sub->tree->entries.end();) {
          if (it->first.rfind(pathStart, 0) == 0) {
            watcher->mEvents.remove(it->first);
            it = sub->tree->entries.erase(it);
          } else {
            it++;
          }
        }
      }

      watcher->mEvents.remove(path);
      sub->tree->remove(path);
    } else if (sub->tree->find(path)) {
      sub->tree->update(path, CONVERT_TIME(st.st_mtim));
      watcher->mEvents.update(path);
    } else {
      watcher->mEvents.create(path);

      // If this is a create, check if it's a directory and start watching if it is.
      DirEntry *entry = sub->tree->add(path, CONVERT_TIME(st.st_mtim), S_ISDIR(st.st_mode));
      if (entry->isDir) {
        watchDir(watcher, path, sub->tree);
      }
    }
  }

  return true;
}

void WasmBackend::unsubscribe(WatcherRef watcher) {
  // Find any subscriptions pointing to this watcher, and remove them.
  for (auto it = mSubscriptions.begin(); it != mSubscriptions.end();) {
    if (it->second->watcher.get() == watcher.get()) {
      if (mSubscriptions.count(it->first) == 1) {
        wasm_backend_remove_watch(it->first);
      }

      it = mSubscriptions.erase(it);
    } else {
      it++;
    }
  }
}
133 lines•4 KB
cpp
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer