/* * Empty a local directory */ static void empty_dir(VMG_ const char *dir) { /* open the directory search */ osdirhdl_t dirhdl; if (os_open_dir(dir, &dirhdl)) { err_try { /* keep going until we're out of files */ char fname[OSFNMAX]; while (os_read_dir(dirhdl, fname, sizeof(fname))) { /* get the full path */ char path[OSFNMAX]; os_build_full_path(path, sizeof(path), dir, fname); /* get the mode */ unsigned long fmode; unsigned long fattr; if (osfmode(path, FALSE, &fmode, &fattr)) { /* check whether it's a directory or an ordinary file */ if ((fmode & OSFMODE_DIR) != 0) { /* * directory - skip the special '.' and '..' links, * since they'd get us stuck in a loop */ os_specfile_t st = os_is_special_file(fname); if (st != OS_SPECFILE_SELF && st != OS_SPECFILE_PARENT) { /* recursively empty the directory */ empty_dir(vmg_ path); /* remove this directory */ if (!os_rmdir(path)) err_throw(VMERR_DELETE_FILE); } } else { /* ordinary file - delete it */ if (osfdel(path)) err_throw(VMERR_DELETE_FILE); } } } } err_finally { /* close the directory search handle */ os_close_dir(dirhdl); } err_end; }
void OBSBasic::DeleteProfile(const char *profileName, const char *profileDir) { char profilePath[512]; char basePath[512]; int ret = GetConfigPath(basePath, 512, "obs-studio/basic/profiles"); if (ret <= 0) { blog(LOG_WARNING, "Failed to get profiles config path"); return; } ret = snprintf(profilePath, 512, "%s/%s/*", basePath, profileDir); if (ret <= 0) { blog(LOG_WARNING, "Failed to get path for profile dir '%s'", profileDir); return; } os_glob_t *glob; if (os_glob(profilePath, 0, &glob) != 0) { blog(LOG_WARNING, "Failed to glob profile dir '%s'", profileDir); return; } for (size_t i = 0; i < glob->gl_pathc; i++) { const char *filePath = glob->gl_pathv[i].path; if (glob->gl_pathv[i].directory) continue; os_unlink(filePath); } os_globfree(glob); ret = snprintf(profilePath, 512, "%s/%s", basePath, profileDir); if (ret <= 0) { blog(LOG_WARNING, "Failed to get path for profile dir '%s'", profileDir); return; } os_rmdir(profilePath); blog(LOG_INFO, "------------------------------------------------"); blog(LOG_INFO, "Removed profile '%s' (%s)", profileName, profileDir); blog(LOG_INFO, "------------------------------------------------"); }
static void dag_unlink_test(struct dag * slf, char * tstamp){ // test package should be last package of slf->sorted int i, fail; for(i = 0; slf->sorted[i]; i++); struct pkg * pk; pk = slf->sorted[i-1]; // we can assume all is fine if this is ok if( starts_with( pk->name, tstamp) ){ fail = os_unlink(pk->c_file); if(fail){ perror(pk->c_file); panic(NULL, __FILE__, __LINE__); } fail = os_unlink(pk->o_file); if(fail){ perror(pk->o_file); panic(NULL, __FILE__, __LINE__); } } const char * testdir[2]; testdir[0] = global_get_str("-src"); testdir[1] = tstamp; char * testpath = path_join_len(testdir, 2); fail = os_rmdir(testpath); if(fail){ perror(testpath); panic(NULL,__FILE__,__LINE__); } free(testpath); if(is_file(global_get_str("-testbin"))){ fail = os_unlink(global_get_str("-testbin")); if(fail){ perror(global_get_str("-testbin")); panic(NULL,__FILE__,__LINE__); } } };
static void *update_thread(void *data) { struct update_info *info = data; int cur_version; if (!init_update(info)) return NULL; cur_version = update_local_version(info); update_remote_version(info, cur_version); os_rmdir(info->temp); if (info->etag_local) bfree(info->etag_local); if (info->etag_remote) bfree(info->etag_remote); return NULL; }