本文整理汇总了C++中rm_rf函数的典型用法代码示例。如果您正苦于以下问题:C++ rm_rf函数的具体用法?C++ rm_rf怎么用?C++ rm_rf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rm_rf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tar_pull_unref
TarPull* tar_pull_unref(TarPull *i) {
if (!i)
return NULL;
if (i->tar_pid > 1) {
(void) kill_and_sigcont(i->tar_pid, SIGKILL);
(void) wait_for_terminate(i->tar_pid, NULL);
}
pull_job_unref(i->tar_job);
pull_job_unref(i->settings_job);
pull_job_unref(i->checksum_job);
pull_job_unref(i->signature_job);
curl_glue_unref(i->glue);
sd_event_unref(i->event);
if (i->temp_path) {
(void) rm_rf(i->temp_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
free(i->temp_path);
}
if (i->settings_temp_path) {
(void) unlink(i->settings_temp_path);
free(i->settings_temp_path);
}
free(i->final_path);
free(i->settings_path);
free(i->image_root);
free(i->local);
return mfree(i);
}
示例2: test_readlink_and_make_absolute
static void test_readlink_and_make_absolute(void) {
char tempdir[] = "/tmp/test-readlink_and_make_absolute";
char name[] = "/tmp/test-readlink_and_make_absolute/original";
char name2[] = "test-readlink_and_make_absolute/original";
char name_alias[] = "/tmp/test-readlink_and_make_absolute-alias";
char *r = NULL;
assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) >= 0);
assert_se(touch(name) >= 0);
assert_se(symlink(name, name_alias) >= 0);
assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
assert_se(streq(r, name));
free(r);
assert_se(unlink(name_alias) >= 0);
assert_se(chdir(tempdir) >= 0);
assert_se(symlink(name2, name_alias) >= 0);
assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
assert_se(streq(r, name));
free(r);
assert_se(unlink(name_alias) >= 0);
assert_se(rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
}
示例3: rm_rf
static void
rm_rf (const char * killme)
{
struct stat sb;
if (!stat (killme, &sb))
{
DIR * odir;
if (S_ISDIR (sb.st_mode) && ((odir = opendir (killme))))
{
struct dirent *d;
for (d = readdir(odir); d != NULL; d=readdir(odir))
{
if (d->d_name && strcmp(d->d_name,".") && strcmp(d->d_name,".."))
{
char * tmp = tr_buildPath (killme, d->d_name, NULL);
rm_rf (tmp);
tr_free (tmp);
}
}
closedir (odir);
}
if (verbose)
fprintf (stderr, "cleanup: removing %s\n", killme);
tr_remove (killme);
}
}
示例4: tar_import_finish
static int tar_import_finish(TarImport *i) {
int r;
assert(i);
assert(i->tar_fd >= 0);
assert(i->temp_path);
assert(i->final_path);
i->tar_fd = safe_close(i->tar_fd);
if (i->tar_pid > 0) {
r = wait_for_terminate_and_warn("tar", i->tar_pid, true);
i->tar_pid = 0;
if (r < 0)
return r;
}
if (i->read_only) {
r = import_make_read_only(i->temp_path);
if (r < 0)
return r;
}
if (i->force_local)
(void) rm_rf(i->final_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
r = rename_noreplace(AT_FDCWD, i->temp_path, AT_FDCWD, i->final_path);
if (r < 0)
return log_error_errno(r, "Failed to move image into place: %m");
free(i->temp_path);
i->temp_path = NULL;
return 0;
}
示例5: setup_test
static int setup_test(Manager **m) {
char **tests_path = STRV_MAKE("exists", "existsglobFOOBAR", "changed", "modified", "unit",
"directorynotempty", "makedirectory");
char **test_path;
Manager *tmp = NULL;
int r;
assert_se(m);
r = manager_new(MANAGER_USER, true, &tmp);
if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT, -ENOEXEC)) {
printf("Skipping test: manager_new: %s", strerror(-r));
return -EXIT_TEST_SKIP;
}
assert_se(r >= 0);
assert_se(manager_startup(tmp, NULL, NULL) >= 0);
STRV_FOREACH(test_path, tests_path) {
_cleanup_free_ char *p = NULL;
p = strjoin("/tmp/test-path_", *test_path, NULL);
assert_se(p);
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
}
示例6: tar_import_unref
TarImport* tar_import_unref(TarImport *i) {
if (!i)
return NULL;
sd_event_source_unref(i->input_event_source);
if (i->tar_pid > 1) {
(void) kill_and_sigcont(i->tar_pid, SIGKILL);
(void) wait_for_terminate(i->tar_pid, NULL);
}
if (i->temp_path) {
(void) rm_rf(i->temp_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
free(i->temp_path);
}
import_compress_free(&i->compress);
sd_event_unref(i->event);
safe_close(i->tar_fd);
free(i->final_path);
free(i->image_root);
free(i->local);
free(i);
return NULL;
}
示例7: rm_rf
static void
rm_rf (const char * killme)
{
tr_sys_path_info info;
if (tr_sys_path_get_info (killme, 0, &info, NULL))
{
tr_sys_dir_t odir;
if (info.type == TR_SYS_PATH_IS_DIRECTORY &&
(odir = tr_sys_dir_open (killme, NULL)) != TR_BAD_SYS_DIR)
{
const char * name;
while ((name = tr_sys_dir_read_name (odir, NULL)) != NULL)
{
if (strcmp (name, ".") != 0 && strcmp (name, "..") != 0)
{
char * tmp = tr_buildPath (killme, name, NULL);
rm_rf (tmp);
tr_free (tmp);
}
}
tr_sys_dir_close (odir, NULL);
}
if (verbose)
fprintf (stderr, "cleanup: removing %s\n", killme);
tr_sys_path_remove (killme, NULL);
}
}
示例8: rm_rf
/*
* Given a local directory, do the equivalent of `rm -rf`
* on it, but using the actual filesystem API.
* You can't just use dir->Remove() because that
* gives an error if the directory is not empty.
*/
void
rm_rf(BDirectory *dir)
{
status_t err;
BEntry entry;
err = dir->GetNextEntry(&entry);
while(err==B_OK)
{
BFile file = BFile(&entry, B_READ_ONLY);
if(file.IsDirectory())
{
BDirectory ndir = BDirectory(&entry);
rm_rf(&ndir);
}
err = entry.Remove();
if(err != B_OK)
{
BPath path;
entry.GetPath(&path);
printf("Remove Error: %s on %s\n",strerror(err),path.Path());
//what to do if I can't remove something?
}
err = dir->GetNextEntry(&entry);
}
err = dir->GetEntry(&entry);
err = entry.Remove();
if(err != B_OK)
printf("Folder Removal Error: %s\n", strerror(err));
}
示例9: test_exec_workingdirectory
static void test_exec_workingdirectory(Manager *m) {
assert_se(mkdir_p("/tmp/test-exec_workingdirectory", 0755) >= 0);
test(m, "exec-workingdirectory.service", 0, CLD_EXITED);
(void) rm_rf("/tmp/test-exec_workingdirectory", REMOVE_ROOT|REMOVE_PHYSICAL);
}
示例10: rm_rf
static void
rm_rf(const char *path)
{
DIR *d;
struct dirent *e;
struct stat st;
char filepath[MAXPATHLEN];
if ((d = opendir(path)) == NULL) {
pkg_emit_errno("opendir", path);
return;
}
while ((e = readdir(d)) != NULL) {
if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0)
continue;
snprintf(filepath, sizeof(filepath), "%s/%s", path, e->d_name);
if (lstat(filepath, &st) != 0) {
pkg_emit_errno("lstat", filepath);
continue;
}
if (S_ISDIR(st.st_mode))
rm_rf(filepath);
remove(filepath);
}
closedir(d);
}
示例11: setup_test
static int setup_test(Manager **m) {
char **tests_path = STRV_MAKE("exists", "existsglobFOOBAR", "changed", "modified", "unit",
"directorynotempty", "makedirectory");
char **test_path;
Manager *tmp = NULL;
int r;
assert_se(m);
r = enter_cgroup_subroot();
if (r == -ENOMEDIUM) {
log_notice_errno(r, "Skipping test: cgroupfs not available");
return -EXIT_TEST_SKIP;
}
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &tmp);
if (MANAGER_SKIP_TEST(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");
return -EXIT_TEST_SKIP;
}
assert_se(r >= 0);
assert_se(manager_startup(tmp, NULL, NULL) >= 0);
STRV_FOREACH(test_path, tests_path) {
_cleanup_free_ char *p = NULL;
p = strjoin("/tmp/test-path_", *test_path);
assert_se(p);
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
}
示例12: test_copy_tree
static void test_copy_tree(void) {
char original_dir[] = "/tmp/test-copy_tree/";
char copy_dir[] = "/tmp/test-copy_tree-copy/";
char **files = STRV_MAKE("file", "dir1/file", "dir1/dir2/file", "dir1/dir2/dir3/dir4/dir5/file");
char **links = STRV_MAKE("link", "file",
"link2", "dir1/file");
char **p, **link;
(void) rm_rf(copy_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
(void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
STRV_FOREACH(p, files) {
char *f = strjoina(original_dir, *p);
assert_se(mkdir_parents(f, 0755) >= 0);
assert_se(write_string_file(f, "file") == 0);
}
示例13: test_skip
static void test_skip(void (*setup)(void)) {
char t[] = "/tmp/journal-skip-XXXXXX";
sd_journal *j;
int r;
assert_se(mkdtemp(t));
assert_se(chdir(t) >= 0);
setup();
/* Seek to head, iterate down.
*/
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_seek_head(j));
assert_ret(sd_journal_next(j));
test_check_numbers_down(j, 4);
sd_journal_close(j);
/* Seek to tail, iterate up.
*/
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_seek_tail(j));
assert_ret(sd_journal_previous(j));
test_check_numbers_up(j, 4);
sd_journal_close(j);
/* Seek to tail, skip to head, iterate down.
*/
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_seek_tail(j));
assert_ret(r = sd_journal_previous_skip(j, 4));
assert_se(r == 4);
test_check_numbers_down(j, 4);
sd_journal_close(j);
/* Seek to head, skip to tail, iterate up.
*/
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_seek_head(j));
assert_ret(r = sd_journal_next_skip(j, 4));
assert_se(r == 4);
test_check_numbers_up(j, 4);
sd_journal_close(j);
log_info("Done...");
if (arg_keep)
log_info("Not removing %s", t);
else {
journal_directory_vacuum(".", 3000000, 0, NULL, true);
assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
}
puts("------------------------------------------------------------");
}
示例14: test_conf_files_list
static void test_conf_files_list(bool use_root) {
char tmp_dir[] = "/tmp/test-conf-files-XXXXXX";
_cleanup_strv_free_ char **found_files = NULL, **found_files2 = NULL;
const char *root_dir, *search_1, *search_2, *expect_a, *expect_b, *expect_c, *mask;
log_debug("/* %s(%s) */", __func__, yes_no(use_root));
setup_test_dir(tmp_dir,
"/dir1/a.conf",
"/dir2/a.conf",
"/dir2/b.conf",
"/dir2/c.foo",
"/dir2/d.conf",
NULL);
mask = strjoina(tmp_dir, "/dir1/d.conf");
assert_se(symlink("/dev/null", mask) >= 0);
if (use_root) {
root_dir = tmp_dir;
search_1 = "/dir1";
search_2 = "/dir2";
} else {
root_dir = NULL;
search_1 = strjoina(tmp_dir, "/dir1");
search_2 = strjoina(tmp_dir, "/dir2");
}
expect_a = strjoina(tmp_dir, "/dir1/a.conf");
expect_b = strjoina(tmp_dir, "/dir2/b.conf");
expect_c = strjoina(tmp_dir, "/dir2/c.foo");
log_debug("/* Check when filtered by suffix */");
assert_se(conf_files_list(&found_files, ".conf", root_dir, CONF_FILES_FILTER_MASKED, search_1, search_2, NULL) == 0);
strv_print(found_files);
assert_se(found_files);
assert_se(streq_ptr(found_files[0], expect_a));
assert_se(streq_ptr(found_files[1], expect_b));
assert_se(!found_files[2]);
log_debug("/* Check when unfiltered */");
assert_se(conf_files_list(&found_files2, NULL, root_dir, CONF_FILES_FILTER_MASKED, search_1, search_2, NULL) == 0);
strv_print(found_files2);
assert_se(found_files2);
assert_se(streq_ptr(found_files2[0], expect_a));
assert_se(streq_ptr(found_files2[1], expect_b));
assert_se(streq_ptr(found_files2[2], expect_c));
assert_se(!found_files2[3]);
assert_se(rm_rf(tmp_dir, REMOVE_ROOT|REMOVE_PHYSICAL) == 0);
}
示例15: pkg_cache_full_clean
void
pkg_cache_full_clean(void)
{
const char *cachedir;
if (!pkg_object_bool(pkg_config_get("AUTOCLEAN")))
return;
pkg_debug(1, "Cleaning up cachedir");
cachedir = pkg_object_string(pkg_config_get("PKG_CACHEDIR"));
return (rm_rf(cachedir));
}