+bool RecursiveDelete(std::string path)
+{
+ /*
+ Execute the 'rm' command directly, by fork() and execve()
+ */
+
+ std::cerr<<"Removing \""<<path<<"\""<<std::endl;
+
+ //return false;
+
+ pid_t child_pid = fork();
+
+ if(child_pid == 0)
+ {
+ // Child
+ char argv_data[3][10000];
+ strcpy(argv_data[0], "/bin/rm");
+ strcpy(argv_data[1], "-rf");
+ strncpy(argv_data[2], path.c_str(), 10000);
+ char *argv[4];
+ argv[0] = argv_data[0];
+ argv[1] = argv_data[1];
+ argv[2] = argv_data[2];
+ argv[3] = NULL;
+
+ std::cerr<<"Executing '"<<argv[0]<<"' '"<<argv[1]<<"' '"
+ <<argv[2]<<"'"<<std::endl;
+
+ execv(argv[0], argv);
+
+ // Execv shouldn't return. Failed.
+ return false;
+ }
+ else
+ {
+ // Parent
+ int child_status;
+ pid_t tpid;
+ do{
+ tpid = wait(&child_status);
+ //if(tpid != child_pid) process_terminated(tpid);
+ }while(tpid != child_pid);
+ return (child_status == 0);
+ }
+}
+