static void removeRec(const char *path,bool rec) { if(isdir(path)) { if(!rec) { printe("Omitting directory '%s'",path); return; } char tmp[MAX_PATH_LEN]; DIR *dir = opendir(path); struct dirent e; while(readdir(dir,&e)) { if(strcmp(e.d_name,".") == 0 || strcmp(e.d_name,"..") == 0) continue; snprintf(tmp,sizeof(tmp),"%s/%s",path,e.d_name); removeRec(tmp,rec); } closedir(dir); if(rmdir(path) < 0) printe("Unable to remove directory '%s'",path); } else if(unlink(path) < 0) printe("Unable to unlink '%s'",path); }
int main(int argc,const char *argv[]) { int rec = false; const char **args; int res = ca_parse(argc,argv,0,"r",&rec,&rec); if(res < 0) { printe("Invalid arguments: %s",ca_error(res)); usage(argv[0]); } if(ca_hasHelp() || ca_getFreeCount() == 0) usage(argv[0]); args = ca_getFree(); while(*args) { removeRec(*args,rec); args++; } return EXIT_SUCCESS; }
static void retractPackage() { EdiRec *rec; cchar *password, *name; name = param("name"); password = param("password"); if (!name || !*name || !password || !*password) { sendResult(feedback("error", "Missing name or password parameters")); return; } if ((rec = readRecWhere("pak", "name", "==", name)) == 0) { sendResult(feedback("error", "Cannot find package")); return; } else if (!mprCheckPassword(password, getField(rec, "password"))) { sendResult(feedback("error", "Invalid password")); return; } sendResult(removeRec("pak", rec->id)); }
/* Remove a resource identified by the "id" parameter */ static void removePost() { if (removeRec("post", param("id"))) { flash("inform", "Post Removed"); } redirect("list"); }