bool create_tar_file(char *path) { char tar_file_path[PATH_MAX] = { 0 }; snprintf(tar_file_path, sizeof(tar_file_path), "%s.tar.gz", path); char *args[5] = { 0 }; args[0] = "tar"; args[1] = "-zcf"; args[2] = tar_file_path; args[3] = path; args[4] = NULL; pid_t pid = fork(); if (pid < 0) { Error("fork()"); } else if (pid == 0) { execvp(args[0], args); exit(1); } pid = wait(NULL); //RemoveDirectory(path); rename_directory(path); return true; }
void DirectoryTree::init_actions() { PkmPlugin *plugin = dynamic_cast<PkmPlugin*>(get_plugin().pointer()); assert(NULL != plugin); // rename directory _rename_action = new QAction(plugin->load_icon("pkm/rename"), tr("重命名(&R)"), this); _rename_action->setStatusTip(tr("重命名当前目录")); _rename_action->setToolTip(tr("重命名当前目录")); connect(_rename_action, SIGNAL(triggered()), this, SLOT(rename_directory())); // add brother _add_brother_action = new QAction(plugin->load_icon("pkm/add_brother"), tr("添加兄弟节点(&A)"), this); _add_brother_action->setStatusTip(tr("为当前目录添加一个兄弟节点")); _add_brother_action->setToolTip(tr("为当前目录添加一个兄弟节点")); connect(_add_brother_action, SIGNAL(triggered()), this, SLOT(add_brother())); // add child _add_child_action = new QAction(plugin->load_icon("pkm/add_child"), tr("添加子节点(&A)"), this); _add_child_action->setStatusTip(tr("为当前目录添加一个子节点")); _add_child_action->setToolTip(tr("为当前目录添加一个子节点")); connect(_add_child_action, SIGNAL(triggered()), this, SLOT(add_child())); // delete _delete_action = new QAction(plugin->load_icon("pkm/delete"), tr("删除(&D)"), this); _delete_action->setStatusTip(tr("删除当前目录")); _delete_action->setToolTip(tr("删除当前目录")); connect(_delete_action, SIGNAL(triggered()), this, SLOT(delete_directory())); // import _import_action = new QAction(plugin->load_icon("pkm/import_files"), tr("导入"), this); _import_action->setStatusTip(tr("导入本地文件")); _import_action->setToolTip(tr("导入本地文件")); connect(_import_action, SIGNAL(triggered()), this, SLOT(import_from_files())); }
bool create_zip_file(char *path) { char zip_file_path[PATH_MAX] = { 0 }; snprintf(zip_file_path, sizeof(zip_file_path), "%s.zip", path); char *args[5] = { 0 }; /* char *vbscript = "ArchiveFolder Wscript.Arguments.Item(0), Wscript.Arguments.Item(1)\r\n" "Sub ArchiveFolder (zipFile, sFolder)\r\n" "With CreateObject(\"Scripting.FileSystemObject\")\r\n" "zipFile = .GetAbsolutePathName(zipFile)\r\n" "sFolder = .GetAbsolutePathName(sFolder)\r\n" " With .CreateTextFile(zipFile, True)\r\n" " .Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, chr(0))\r\n" " End With\r\n" "End With\r\n" "With CreateObject(\"Shell.Application\")\r\n" " .NameSpace(zipFile).CopyHere .NameSpace(sFolder).Items\r\n" " Do Until .NameSpace(zipFile).Items.Count = _\r\n" " .NameSpace(sFolder).Items.Count\r\n" " WScript.Sleep 1000\r\n" " Loop\r\n" "End With\r\n" "End Sub\r\n"; */ #define VBSCRIPT_PATH "zip.vbs" args[0] = "cscript"; args[1] = VBSCRIPT_PATH; args[2] = zip_file_path; args[3] = path; args[4] = NULL; pid_t p = fork(); if (p < 0) Error("fork"); else if (p == 0) { execvp(args[0], args); exit(1); } p = wait(NULL); rename_directory(path); return true; }
static int ossfs_rename(const char *from, const char *to) { gint res; struct stat stbuf; g_debug("ossfs_rename(from=%s, to=%s)", from, to); res = 0; res = ossfs_getattr(from, &stbuf); if (res) return res; if (S_ISDIR(stbuf.st_mode)) { res = rename_directory(from, to); } else { res = rename_object(from, to); } if (cache_contains((gpointer)from)) { cache_remove((gpointer)from); } if (cache_contains((gpointer)to)) { cache_remove((gpointer)to); } return res; }
/* Examine the directories under directory_name and delete any files that were not there at the time of the back-up. */ static bool try_purge_directory (char const *directory_name) { char *current_dir; char *cur, *arc, *p; char *temp_stub = NULL; struct dumpdir *dump; if (!is_dumpdir (¤t_stat_info)) return false; current_dir = savedir (directory_name); if (!current_dir) /* The directory doesn't exist now. It'll be created. In any case, we don't have to delete any files out of it. */ return false; /* Verify if dump directory is sane */ if (!dumpdir_ok (current_stat_info.dumpdir)) return false; /* Process renames */ for (arc = current_stat_info.dumpdir; *arc; arc += strlen (arc) + 1) { if (*arc == 'X') { #define TEMP_DIR_TEMPLATE "tar.XXXXXX" size_t len = strlen (arc + 1); temp_stub = xrealloc (temp_stub, len + 1 + sizeof TEMP_DIR_TEMPLATE); memcpy (temp_stub, arc + 1, len); temp_stub[len] = '/'; memcpy (temp_stub + len + 1, TEMP_DIR_TEMPLATE, sizeof TEMP_DIR_TEMPLATE); if (!mkdtemp (temp_stub)) { ERROR ((0, errno, _("Cannot create temporary directory using template %s"), quote (temp_stub))); free (temp_stub); free (current_dir); return false; } } else if (*arc == 'R') { char *src, *dst; src = arc + 1; arc += strlen (arc) + 1; dst = arc + 1; /* Ensure that neither source nor destination are absolute file names (unless permitted by -P option), and that they do not contain dubious parts (e.g. ../). This is an extra safety precaution. Besides, it might be necessary to extract from archives created with tar versions prior to 1.19. */ if (*src) src = safer_name_suffix (src, false, absolute_names_option); if (*dst) dst = safer_name_suffix (dst, false, absolute_names_option); if (*src == 0) src = temp_stub; else if (*dst == 0) dst = temp_stub; if (!rename_directory (src, dst)) { free (temp_stub); free (current_dir); /* FIXME: Make sure purge_directory(dst) will return immediately */ return false; } } } free (temp_stub); /* Process deletes */ dump = dumpdir_create (current_stat_info.dumpdir); p = NULL; for (cur = current_dir; *cur; cur += strlen (cur) + 1) { const char *entry; struct stat st; if (p) free (p); p = new_name (directory_name, cur); if (deref_stat (false, p, &st)) { if (errno != ENOENT) /* FIXME: Maybe keep a list of renamed dirs and check it here? */ { stat_diag (p); WARN ((0, 0, _("%s: Not purging directory: unable to stat"), quotearg_colon (p))); } continue; } if (!(entry = dumpdir_locate (dump, cur)) || (*entry == 'D' && !S_ISDIR (st.st_mode)) || (*entry == 'Y' && S_ISDIR (st.st_mode))) { if (one_file_system_option && st.st_dev != root_device) { WARN ((0, 0, _("%s: directory is on a different device: not purging"), quotearg_colon (p))); continue; } if (! interactive_option || confirm ("delete", p)) { if (verbose_option) fprintf (stdlis, _("%s: Deleting %s\n"), program_name, quote (p)); if (! remove_any_file (p, RECURSIVE_REMOVE_OPTION)) { int e = errno; ERROR ((0, e, _("%s: Cannot remove"), quotearg_colon (p))); } } } } free (p); dumpdir_free (dump); free (current_dir); return true; }