static bool scan_directory_cb(library_directory_t *directory, void *empty) { (void)empty; struct stat status; if (stat(directory->path, &status)) { musicd_perror(LOG_DEBUG, "scan", "removing directory %s", directory->path); library_directory_delete(directory->id); return true; } if (interrupted) { return false; } library_iterate_directories(directory->id, scan_directory_cb, NULL); if (directory->mtime == status.st_mtime) { return true; } library_iterate_files_by_directory(directory->id, scan_files_cb); iterate_directory(directory->path, directory->id); assign_images(directory->id); if (interrupted) { return false; } library_directory_mtime_set(directory->id, status.st_mtime); return true; }
int is_directory(const char *filename) { char *basename; char *dirname; size_t i; char *copy; if (grub_strcmp(filename, "/") == 0) return 1; copy = grub_strdup(filename); if (!copy) return 0; dirname = copy; i = grub_strlen(dirname); while (i && dirname[i - 1] == '/') dirname[--i] = '\0'; basename = grub_strrchr(dirname, '/'); if (basename) *basename++ = '\0'; else basename = "/"; if (*dirname == '\0') dirname = "/"; is_directory_filename = basename; is_directory_result = 0; iterate_directory(dirname, is_directory_callback); grub_free(copy); return is_directory_result; }
static PyObject *bits__listdir(PyObject *self, PyObject *args) { PyObject *result; const char *path; if (!PyArg_ParseTuple(args, "s", &path)) return NULL; if (!is_directory(path)) return os_error_with_filename(ENOTDIR, path); listdir_result = PyList_New(0); iterate_directory(path, listdir_callback); result = listdir_result; listdir_result = NULL; return result; }
static void scan_directory(const char *dirpath, int parent) { int dir_id; time_t dir_mtime; struct stat status; dir_id = library_directory(dirpath, -1); if (stat(dirpath, &status)) { musicd_perror(LOG_WARNING, "scan", "could not stat directory %s", dirpath); if (dir_id) { library_directory_delete(dir_id); } return; } if (dir_id > 0) { library_iterate_directories(dir_id, scan_directory_cb, NULL); dir_mtime = library_directory_mtime(dir_id); if (dir_mtime == status.st_mtime) { return; } } else { dir_id = library_directory(dirpath, parent); } library_iterate_files_by_directory(dir_id, scan_files_cb); iterate_directory(dirpath, dir_id); assign_images(dir_id); if (interrupted) { return; } library_directory_mtime_set(dir_id, status.st_mtime); }