void pocl_cache_cleanup_cachedir(cl_program program) { unsigned i; if (!pocl_get_bool_option("POCL_KERNEL_CACHE", POCL_BUILD_KERNEL_CACHE)) { for (i=0; i< program->num_devices; i++) { if (program->build_hash[i][0] == 0) continue; void* lock = acquire_program_lock(program, i, 0); if (!lock) return; char cachedir[POCL_FILENAME_LENGTH]; program_device_dir(cachedir, program, i, ""); pocl_rm_rf(cachedir); release_lock(lock); } } }
int pocl_rm_rf(const char* path) { DIR *d = opendir(path); size_t path_len = strlen(path); int error = -1; if(d) { struct dirent *p = readdir(d); error = 0; while (!error && p) { char *buf; if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) continue; size_t len = path_len + strlen(p->d_name) + 2; buf = malloc(len); buf[len] = '\0'; if (buf) { struct stat statbuf; snprintf(buf, len, "%s/%s", path, p->d_name); if (!stat(buf, &statbuf)) error = pocl_rm_rf(buf); else error = remove(buf); free(buf); } p = readdir(d); } closedir(d); if (!error) remove(path); } return error; }