void JackTools::CleanupFiles(const char* server_name) { DIR* dir; struct dirent *dirent; char dir_name[JACK_PATH_MAX + 1] = ""; ServerDir(server_name, dir_name); /* On termination, we remove all files that jackd creates so * subsequent attempts to start jackd will not believe that an * instance is already running. If the server crashes or is * terminated with SIGKILL, this is not possible. So, cleanup * is also attempted when jackd starts. * * There are several tricky issues. First, the previous JACK * server may have run for a different user ID, so its files * may be inaccessible. This is handled by using a separate * JACK_TMP_DIR subdirectory for each user. Second, there may * be other servers running with different names. Each gets * its own subdirectory within the per-user directory. The * current process has already registered as `server_name', so * we know there is no other server actively using that name. */ /* nothing to do if the server directory does not exist */ if ((dir = opendir(dir_name)) == NULL) { return; } /* unlink all the files in this directory, they are mine */ while ((dirent = readdir(dir)) != NULL) { char fullpath[JACK_PATH_MAX + 1]; if ((strcmp(dirent->d_name, ".") == 0) || (strcmp (dirent->d_name, "..") == 0)) { continue; } snprintf(fullpath, sizeof(fullpath), "%s/%s", dir_name, dirent->d_name); if (unlink(fullpath)) { jack_error("cannot unlink `%s' (%s)", fullpath, strerror(errno)); } } closedir(dir); /* now, delete the per-server subdirectory, itself */ if (rmdir(dir_name)) { jack_error("cannot remove `%s' (%s)", dir_name, strerror(errno)); } /* finally, delete the per-user subdirectory, if empty */ if (rmdir(UserDir())) { if (errno != ENOTEMPTY) { jack_error("cannot remove `%s' (%s)", UserDir(), strerror(errno)); } } }
int Redirect_List(const char* path, void* buffer, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* file_info) { const char* userPath = UserDir(); List* L; if(userPath == NULL) { L = ListFiles(rootDir, path); } else { List* lists[3]; lists[0] = ListFiles(userPath, path); lists[1] = ListFiles(rootDir, path); lists[2] = NULL; free((void*)userPath); L = join_lists(lists); } for (int i=0; i<L->length; i++) { struct stat st; memset(&st, 0, sizeof(st)); if(stat(L->str[i], &st) == -1) { List_free(L); return -errno; } const char* name = last_term(L->str[i]); int result = filler(buffer, name, &st, 0); free((void*)name); if(result != 0) break; } List_free(L); return 0; }
/* returns the name of the per-server subdirectory of jack_user_dir() */ char* JackTools::ServerDir(const char* server_name, char* server_dir) { /* format the path name into the suppled server_dir char array, * assuming that server_dir is at least as large as JACK_PATH_MAX + 1 */ snprintf(server_dir, JACK_PATH_MAX + 1, "%s/%s", UserDir(), server_name); return server_dir; }
const char* Redirect(const char* path) { const char* userPath = UserDir(); const char* result; if(userPath != NULL) { result = FindActualFile(userPath, path); free((void*)userPath); } if(userPath == NULL || result == NULL) { result = FindActualFile(rootDir, path); } return result; }
// // Creating new files // const char* Redirect_Create(const char* path) { const char* dir = UserDir(); if(dir == NULL) dir = rootDir; bool createPath = false; if(time(NULL)-lastCreate > NewPackageInterval) { dailyCounter++; lastCreate = time(NULL); createPath = true; } char basePath[64]; sprintf(basePath, "%s%s%i/", dir, newName, dailyCounter); free((void*)dir); if(createPath) mkdir(basePath, 0755); const char* array[3] = {basePath, path, NULL}; const char* newPath = join(array); return newPath; }