本文整理汇总了C++中rm_rf函数的典型用法代码示例。如果您正苦于以下问题:C++ rm_rf函数的具体用法?C++ rm_rf怎么用?C++ rm_rf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rm_rf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:34,代码来源:pull-tar.c
示例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);
}
开发者ID:BenjaminLefoul,项目名称:systemd,代码行数:25,代码来源:test-fs-util.c
示例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);
}
}
开发者ID:Elbandi,项目名称:transmission,代码行数:30,代码来源:libtransmission-test.c
示例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;
}
开发者ID:rachari,项目名称:systemd,代码行数:35,代码来源:import-tar.c
示例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);
}
开发者ID:josephgbr,项目名称:systemd,代码行数:25,代码来源:test-path.c
示例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;
}
开发者ID:rachari,项目名称:systemd,代码行数:29,代码来源:import-tar.c
示例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);
}
}
开发者ID:JanX2,项目名称:transmission,代码行数:31,代码来源:libtransmission-test.c
示例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));
}
开发者ID:astrieanna,项目名称:haiku-dropbox-client,代码行数:37,代码来源:HaikuDropbox.cpp
示例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);
}
开发者ID:PlanetEater,项目名称:systemd,代码行数:7,代码来源:test-execute.c
示例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);
}
开发者ID:ChunHungLiu,项目名称:pkg,代码行数:27,代码来源:clean_cache.c
示例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);
}
开发者ID:davide125,项目名称:systemd,代码行数:31,代码来源:test-path.c
示例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);
}
开发者ID:iaguis,项目名称:systemd,代码行数:17,代码来源:test-copy.c
示例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("------------------------------------------------------------");
}
开发者ID:AlexBaranosky,项目名称:systemd,代码行数:56,代码来源:test-journal-interleaving.c
示例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);
}
开发者ID:Keruspe,项目名称:systemd,代码行数:54,代码来源:test-conf-files.c
示例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));
}
开发者ID:ChunHungLiu,项目名称:pkg,代码行数:14,代码来源:clean_cache.c
示例16: 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;
const char *unixsockp;
struct stat st;
log_info("%s", __func__);
(void) rm_rf(copy_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
(void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
STRV_FOREACH(p, files) {
_cleanup_free_ char *f;
assert_se(f = strappend(original_dir, *p));
assert_se(mkdir_parents(f, 0755) >= 0);
assert_se(write_string_file(f, "file", WRITE_STRING_FILE_CREATE) == 0);
}
开发者ID:iamyooon,项目名称:systemd,代码行数:23,代码来源:test-copy.c
示例17: cg_trim
int cg_trim(const char *controller, const char *path, bool delete_root) {
char *fs;
int r;
assert(controller);
assert(path);
if ((r = cg_get_path(controller, path, NULL, &fs)) < 0)
return r;
r = rm_rf(fs, true, delete_root);
free(fs);
return r == -ENOENT ? 0 : r;
}
开发者ID:terralinux,项目名称:systemd,代码行数:15,代码来源:cgroup-util.c
示例18: pz_perror
static TWindow *browser_do_delete (ttk_menu_item *item)
{
#define PATHSIZ 512
struct stat st;
const char *filename = item->data;
if (stat (filename, &st) < 0) {
pz_perror (filename);
return TTK_MENU_UPONE;
}
if (S_ISDIR (st.st_mode)) {
/* we change the current directory here in order to find the
* absolute path of the specified directory with getcwd. this
* removes the need to check for references to the parent
* directory or follow along a path until we find the end
* result. in addition, opening the current directory and using
* its file descriptor to return to it is faster than storing
* its path */
if (filename[0]) {
int fd;
char full_path[PATHSIZ];
if ((fd = open(".", O_RDONLY)) == -1)
return TTK_MENU_UPONE;
chdir(filename);
getcwd(full_path, PATHSIZ);
fchdir(fd);
close(fd);
if (full_path[0] && full_path[1] &&
strchr(full_path + 2, '/'))
rm_rf (filename); // not "" or "/" or a root dir
else
pz_error (_("Dangerous rm -rf aborted.\n"));
}
} else {
unlink (filename);
}
/* hide the top two windows */
if (ttk_hide_window (ttk_windows->w) != -1 &&
ttk_hide_window (ttk_windows->w) != -1) {
/* -ttk_windows->w->widgets->v- is the top window's menu */
ttk_menu_remove_by_ptr(ttk_windows->w->widgets->v,
ttk_menu_get_selected_item(ttk_windows->w->widgets->v));
} else {
pz_error("Unable to close windows");
}
return TTK_MENU_DONOTHING; /* we are now back at the directory */
}
开发者ID:ysei,项目名称:podzilla2,代码行数:47,代码来源:browser.c
示例19: rm_rf
int rm_rf(char *path)
{
DIR *dir;
int ret = 0;
struct dirent *d;
char namebuf[PATH_MAX];
dir = opendir(path);
if (dir == NULL)
return 0;
while ((d = readdir(dir)) != NULL && !ret) {
struct stat statbuf;
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;
scnprintf(namebuf, sizeof(namebuf), "%s/%s",
path, d->d_name);
ret = stat(namebuf, &statbuf);
if (ret < 0) {
pr_debug("stat failed: %s\n", namebuf);
break;
}
if (S_ISREG(statbuf.st_mode))
ret = unlink(namebuf);
else if (S_ISDIR(statbuf.st_mode))
ret = rm_rf(namebuf);
else {
pr_debug("unknown file: %s\n", namebuf);
ret = -1;
}
}
closedir(dir);
if (ret < 0)
return ret;
return rmdir(path);
}
开发者ID:DenisLug,项目名称:mptcp,代码行数:42,代码来源:util.c
示例20: remove_binaries
static int remove_binaries(const char *esp_path) {
char *p;
int r, q;
unsigned i;
p = strjoina(esp_path, "/EFI/systemd");
r = rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
q = remove_boot_efi(esp_path);
if (q < 0 && r == 0)
r = q;
for (i = ELEMENTSOF(efi_subdirs); i > 0; i--) {
q = rmdir_one(esp_path, efi_subdirs[i-1]);
if (q < 0 && r == 0)
r = q;
}
return r;
}
开发者ID:Rydoo42,项目名称:systemd,代码行数:20,代码来源:bootctl.c
注:本文中的rm_rf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论