本文整理汇总了C++中rmtree函数的典型用法代码示例。如果您正苦于以下问题:C++ rmtree函数的具体用法?C++ rmtree怎么用?C++ rmtree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rmtree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exit_nicely
/*
* clean up any files we created on failure
* if we created the data directory remove it too
*/
static void
exit_nicely(void)
{
if (!noclean)
{
if (made_new_pgdata)
{
fprintf(stderr, _("%s: removing data directory \"%s\"\n"),
progname, pg_data);
if (!rmtree(pg_data, true))
fprintf(stderr, _("%s: failed to remove data directory\n"),
progname);
}
else if (found_existing_pgdata)
{
fprintf(stderr,
_("%s: removing contents of data directory \"%s\"\n"),
progname, pg_data);
if (!rmtree(pg_data, false))
fprintf(stderr, _("%s: failed to remove contents of data directory\n"),
progname);
}
/* otherwise died during startup, do nothing! */
}
else
{
if (made_new_pgdata || found_existing_pgdata)
fprintf(stderr,
_("%s: data directory \"%s\" not removed at user's request\n"),
progname, pg_data);
}
exit(1);
}
示例2: main
int main(int argc, char ** argv)
{
int n = 1;
real m = 1.0;
check_help();
extern char *poptarg;
int c;
const char *param_string = "m:n:";
while ((c = pgetopt(argc, argv, param_string,
"$Revision: 1.9 $", _SRC_)) != -1)
switch(c) {
case 'm': m = atof(poptarg);
break;
case 'n': n = atoi(poptarg);
break;
case '?': params_to_usage(cerr, argv[0], param_string);
get_help();
exit(1);
}
if (m <= 0) err_exit("mknodes: M > 0 required!");
if (n <= 0) err_exit("mknodes: N > 0 required!");
node * root = mknode_mass(n, m);
root->log_history(argc, argv);
put_node(root);
rmtree(root);
return 0;
}
示例3: rmtree
// Recursively deletes the file named path. If path is a file, it will be
// removed. If it is a directory, everything in it will also be deleted.
// Returns 0 on success, -1 on error, and sets errno appropriately.
static int rmtree(const char* path) {
// TODO: Handle errors in a more intelligent fashion?
DIR* dir = opendir(path);
if (dir == NULL) {
if (errno == ENOTDIR) {
// Not a directory: unlink it instead
return unlink(path);
}
return -1;
}
assert(dir != NULL);
for (struct dirent* entry = readdir(dir); entry != NULL; entry = readdir(dir)) {
// Skip special directories
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
// Recursively delete the directory entry. This handles regular files
// and directories.
string fullpath(path);
fullpath += "/";
fullpath += entry->d_name;
rmtree(fullpath.c_str());
}
int error = closedir(dir);
assert(error == 0);
return rmdir(path);
}
示例4: copy_subdir_files
/*
* Delete the given subdirectory contents from the new cluster, and copy the
* files from the old cluster into it.
*/
static void
copy_subdir_files(char *subdir)
{
char old_path[MAXPGPATH];
char new_path[MAXPGPATH];
prep_status("Deleting files from new %s", subdir);
snprintf(old_path, sizeof(old_path), "%s/%s", old_cluster.pgdata, subdir);
snprintf(new_path, sizeof(new_path), "%s/%s", new_cluster.pgdata, subdir);
if (!rmtree(new_path, true))
pg_log(PG_FATAL, "could not delete directory \"%s\"\n", new_path);
check_ok();
prep_status("Copying old %s to new server", subdir);
exec_prog(UTILITY_LOG_FILE, NULL, true,
#ifndef WIN32
"cp -Rf \"%s\" \"%s\"",
#else
/* flags: everything, no confirm, quiet, overwrite read-only */
"xcopy /e /y /q /r \"%s\" \"%s\\\"",
#endif
old_path, new_path);
check_ok();
}
示例5: opendir
bool FileSystem::rmtree(const Path& path) {
Directory* test_dir = opendir(path);
if (test_dir != NULL) {
auto_Object<Directory> dir(test_dir);
Directory::Entry* test_dentry = dir->read();
if (test_dentry != NULL) {
auto_Object<Directory::Entry> dentry(*test_dentry);
do {
if (dentry->is_special()) {
continue;
}
Path dentry_path(path / dentry->get_name());
if (dentry->ISDIR()) {
if (rmtree(dentry_path)) {
continue;
} else {
return false;
}
} else if (unlink(dentry_path)) {
continue;
} else {
return false;
}
} while (dir->read(*dentry));
return rmdir(path);
}
}
return false;
}
示例6: move_program
static BOOL move_program() {
if (MoveFileEx(L"Calibre Portable\\calibre-portable.exe",
L"..\\calibre-portable.exe", MOVEFILE_REPLACE_EXISTING) == 0) {
show_last_error(L"Failed to move calibre-portable.exe, make sure calibre is not running");
return false;
}
if (directory_exists(L"..\\Calibre")) {
if (!rmtree(L"..\\Calibre")) {
show_error(L"Failed to delete the Calibre program folder. Make sure calibre is not running.");
return false;
}
}
if (MoveFileEx(L"Calibre Portable\\Calibre", L"..\\Calibre", 0) == 0) {
Sleep(4000); // Sleep and try again
if (MoveFileEx(L"Calibre Portable\\Calibre", L"..\\Calibre", 0) == 0) {
show_last_error(L"Failed to move calibre program folder. This is usually caused by an antivirus program or a file sync program like DropBox. Turn them off temporarily and try again. Underlying error: ");
return false;
}
}
if (!directory_exists(L"..\\Calibre Library")) {
MoveFileEx(L"Calibre Portable\\Calibre Library", L"..\\Calibre Library", 0);
}
if (!directory_exists(L"..\\Calibre Settings")) {
MoveFileEx(L"Calibre Portable\\Calibre Settings", L"..\\Calibre Settings", 0);
}
return true;
}
示例7: main
main(int argc, char ** argv)
{
check_help();
extern char *poptarg;
extern char *poparr[];
int c;
const char *param_string = "";
while ((c = pgetopt(argc, argv, param_string,
"$Revision: 1.5 $", _SRC_)) != -1)
switch(c) {
case '?': params_to_usage(cerr, argv[0], param_string);
get_help();
exit(1);
}
dyn *b;
real prev_time = -VERY_LARGE_NUMBER;
cerr.precision(HIGH_PRECISION);
while (b = get_dyn()) {
real time = b->get_system_time();
if (prev_time > -VERY_LARGE_NUMBER) {
real dt = time - prev_time;
PRC(time); PRL(dt);
} else
PRL(time);
prev_time = time;
rmtree(b);
}
}
示例8: testutil_cleanup
void
testutil_cleanup(void)
{
test_call_ok(chdir(orig_wd), strerror(errno),
"cd into original working directory");
rmtree("test_tmp");
}
示例9: CreateSlotOnDisk
/* ----
* Manipulation of ondisk state of replication slots
*
* NB: none of the routines below should take any notice whether a slot is the
* current one or not, that's all handled a layer above.
* ----
*/
static void
CreateSlotOnDisk(ReplicationSlot *slot)
{
char tmppath[MAXPGPATH];
char path[MAXPGPATH];
struct stat st;
/*
* No need to take out the io_in_progress_lock, nobody else can see this
* slot yet, so nobody else will write. We're reusing SaveSlotToPath which
* takes out the lock, if we'd take the lock here, we'd deadlock.
*/
sprintf(path, "pg_replslot/%s", NameStr(slot->data.name));
sprintf(tmppath, "pg_replslot/%s.tmp", NameStr(slot->data.name));
/*
* It's just barely possible that some previous effort to create or
* drop a slot with this name left a temp directory lying around.
* If that seems to be the case, try to remove it. If the rmtree()
* fails, we'll error out at the mkdir() below, so we don't bother
* checking success.
*/
if (stat(tmppath, &st) == 0 && S_ISDIR(st.st_mode))
rmtree(tmppath, true);
/* Create and fsync the temporary slot directory. */
if (mkdir(tmppath, S_IRWXU) < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not create directory \"%s\": %m",
tmppath)));
fsync_fname(tmppath, true);
/* Write the actual state file. */
slot->dirty = true; /* signal that we really need to write */
SaveSlotToPath(slot, tmppath, ERROR);
/* Rename the directory into place. */
if (rename(tmppath, path) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not rename file \"%s\" to \"%s\": %m",
tmppath, path)));
/*
* If we'd now fail - really unlikely - we wouldn't know whether this slot
* would persist after an OS crash or not - so, force a restart. The
* restart would try to fysnc this again till it works.
*/
START_CRIT_SECTION();
fsync_fname(path, true);
fsync_fname("pg_replslot", true);
END_CRIT_SECTION();
}
示例10: chdir
ChTempDir::~ChTempDir() {
// TODO: chdir back to the original directory?
int status = chdir("/");
assert(status == 0);
// Recursively delete everything in the temporary directory.
status = rmtree(name_.c_str());
assert(status == 0);
}
示例11: runbenchn
static void
runbenchn(Benchmark *b, int n)
{
int outfd = tmpfd();
int durfd = tmpfd();
strcpy(b->dir, TmpDirPat);
mktemp(b->dir);
int pid = fork();
if (pid < 0) {
die(1, errno, "fork");
} else if (!pid) {
setpgid(0, 0);
if (dup2(outfd, 1) == -1) {
die(3, errno, "dup2");
}
if (close(outfd) == -1) {
die(3, errno, "fclose");
}
if (dup2(1, 2) == -1) {
die(3, errno, "dup2");
}
curdir = b->dir;
ctstarttimer();
b->f(n);
ctstoptimer();
write(durfd, &bdur, sizeof bdur);
write(durfd, &bbytes, sizeof bbytes);
_exit(0);
}
setpgid(pid, pid);
pid = waitpid(pid, &b->status, 0);
if (pid == -1) {
die(3, errno, "wait");
}
killpg(pid, 9);
rmtree(b->dir);
if (b->status != 0) {
putchar('\n');
lseek(outfd, 0, SEEK_SET);
copyfd(stdout, outfd);
return;
}
lseek(durfd, 0, SEEK_SET);
int r = read(durfd, &b->dur, sizeof b->dur);
if (r != sizeof b->dur) {
perror("read");
b->status = 1;
}
r = read(durfd, &b->bytes, sizeof b->bytes);
if (r != sizeof b->bytes) {
perror("read");
b->status = 1;
}
}
示例12: rmtree
void rmtree(node* b,
bool delete_b) // default = true
{
node* d = b->get_oldest_daughter();
while (d) {
node* tmp = d->get_younger_sister();
rmtree(d);
d = tmp;
}
if (delete_b) delete b; // optionally leave node itself untouched
}
示例13: main
main(int argc, char *argv[])
{
// Read and sort the list of masses.
vector<real> mass;
bool percent = false;
mass.push_back(0);
for (int i = 1; i < argc; i++) {
real m = atof(argv[i]);
mass.push_back(m);
if (m > 1) percent = true; // default interpretation is fraction,
// >1 ==> switch to percentile
}
if (percent)
for (int i = 0; i < mass.size(); i++) mass[i] = 0.01*mass[i];
sort(mass.begin(), mass.end());
mass.push_back(1.0);
dyn *b; // root node
while (b = get_dyn()) {
// Compute the quartiles (not actually printed, but stored
// in the root dyn story) for each mass range.
cerr << b->get_system_time() << " ";
for (int i = 1; i < mass.size(); i++) {
if (i == 1)
set_lagr_cutoff_mass(b, mass[i-1], mass[i]); // sort masses
else
reset_lagr_cutoff_mass(b, mass[i-1], mass[i]); // no sort
real rhalf = compute_lagrangian_radii(b, 0.5,
false, // not verbose
4); // mass filter
// Alternatively, if several Lagrangian radii are needed:
//
// real lagr_array[3] = {0.1, 0.5, 0.9};
// compute_lagrangian_radii(b,
// lagr_array, 3,
// false, // not verbose
// 4); // mass filter
// rhalf = lagr_array[1];
cerr << rhalf<< " ";
}
cerr << endl;
rmtree(b);
}
}
示例14: StartupReplicationSlots
/*
* Load all replication slots from disk into memory at server startup. This
* needs to be run before we start crash recovery.
*/
void
StartupReplicationSlots(XLogRecPtr checkPointRedo)
{
DIR *replication_dir;
struct dirent *replication_de;
ereport(DEBUG1,
(errmsg("starting up replication slots")));
/* restore all slots by iterating over all on-disk entries */
replication_dir = AllocateDir("pg_replslot");
while ((replication_de = ReadDir(replication_dir, "pg_replslot")) != NULL)
{
struct stat statbuf;
char path[MAXPGPATH];
if (strcmp(replication_de->d_name, ".") == 0 ||
strcmp(replication_de->d_name, "..") == 0)
continue;
snprintf(path, MAXPGPATH, "pg_replslot/%s", replication_de->d_name);
/* we're only creating directories here, skip if it's not our's */
if (lstat(path, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
continue;
/* we crashed while a slot was being setup or deleted, clean up */
if (string_endswith(replication_de->d_name, ".tmp"))
{
if (!rmtree(path, true))
{
ereport(WARNING,
(errcode_for_file_access(),
errmsg("could not remove directory \"%s\"", path)));
continue;
}
fsync_fname("pg_replslot", true);
continue;
}
/* looks like a slot in a normal state, restore */
RestoreSlotFromDisk(replication_de->d_name);
}
FreeDir(replication_dir);
/* currently no slots exist, we're done. */
if (max_replication_slots <= 0)
return;
/* Now that we have recovered all the data, compute replication xmin */
ReplicationSlotsComputeRequiredXmin();
ReplicationSlotsComputeRequiredLSN();
}
示例15: queue_message_incoming_delete
int
queue_message_incoming_delete(uint32_t msgid)
{
char rootdir[MAXPATHLEN];
if (! queue_message_incoming_path(msgid, rootdir, sizeof(rootdir)))
fatal("queue_message_incoming_delete: snprintf");
if (rmtree(rootdir, 0) == -1)
fatal("queue_message_incoming_delete: rmtree");
return 1;
}