static void agent_destroy (agent_t **self_p) { assert (self_p); if (*self_p) { agent_t *self = *self_p; fmq_dir_t *inbox = fmq_dir_new (self->fmq_inbox, NULL); fmq_dir_remove (inbox, true); fmq_dir_destroy (&inbox); fmq_dir_t *outbox = fmq_dir_new (self->fmq_outbox, NULL); fmq_dir_remove (outbox, true); fmq_dir_destroy (&outbox); zhash_destroy (&self->peers); zhash_destroy (&self->peer_groups); zhash_destroy (&self->own_groups); zhash_destroy (&self->headers); zre_udp_destroy (&self->udp); zre_log_destroy (&self->log); fmq_server_destroy (&self->fmq_server); fmq_client_destroy (&self->fmq_client); free (self->identity); free (self); *self_p = NULL; } }
static bool mount_refresh (mount_t *self, server_t *server) { bool activity = false; // Get latest snapshot and build a patches list for any changes fmq_dir_t *latest = fmq_dir_new (self->location, NULL); zlist_t *patches = fmq_dir_diff (self->dir, latest, self->alias); // Drop old directory and replace with latest version fmq_dir_destroy (&self->dir); self->dir = latest; // Copy new patches to clients' patches list sub_t *sub = (sub_t *) zlist_first (self->subs); while (sub) { fmq_patch_t *patch = (fmq_patch_t *) zlist_first (patches); while (patch) { sub_patch_add (sub, patch); patch = (fmq_patch_t *) zlist_next (patches); activity = true; } sub = (sub_t *) zlist_next (self->subs); } // Destroy patches, they've all been copied while (zlist_size (patches)) { fmq_patch_t *patch = (fmq_patch_t *) zlist_pop (patches); fmq_patch_destroy (&patch); } zlist_destroy (&patches); return activity; }
static void s_posix_populate_entry (fmq_dir_t *self, struct dirent *entry) { // Skip . and .. if (streq (entry->d_name, ".") || streq (entry->d_name, "..")) return; char fullpath [1024 + 1]; snprintf (fullpath, 1024, "%s/%s", self->path, entry->d_name); struct stat stat_buf; if (stat (fullpath, &stat_buf)) return; if (entry->d_name [0] == '.') ; // Skip hidden files else // If we have a subdirectory, go load that if (stat_buf.st_mode & S_IFDIR) { fmq_dir_t *subdir = fmq_dir_new (entry->d_name, self->path); zlist_append (self->subdirs, subdir); } else { // Add file entry to directory list fmq_file_t *file = fmq_file_new (self->path, entry->d_name); zlist_append (self->files, file); } }
static zhash_t * sub_cache (sub_t *self) { // Get directory cache for this path fmq_dir_t *dir = fmq_dir_new (self->path + 1, self->inbox); zhash_t *cache = dir? fmq_dir_cache (dir): NULL; fmq_dir_destroy (&dir); return cache; }
static mount_t * mount_new (char *location, char *alias) { // Mount path must start with '/' // We'll do better error handling later assert (*alias == '/'); mount_t *self = (mount_t *) zmalloc (sizeof (mount_t)); self->location = strdup (location); self->alias = strdup (alias); self->dir = fmq_dir_new (self->location, NULL); self->subs = zlist_new (); return self; }
static void s_win32_populate_entry (fmq_dir_t *self, WIN32_FIND_DATA *entry) { if (entry->cFileName [0] == '.') ; // Skip hidden files else // If we have a subdirectory, go load that if (entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { fmq_dir_t *subdir = fmq_dir_new (entry->cFileName, self->path); zlist_append (self->subdirs, subdir); } else { // Add file entry to directory list fmq_file_t *file = fmq_file_new (self->path, entry->cFileName); zlist_append (self->files, file); } }