本文整理汇总了C++中do_rename函数的典型用法代码示例。如果您正苦于以下问题:C++ do_rename函数的具体用法?C++ do_rename怎么用?C++ do_rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_rename函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: recover_finishing
static int recover_finishing(struct async *as,
struct sdirs *sdirs, struct conf **cconfs)
{
int r;
char msg[128]="";
struct asfd *asfd=as->asfd;
logp("Found finishing symlink - attempting to complete prior backup!\n");
snprintf(msg, sizeof(msg),
"Now finalising previous backup of client. "
"Please try again later.");
asfd->write_str(asfd, CMD_ERROR, msg);
// Do not need the client connected any more.
// Disconnect.
logp("Disconnect from client.\n");
as->asfd_remove(as, asfd);
asfd_close(asfd);
switch(get_protocol(cconfs))
{
case PROTO_1:
r=backup_phase4_server_protocol1(sdirs, cconfs);
break;
case PROTO_2:
default:
r=backup_phase4_server_protocol2(sdirs, cconfs);
break;
}
if(r)
{
logp("Problem with prior backup. Please check the client log on the server.");
return -1;
}
logp("Prior backup completed OK.\n");
// Move the symlink to indicate that we are now in the end
// phase.
// FIX THIS: Check whether the rename race condition is recoverable
// here.
if(do_rename(sdirs->finishing, sdirs->current)) return -1;
return 0;
}
开发者ID:ZungBang,项目名称:burp,代码行数:43,代码来源:rubble.c
示例2: do_rename_w
static int do_rename_w(const char *a, const char *b,
const char *cname, struct bu *bu)
{
int ret=-1;
char *target=NULL;
char new_name[256]="";
snprintf(new_name, sizeof(new_name), "%s-%s", cname, bu->basename);
if(!(target=prepend_s(b, new_name))
|| build_path_w(target))
goto end;
if(do_rename(a, target))
{
logp("Error when trying to rename for delete %s\n", a);
goto end;
}
ret=0;
end:
free_w(&target);
return ret;
}
开发者ID:ZungBang,项目名称:burp,代码行数:20,代码来源:delete.c
示例3: make_backup
int make_backup(char *fname)
{
char fnamebak[MAXPATHLEN];
if (strlen(fname) + strlen(backup_suffix) > (MAXPATHLEN-1)) {
rprintf(FERROR,"backup filename too long\n");
return 0;
}
slprintf(fnamebak,sizeof(fnamebak),"%s%s",fname,backup_suffix);
if (do_rename(fname,fnamebak) != 0) {
/* cygwin (at least version b19) reports EINVAL */
if (errno != ENOENT && errno != EINVAL) {
rprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
return 0;
}
} else if (verbose > 1) {
rprintf(FINFO,"backed up %s to %s\n",fname,fnamebak);
}
return 1;
}
开发者ID:AkankshaGovil,项目名称:Automation,代码行数:20,代码来源:rsync.c
示例4: main
int main(int argc, char *argv[])
{
char *init_cwd;
pid_t pid;
int status;
int ret = 1;
if (argc != 2) {
printf("Usage: %s <dir>\n", argv[0]);
exit(1);
}
init_cwd = argv[1];
ret = chdir(init_cwd);
if (ret < 0) {
perror("chdir failed");
exit(1);
}
if (signal(SIGALRM, sigproc) == SIG_ERR) {
perror("signal failed");
exit(1);
}
alarm(TIMEOUT);
pid = fork();
if (pid < 0) {
perror("fork failed");
exit(1);
} else if (pid == 0) {
do_rename("t_getcwd_testfile");
} else {
ret = test_getcwd(init_cwd);
kill(pid, SIGTERM);
waitpid(pid, &status, 0);
}
exit(ret);
}
开发者ID:Andiry,项目名称:xfstests,代码行数:40,代码来源:t_getcwd.c
示例5: do_hardlink
/* Make it atomic by linking to a temporary file, then moving it into place. */
static int do_hardlink(struct file *o, struct file *n, const char *ext)
{
int ret=-1;
char *tmppath=NULL;
if(!(tmppath=prepend(o->path, ext, "")))
{
log_out_of_memory(__func__);
goto end;
}
if(link(n->path, tmppath))
{
logp("Could not hardlink %s to %s: %s\n", tmppath, n->path,
strerror(errno));
goto end;
}
if((ret=do_rename(tmppath, o->path)))
goto end;
ret=0;
end:
free_w(&tmppath);
return ret;
}
开发者ID:kaptk2,项目名称:burp,代码行数:23,代码来源:bedup.c
示例6: do_hardlink
/* Make it atomic by linking to a temporary file, then moving it into place. */
static int do_hardlink(struct file *o, struct file *n, const char *ext)
{
char *tmppath=NULL;
if(!(tmppath=prepend(o->path, ext, "")))
{
logp("out of memory\n");
return -1;
}
if(link(n->path, tmppath))
{
logp("Could not hardlink %s to %s: %s\n", tmppath, n->path,
strerror(errno));
free(tmppath);
return -1;
}
if(do_rename(tmppath, o->path))
{
free(tmppath);
return -1;
}
free(tmppath);
return 0;
}
开发者ID:tcheneau,项目名称:burp,代码行数:24,代码来源:bedup.c
示例7: merge_into_global_sparse
static int merge_into_global_sparse(const char *sparse, const char *global,
struct conf **confs)
{
int ret=-1;
char *tmpfile=NULL;
struct stat statp;
char *lockfile=NULL;
struct lock *lock=NULL;
const char *globalsrc=NULL;
if(!(tmpfile=prepend_n(global, "tmp", strlen("tmp"), ".")))
goto end;
// Get a lock before messing with the global sparse index.
if(!(lockfile=prepend_n(global, "lock", strlen("lock"), "."))
|| !(lock=lock_alloc_and_init(lockfile)))
goto end;
if(try_to_get_lock(lock)) goto end;
if(!lstat(global, &statp)) globalsrc=global;
if(merge_sparse_indexes(sparse, globalsrc, tmpfile, confs))
goto end;
// FIX THIS: nasty race condition needs to be recoverable.
if(do_rename(tmpfile, global)) goto end;
ret=0;
end:
lock_release(lock);
lock_free(&lock);
if(lockfile) free(lockfile);
if(tmpfile) free(tmpfile);
return ret;
}
开发者ID:adrianimboden,项目名称:burp,代码行数:36,代码来源:backup_phase4.c
示例8: compress_file
int compress_file(const char *src, const char *dst, struct config *cconf)
{
char *dsttmp=NULL;
pid_t pid=getpid();
char p[12]="";
snprintf(p, sizeof(p), "%d", (int)pid);
if(!(dsttmp=prepend(dst, p, strlen(p), 0 /* no slash */)))
return -1;
// Need to compress the log.
logp("Compressing %s to %s...\n", src, dst);
if(compress(src, dsttmp, cconf)
|| do_rename(dsttmp, dst))
{
unlink(dsttmp);
free(dsttmp);
return -1;
}
// succeeded - get rid of the uncompressed version
unlink(src);
free(dsttmp);
return 0;
}
开发者ID:barroque,项目名称:burp,代码行数:24,代码来源:current_backups_server.c
示例9: main
int
main(int argc, char **argv)
{
int a;
if (argc == 1)
{
printf("usage: %s file [file ...]\n", argv[0]);
exit(1);
}
for (a = 1;a < argc;a++)
{
if (strcmp("-v", argv[a]) == 0)
{
_verbose++;
continue;
}
do_rename(argv[a]);
}
return 0;
}
开发者ID:lipro,项目名称:kcemu,代码行数:24,代码来源:tape-rename.c
示例10: main
int main(void)
{
char dir_src[PATH_MAX];
char dir_dst[PATH_MAX];
EXPECT_ZERO(get_tempdir(dir_src, PATH_MAX, 0755));
EXPECT_ZERO(register_tempdir_for_cleanup(dir_src));
EXPECT_ZERO(get_tempdir(dir_dst, PATH_MAX, 0755));
EXPECT_ZERO(register_tempdir_for_cleanup(dir_dst));
/* test rename /src/a -> /dst/m, a as file, m as file */
EXPECT_ZERO(do_touch2(dir_src, "a"));
EXPECT_ZERO(do_touch2(dir_dst, "m"));
EXPECT_ZERO(do_rename(dir_src, "a", dir_dst, "m"));
/* test rename /src/b -> /dst/n, b as file, n as dir */
EXPECT_ZERO(do_touch2(dir_src, "b"));
EXPECT_ZERO(do_test_mkdir(dir_dst, "n"));
EXPECT_EQ(do_rename(dir_src, "b", dir_dst, "n"), -EISDIR);
/* test rename /src/c -> /dst/o, c as dir, o as file */
EXPECT_ZERO(do_test_mkdir(dir_src, "c"));
EXPECT_ZERO(do_touch2(dir_dst, "o"));
EXPECT_EQ(do_rename(dir_src, "c", dir_dst, "o"), -ENOTDIR);
/* test rename /src/d -> /dst/p, d as dir, p as dir */
EXPECT_ZERO(do_test_mkdir(dir_src, "d"));
EXPECT_ZERO(do_test_mkdir(dir_dst, "p"));
EXPECT_ZERO(do_rename(dir_src, "d", dir_dst, "p"));
/* test rename /src/e -> /dst/q, e as file, q as nonexistent */
EXPECT_ZERO(do_touch2(dir_src, "e"));
EXPECT_ZERO(do_rename(dir_src, "e", dir_dst, "q"));
/* test rename /src/f -> /dst/r, f as dir, r as nonexistent */
EXPECT_ZERO(do_test_mkdir(dir_src, "f"));
EXPECT_ZERO(do_rename(dir_src, "f", dir_dst, "r"));
return 0;
}
开发者ID:cmccabe,项目名称:redfish,代码行数:40,代码来源:posix_rename_test.c
示例11: ca_client_setup
/* Return 1 for everything OK, signed and returned, -1 for error, 0 for
nothing done. */
int ca_client_setup(struct config *conf, struct cntr *p1cntr)
{
char cmd;
int ret=-1;
size_t len=0;
char *buf=NULL;
char csr_path[256]="";
char ssl_cert_tmp[512]="";
char ssl_cert_ca_tmp[512]="";
struct stat statp;
// Do not continue if we have none of the following things set.
if( !conf->ca_burp_ca
|| !conf->ca_csr_dir
|| !conf->ssl_cert_ca
|| !conf->ssl_cert
|| !conf->ssl_key
// Do not try to get a new certificate if we already have a
// key.
|| !lstat(conf->ssl_key, &statp))
{
if(async_write_str(CMD_GEN, "nocsr")
|| async_read_expect(CMD_GEN, "nocsr ok"))
{
logp("problem reading from server nocsr\n");
return -1;
}
logp("nocsr ok\n");
return 0;
}
// Tell the server we want to do a signing request.
if(async_write_str(CMD_GEN, "csr"))
return -1;
if(async_rw_ensure_read(&cmd, &buf, &len, '\0', NULL, 0))
{
logp("problem reading from server csr\n");
goto end;
}
if(cmd!=CMD_GEN || strncmp(buf, "csr ok:", strlen("csr ok:")))
{
logp("unexpected command from server: %c:%s\n", cmd, buf);
goto end;
}
// The server appends its name after 'csr ok:'
if(conf->ssl_peer_cn) free(conf->ssl_peer_cn);
if(!(conf->ssl_peer_cn=strdup(buf+strlen("csr ok:"))))
{
logp("out of memory\n");
goto end;
}
logp("Server will sign a certificate request\n");
// First need to generate a client key and a certificate signing
// request.
snprintf(csr_path, sizeof(csr_path), "%s/%s.csr",
conf->ca_csr_dir, conf->cname);
if(generate_key_and_csr(conf, csr_path)) goto end;
// Then copy the csr to the server.
if(send_a_file(csr_path, p1cntr)) goto end;
snprintf(ssl_cert_tmp, sizeof(ssl_cert_tmp), "%s.%d",
conf->ssl_cert, getpid());
snprintf(ssl_cert_ca_tmp, sizeof(ssl_cert_ca_tmp), "%s.%d",
conf->ssl_cert_ca, getpid());
// The server will then sign it, and give it back.
if(receive_a_file(ssl_cert_tmp, p1cntr)) goto end;
// The server will also send the CA certificate.
if(receive_a_file(ssl_cert_ca_tmp, p1cntr)) goto end;
if(do_rename(ssl_cert_tmp, conf->ssl_cert)
|| do_rename(ssl_cert_ca_tmp, conf->ssl_cert_ca))
goto end;
// Need to rewrite our configuration file to contain the server
// name (ssl_peer_cn)
if(rewrite_client_conf(conf)) goto end;
// My goodness, everything seems to have gone OK. Stand back!
ret=1;
end:
if(buf) free(buf);
if(ret<0)
{
// On error, remove any possibly newly created files, so that
// this function might run again on another go.
unlink(csr_path);
unlink(conf->ssl_key);
unlink(conf->ssl_cert);
unlink(conf->ssl_cert_ca);
unlink(ssl_cert_tmp);
unlink(ssl_cert_ca_tmp);
}
//.........这里部分代码省略.........
开发者ID:goneri,项目名称:burp,代码行数:101,代码来源:ca_client.c
示例12: backup_phase3_server_all
//.........这里部分代码省略.........
{
switch(manio_read(chmanio, csb))
{
case -1: goto end;
case 1: manio_close(&chmanio);
}
}
if(usb->path.buf && !csb->path.buf)
{
if(write_status(CNTR_STATUS_MERGING,
usb->path.buf, cntr)) goto end;
switch(manio_copy_entry(
usb, usb, &blk, unmanio, newmanio))
{
case -1: goto end;
case 1: manio_close(&unmanio);
}
}
else if(!usb->path.buf && csb->path.buf)
{
if(write_status(CNTR_STATUS_MERGING,
csb->path.buf, cntr)) goto end;
switch(manio_copy_entry(
csb, csb, &blk, chmanio, newmanio))
{
case -1: goto end;
case 1: manio_close(&chmanio);
}
}
else if(!usb->path.buf && !csb->path.buf)
{
continue;
}
else if(!(pcmp=sbuf_pathcmp(usb, csb)))
{
// They were the same - write one.
if(write_status(CNTR_STATUS_MERGING,
csb->path.buf, cntr)) goto end;
switch(manio_copy_entry(
csb, csb, &blk, chmanio, newmanio))
{
case -1: goto end;
case 1: manio_close(&chmanio);
}
}
else if(pcmp<0)
{
if(write_status(CNTR_STATUS_MERGING,
usb->path.buf, cntr)) goto end;
switch(manio_copy_entry(
usb, usb, &blk, unmanio, newmanio))
{
case -1: goto end;
case 1: manio_close(&unmanio);
}
}
else
{
if(write_status(CNTR_STATUS_MERGING,
csb->path.buf, cntr)) goto end;
switch(manio_copy_entry(
csb, csb, &blk, chmanio, newmanio))
{
case -1: goto end;
case 1: manio_close(&chmanio);
}
}
}
// Flush to disk.
if(manio_close(&newmanio))
{
logp("error gzclosing %s in backup_phase3_server\n",
manifesttmp);
goto end;
}
// Rename race condition should be of no consequence here, as the
// manifest should just get recreated automatically.
if(do_rename(manifesttmp, sdirs->manifest))
goto end;
else
{
recursive_delete(sdirs->changed);
recursive_delete(sdirs->unchanged);
}
logp("End phase3 (merge manifests)\n");
ret=0;
end:
manio_close(&newmanio);
manio_close(&chmanio);
manio_close(&unmanio);
sbuf_free(&csb);
sbuf_free(&usb);
blk_free(&blk);
free_w(&manifesttmp);
return ret;
}
开发者ID:Lacoste,项目名称:burp,代码行数:101,代码来源:backup_phase3.c
示例13: backup_phase3_server_protocol2
//.........这里部分代码省略.........
&& csb
&& !csb->path.buf)
{
switch(manio_sbuf_fill(chmanio, NULL /* no async */,
csb, NULL, NULL, confs))
{
case -1: goto end;
case 1: finished_ch++;
}
}
if((usb && usb->path.buf) && (!csb || !csb->path.buf))
{
switch(manio_copy_entry(NULL /* no async */,
&usb, usb,
&blk, unmanio, newmanio, confs))
{
case -1: goto end;
case 1: finished_un++;
}
}
else if((!usb || !usb->path.buf) && (csb && csb->path.buf))
{
switch(manio_copy_entry(NULL /* no async */,
&csb, csb, &blk, chmanio, newmanio, confs))
{
case -1: goto end;
case 1: finished_ch++;
}
}
else if((!usb || !usb->path.buf) && (!csb || !(csb->path.buf)))
{
continue;
}
else if(!(pcmp=sbuf_pathcmp(usb, csb)))
{
// They were the same - write one.
switch(manio_copy_entry(NULL /* no async */,
&csb, csb, &blk, chmanio, newmanio, confs))
{
case -1: goto end;
case 1: finished_ch++;
}
}
else if(pcmp<0)
{
switch(manio_copy_entry(NULL /* no async */,
&usb, usb, &blk, unmanio, newmanio, confs))
{
case -1: goto end;
case 1: finished_un++;
}
}
else
{
switch(manio_copy_entry(NULL /* no async */,
&csb, csb, &blk, chmanio, newmanio, confs))
{
case -1: goto end;
case 1: finished_ch++;
}
}
}
fcount=newmanio->fcount;
// Flush to disk and set up for reading.
if(manio_free(&newmanio)
|| !(newmanio=manio_alloc())
|| manio_init_read(newmanio, sdirs->rmanifest))
goto end;
// Rename race condition should be of no consequence here, as the
// manifest should just get recreated automatically.
if(do_rename(manifesttmp, sdirs->rmanifest))
goto end;
else
{
recursive_delete(sdirs->changed, NULL, 1);
recursive_delete(sdirs->unchanged, NULL, 1);
}
if(sparse_generation(newmanio, fcount, sdirs, confs))
goto end;
ret=0;
logp("End phase3\n");
end:
manio_free(&newmanio);
manio_free(&chmanio);
manio_free(&unmanio);
sbuf_free(&csb);
sbuf_free(&usb);
blk_free(&blk);
free_w(&hooksdir);
free_w(&dindexdir);
free_w(&manifesttmp);
return ret;
}
开发者ID:kaptk2,项目名称:burp,代码行数:101,代码来源:backup_phase3.c
示例14: newwin
//.........这里部分代码省略.........
for (int i = 0; i < FULL_SCREEN_HEIGHT; i++)
{
mvwputch(w_grid, i, winx2, c_ltgray, i == winy1 || i == winy2-1? LINE_XOXX : LINE_XOXO);
if (i >= winy1 && i < winy2) {
mvwputch(w_grid, i, winx1, c_ltgray, LINE_XOXO);
}
}
for (int i = 0; i < FULL_SCREEN_WIDTH; i++)
{
mvwputch(w_grid, winy1, i, c_ltgray,
i == winx1? LINE_OXXX : (i == winx2? LINE_OXXX : LINE_OXOX));
if (i < winx2) {
mvwputch(w_grid, winy2-1, i, c_ltgray, i == winx1? LINE_XXOX : LINE_OXOX);
}
}
wrefresh(w_grid);
crafting_inv = gm->crafting_inventory(&gm->u);
int charges = static_cast<it_tool *>(g->itypes["welder"])->charges_per_use;
int charges_crude = static_cast<it_tool *>(g->itypes["welder_crude"])->charges_per_use;
has_wrench = crafting_inv.has_amount("wrench", 1) ||
crafting_inv.has_amount("toolset", 1);
has_hacksaw = crafting_inv.has_amount("hacksaw", 1) ||
crafting_inv.has_amount("toolset", 1);
has_welder = (crafting_inv.has_amount("welder", 1) &&
crafting_inv.has_charges("welder", charges)) ||
(crafting_inv.has_amount("welder_crude", 1) &&
crafting_inv.has_charges("welder_crude", charges_crude)) ||
(crafting_inv.has_amount("toolset", 1) &&
crafting_inv.has_charges("toolset", charges/20));
has_jack = crafting_inv.has_amount("jack", 1);
has_siphon = crafting_inv.has_amount("hose", 1);
has_wheel = crafting_inv.has_amount( "wheel", 1 ) ||
crafting_inv.has_amount( "wheel_wide", 1 ) ||
crafting_inv.has_amount( "wheel_bicycle", 1 ) ||
crafting_inv.has_amount( "wheel_motorbike", 1 ) ||
crafting_inv.has_amount( "wheel_small", 1 );
display_stats ();
display_veh ();
move_cursor (0, 0);
bool finish = false;
while (!finish)
{
char ch = input(); // See keypress.h
int dx, dy;
get_direction (dx, dy, ch);
if (ch == KEY_ESCAPE || ch == 'q' )
{
finish = true;
}
else
{
if (dx != -2 && (dx || dy) &&
cursor_x + dx >= -6 && cursor_x + dx < 6 &&
cursor_y + dy >= -6 && cursor_y + dy < 6)
{
move_cursor(dx, dy);
}
else
{
int mval = cant_do(ch);
display_mode (ch);
switch (ch)
{
case 'i': do_install(mval); break;
case 'r': do_repair(mval); break;
case 'f': do_refill(mval); break;
case 'o': do_remove(mval); break;
case 'e': do_rename(mval); break;
case 's': do_siphon(mval); break;
case 'c': do_tirechange(mval); break;
case 'd': do_drain(mval); break;
}
if (sel_cmd != ' ')
{
finish = true;
}
display_mode (' ');
}
}
}
werase(w_grid);
werase(w_mode);
werase(w_msg);
werase(w_disp);
werase(w_parts);
werase(w_stats);
werase(w_list);
delwin(w_grid);
delwin(w_mode);
delwin(w_msg);
delwin(w_disp);
delwin(w_parts);
delwin(w_stats);
delwin(w_list);
erase();
}
开发者ID:jesusmod,项目名称:Cataclysm-DDA,代码行数:101,代码来源:veh_interact.cpp
示例15: backup_phase4_server_protocol2
int backup_phase4_server_protocol2(struct sdirs *sdirs, struct conf **confs)
{
int ret=-1;
uint64_t i=0;
uint64_t pass=0;
char *sparse=NULL;
char *global_sparse=NULL;
char *h1dir=NULL;
char *h2dir=NULL;
char *hooksdir=NULL;
char *srca=NULL;
char *srcb=NULL;
char *dst=NULL;
char compa[32]="";
char compb[32]="";
char compd[32]="";
struct manio *newmanio=NULL;
char *logpath=NULL;
char *fmanifest=NULL; // FIX THIS: should be part of sdirs.
if(!(logpath=prepend_s(sdirs->finishing, "log")))
goto end;
if(set_logfp(logpath, confs))
goto end;
logp("Begin phase4 (sparse generation)\n");
if(!(newmanio=manio_alloc())
|| !(fmanifest=prepend_s(sdirs->finishing, "manifest"))
|| manio_init_read(newmanio, fmanifest)
|| manio_read_fcount(newmanio)
|| !(hooksdir=prepend_s(fmanifest, "hooks"))
|| !(h1dir=prepend_s(fmanifest, "h1"))
|| !(h2dir=prepend_s(fmanifest, "h2")))
goto end;
while(1)
{
char *srcdir=NULL;
char *dstdir=NULL;
if(!pass)
{
srcdir=hooksdir;
dstdir=h1dir;
}
else if(pass%2)
{
srcdir=h1dir;
dstdir=h2dir;
}
else
{
srcdir=h2dir;
dstdir=h1dir;
}
pass++;
for(i=0; i<newmanio->offset.fcount; i+=2)
{
free_w(&srca);
free_w(&srcb);
free_w(&dst);
snprintf(compa, sizeof(compa), "%08"PRIX64, i);
snprintf(compb, sizeof(compb), "%08"PRIX64, i+1);
snprintf(compd, sizeof(compd), "%08"PRIX64, i/2);
if(!(srca=prepend_s(srcdir, compa))
|| !(dst=prepend_s(dstdir, compd)))
goto end;
if(i+1<newmanio->offset.fcount
&& !(srcb=prepend_s(srcdir, compb)))
goto end;
if(merge_sparse_indexes(srca, srcb, dst, confs))
goto end;
}
if((newmanio->offset.fcount=i/2)<2) break;
}
if(!(sparse=prepend_s(fmanifest, "sparse"))
|| !(global_sparse=prepend_s(sdirs->data, "sparse")))
goto end;
// FIX THIS: nasty race condition here needs to be automatically
// recoverable.
if(do_rename(dst, sparse)) goto end;
if(merge_into_global_sparse(sparse, global_sparse, confs)) goto end;
logp("End phase4 (sparse generation)\n");
ret=0;
end:
manio_free(&newmanio);
free_w(&sparse);
free_w(&global_sparse);
free_w(&srca);
free_w(&srcb);
recursive_delete(h1dir, NULL, 1);
recursive_delete(h2dir, NULL, 1);
free_w(&h1dir);
free_w(&h2dir);
free_w(&logpath);
//.........这里部分代码省略.........
开发者ID:adrianimboden,项目名称:burp,代码行数:101,代码来源:backup_phase4.c
示例16: atomic_data_jiggle
/* Need to make all the stuff that this does atomic so that existing backups
never get broken, even if somebody turns the power off on the server. */
static int atomic_data_jiggle(struct sdirs *sdirs, struct fdirs *fdirs,
int hardlinked_current, struct conf *cconf, unsigned long bno)
{
int ars=0;
int ret=-1;
char *datapth=NULL;
char *tmpman=NULL;
struct stat statp;
char *deltabdir=NULL;
char *deltafdir=NULL;
char *sigpath=NULL;
gzFile zp=NULL;
struct sbuf *sb=NULL;
FILE *delfp=NULL;
logp("Doing the atomic data jiggle...\n");
if(!(tmpman=get_tmp_filename(fdirs->manifest)))
goto end;
if(lstat(fdirs->manifest, &statp))
{
// Manifest does not exist - maybe the server was killed before
// it could be renamed.
logp("%s did not exist - trying %s\n", fdirs->manifest, tmpman);
// Rename race condition is of no consequence, because manifest
// already does not exist.
do_rename(tmpman, fdirs->manifest);
}
if(!(zp=gzopen_file(fdirs->manifest, "rb")))
goto end;
if(!(deltabdir=prepend_s(fdirs->currentdup, "deltas.reverse"))
|| !(deltafdir=prepend_s(sdirs->finishing, "deltas.forward"))
|| !(sigpath=prepend_s(fdirs->currentdup, "sig.tmp"))
|| !(sb=sbuf_alloc(cconf)))
{
log_out_of_memory(__func__);
goto end;
}
mkdir(fdirs->datadir, 0777);
while(!(ars=sbufl_fill(sb, NULL, NULL, zp, cconf->cntr)))
{
if(sb->burp1->datapth.buf)
{
if(write_status(STATUS_SHUFFLING,
sb->burp1->datapth.buf, cconf)) goto end;
if((ret=jiggle(sdirs, fdirs, sb, hardlinked_current,
deltabdir, deltafdir,
sigpath, &delfp, cconf))) goto end;
}
sbuf_free_content(sb);
}
if(ars<0) goto end;
if(close_fp(&delfp))
{
logp("error closing %s in atomic_data_jiggle\n",
fdirs->deletionsfile);
goto end;
}
if(maybe_delete_files_from_manifest(tmpman, fdirs, cconf))
goto end;
// Remove the temporary data directory, we have probably removed
// useful files from it.
sync(); // try to help CIFS
recursive_delete(deltafdir, NULL, 0 /* do not del files */);
end:
gzclose_fp(&zp);
close_fp(&delfp);
sbuf_free(&sb);
free_w(&deltabdir);
free_w(&deltafdir);
free_w(&sigpath);
free_w(&datapth);
free_w(&tmpman);
return ret;
}
开发者ID:Sherlock221B,项目名称:burp,代码行数:87,代码来源:backup_phase4.c
示例17: backup_phase4_server_burp1
int backup_phase4_server_burp1(struct sdirs *sdirs, struct conf *cconf)
{
int ret=-1;
struct stat statp;
ssize_t len=0;
char realcurrent[256]="";
unsigned long bno=0;
int hardlinked_current=0;
char tstmp[64]="";
int previous_backup=0;
struct fdirs *fdirs=NULL;
if((len=readlink(sdirs->current, realcurrent, sizeof(realcurrent)-1))<0)
len=0;
realcurrent[len]='\0';
if(!(fdirs=fdirs_alloc())
|| fdirs_init(fdirs, sdirs, realcurrent))
goto end;
if(set_logfp(fdirs->logpath, cconf))
goto end;
logp("Begin phase4 (shuffle files)\n");
if(write_status(STATUS_SHUFFLING, NULL, cconf))
goto end;
if(!lstat(sdirs->current, &statp)) // Had a previous backup.
{
previous_backup++;
if(lstat(fdirs->hlinkedcurrent, &statp))
{
hardlinked_current=0;
logp("Previous backup is not a hardlinked_archive\n");
logp(" will generate reverse deltas\n");
}
else
{
hardlinked_current=1;
logp("Previous backup is a hardlinked_archive\n");
logp(" will not generate reverse deltas\n");
}
// If current was not a hardlinked_archive, need to duplicate
// it.
if(!hardlinked_current && lstat(fdirs->currentdup, &statp))
{
// Have not duplicated the current backup yet.
if(!lstat(fdirs->currentduptmp, &statp))
{
logp("Removing previous directory: %s\n",
fdirs->currentduptmp);
if(recursive_delete(fdirs->currentduptmp,
NULL, 1 /* del files */))
{
logp("Could not delete %s\n",
fdirs->currentduptmp);
goto end;
}
}
logp("Duplicating current backup.\n");
if(recursive_hardlink(sdirs->current,
fdirs->currentduptmp, cconf)
// The rename race condition is of no consequence here
// because currentdup does not exist.
|| do_rename(fdirs->currentduptmp, fdirs->currentdup))
goto end;
}
}
if(timestamp_read(fdirs->timestamp, tstmp, sizeof(tstmp)))
{
logp("could not read timestamp file: %s\n",
fdirs->timestamp);
goto end;
}
// Get the backup number.
bno=strtoul(tstmp, NULL, 10);
// Determine whether the new backup should be a hardlinked
// archive or not, from the conf and the backup number...
if(need_hardlinked_archive(cconf, bno))
{
// Create a file to indicate that the previous backup
// does not have others depending on it.
FILE *hfp=NULL;
if(!(hfp=open_file(fdirs->hlinked, "wb"))) goto end;
// Stick the next backup timestamp in it. It might
// be useful one day when wondering when the next
// backup, now deleted, was made.
fprintf(hfp, "%s\n", tstmp);
if(close_fp(&hfp))
{
logp("error closing hardlinked indication\n");
goto end;
}
}
//.........这里部分代码省略.........
开发者ID:Sherlock221B,项目名称:burp,代码行数:101,代码来源:backup_phase4.c
示例18: maybe_delete_files_from_manifest
static int maybe_delete_files_from_manifest(const char *manifesttmp,
struct fdirs *fdirs, struct conf *cconf)
{
int ars=0;
int ret=-1;
int pcmp=0;
FILE *dfp=NULL;
gzFile nmzp=NULL;
gzFile omzp=NULL;
struct sbuf *db=NULL;
struct sbuf *mb=NULL;
struct stat statp;
if(lstat(fdirs->deletionsfile, &statp)) // No deletions, no problem.
return 0;
logp("Performing deletions on manifest\n");
if(!(manifesttmp=get_tmp_filename(fdirs->manifest)))
goto end;
if(!(dfp=open_file(fdirs->deletionsfile, "rb"))
|| !(omzp=gzopen_file(fdirs->manifest, "rb"))
|| !(nmzp=gzopen_file(manifesttmp, comp_level(cconf)))
|| !(db=sbuf_alloc(cconf))
|| !(mb=sbuf_alloc(cconf)))
goto end;
while(omzp || dfp)
{
if(dfp && !db->path.buf
&& (ars=sbufl_fill(db, NULL, dfp, NULL, cconf->cntr)))
{
if(ars<0) goto end;
// ars==1 means it ended ok.
close_fp(&dfp);
}
if(omzp && !mb->path.buf
&& (ars=sbufl_fill(mb, NULL, NULL, omzp, cconf->cntr)))
{
if(ars<0) goto end;
// ars==1 means it ended ok.
gzclose_fp(&omzp);
}
if(mb->path.buf && !db->path.buf)
{
if(sbufl_to_manifest(mb, NULL, nmzp)) goto end;
sbuf_free_content(mb);
}
else if(!mb->path.buf && db->path.buf)
{
sbuf_free_content(db);
}
else if(!mb->path.buf && !db->path.buf)
{
continue;
}
else if(!(pcmp=sbuf_pathcmp(mb, db)))
{
// They were the same - do not write.
sbuf_free_content(mb);
sbuf_free_content(db);
}
else if(pcmp<0)
{
// Behind in manifest. Write.
if(sbufl_to_manifest(mb, NULL, nmzp)) goto end;
sbuf_free_content(mb);
}
else
{
// Behind in deletions file. Do not write.
sbuf_free_content(db);
}
}
ret=0;
end:
if(gzclose_fp(&nmzp))
{
logp("error closing %s in %s\n", manifesttmp, __func__);
ret=-1;
}
close_fp(&dfp);
gzclose_fp(&omzp);
sbuf_free(&db);
sbuf_free(&mb);
if(!ret)
{
unlink(fdirs->deletionsfile);
// The rename race condition is not a problem here, as long
// as manifesttmp is the same path as that generated in the
// atomic data jiggle.
if(do_rename(manifesttmp, fdirs->manifest))
return -1;
}
if(manifesttmp) unlink(manifesttmp);
return ret;
}
开发者ID:Sherlock221B,项目名称:burp,代码行数:100,代码来源:backup_phase4.c
示例19: dbg
void *extra_self_tests(int arg1, void *arg2)
{
/* creating /test1/test2/ directories */
dbg(DBG_ERROR | DBG_VFS,"TEST: Creating directories\n");
do_mkdir("dir");
do_mkdir("dir/dir1");
do_mkdir("dir/dir2");
do_mkdir("dir/dir3");
do_mkdir("dir/dir4");
dbg(DBG_ERROR | DBG_VFS,"TEST: Directories are created\n");
int fd;
char *file2buf="File 2 write only test case";
char *file1buf="Testing file_1 for write operation";
char readbuf[150];
dbg(DBG_ERROR | DBG_VFS,"TEST: Change directory to dir/dir1\n");
do_chdir("dir/dir1");
/* file1.txt creation with O_CREAT|O_WRONLY flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Create file1.txt with O_CREAT|O_WRONLY flag in directory dir/dir1\n");
fd = do_open("file1.txt", O_CREAT|O_WRONLY);
do_write(fd, file1buf, strlen(file1buf));
do_close(fd);
/* file2.txt creation with O_CREAT|O_RDONLY flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Change directory to dir/dir2\n");
do_chdir("/dir/dir2");
dbg(DBG_ERROR | DBG_VFS,"TEST: Create file2.txt with O_CREAT | O_RDONLY flag in directory dir/dir2\n");
fd = do_open("file2.txt", O_CREAT | O_RDONLY);
do_close(fd);
/* Write into file2.txt using O_WRONLY flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Write into file2.txt with O_WRONLY flag in directory dir/dir2\n");
fd = do_open("file2.txt", O_WRONLY);
do_write(fd, file2buf, strlen(file2buf));
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: written chars: \"%s\" in file2.txt\n",file2buf);
char *appendbuf=" Appending for O_WRONLY|O_APPEND mode";
/* Append into file2.txt using O_WRONLY|O_APPEND flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Append into file2.txt with O_WRONLY|O_APPEND flag in directory dir/dir2\n");
fd = do_open("file2.txt", O_WRONLY|O_APPEND);
do_write(fd, appendbuf, strlen(appendbuf));
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: Appending chars: \"%s\" in file2.txt\n",appendbuf);
fd = do_open("file2.txt", O_RDONLY);
memset(readbuf,0,sizeof(char)*150);
do_read(fd,readbuf,strlen(file2buf)+strlen(appendbuf));
dbg(DBG_ERROR | DBG_VFS,"TEST: After Appending text in file2.txt is: \"%s\" \n",readbuf);
char *append2buf=" Appending for O_RDWR|O_APPEND mode in file2";
/* Append into file2.txt using O_RDWR|O_APPEND flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Append into file2.txt with O_RDWR|O_APPEND flag in directory dir/dir2\n");
fd = do_open("file2.txt", O_RDWR|O_APPEND);
do_write(fd, append2buf, strlen(append2buf));
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: Appending chars: \"%s\" in file2.txt\n",append2buf);
fd = do_open("file2.txt", O_RDONLY);
memset(readbuf,0,sizeof(char)*150);
do_read(fd,readbuf,strlen(file2buf)+strlen(append2buf)+strlen(appendbuf));
dbg(DBG_ERROR | DBG_VFS,"TEST: After Appending text in file2.txt is: \"%s\" \n",readbuf);
dbg(DBG_ERROR | DBG_VFS,"TEST:Linking Source directory => /dir/dir2, Destination directory => /dir/linkofdir2 \n");
do_chdir("/");
do_link("dir/dir2","dir/linkofdir2");
dbg(DBG_ERROR | DBG_VFS,"TEST:Linking Source file => /dir/dir1/file1.txt, to the Destination => /dir/linkoffile1 \n");
do_link("dir/dir1/file1.txt","dir/linkoffile1");
dbg(DBG_ERROR | DBG_VFS,"TEST: Renaming directory from dir/dir3 to dir/renamed \n");
do_rename("dir/dir3","dir/renameddir3");
dbg(DBG_ERROR | DBG_VFS,"TEST: Renaming file from dir/dir1/file1.txt to dir/dir1/renamedfile1.txt \n");
do_rename("dir/dir1/file1.txt","dir/dir1/renamedfile1.txt");
dbg(DBG_ERROR | DBG_VFS,"TEST: Removing directory dir/dir4 \n");
do_rmdir("dir/dir4");
dbg(DBG_ERROR | DBG_VFS,"TEST: reading 18 chars from file: /dir/linkoffile2 which is hard link of /dir/dir2/file2.txt \n");
fd = do_open("dir/linkoffile2", O_RDONLY);
memset(readbuf,0,sizeof(char)*150);
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: read 18 chars: \"%s\" from file: /dir/linkoffile1\n",readbuf);
dbg(DBG_ERROR | DBG_VFS,"TEST: reading file using lseek function on /dir/linkoffile2 which is hard link of /dir/dir2/file2.txt \n");
memset(readbuf,0,sizeof(char)*150);
fd = do_open("dir/linkoffile2", O_RDONLY);
do_lseek(fd,-19,2);
do_read(fd,readbuf,19);
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: read chars: \"%s\" using lseek from file: /dir/linkoffile1\n",readbuf);
dbg(DBG_ERROR | DBG_VFS,"TEST: creating a duplicate file descriptor of file: /dir/dir2/file2.txt using do_dup()\n");
fd = do_open("/dir/dir2/file2.txt", O_RDONLY);
int fd2= do_dup(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: duplicate file descriptor is :\"%d\" of file: /dir/dir2/file2.txt \n",fd2);
do_close(fd); do_close(fd2);
dbg(DBG_ERROR | DBG_VFS,"TEST: creating a duplicate file descriptor of file: /dir/dir2/file2.txt using do_dup2()\n");
//.........这里部分代码省略.........
开发者ID:jiangchhz,项目名称:abmp,代码行数:101,代码来源:kmain.c
示例20: aufs_rename
//.........这里部分代码省略.........
a->h_path.mnt = a->br->br_mnt;
/* are they available to be renamed */
err = au_ren_may_dir(a);
if (unlikely(err))
goto out_children;
/* prepare the writable parent dir on the same branch */
if (a->dst_bstart == a->btgt) {
au_fset_ren(a->flags, WHDST);
} else {
err = au_cpup_dirs(a->dst_dentry, a->btgt);
if (unlikely(err))
goto out_children;
}
if (a->src_dir != a->dst_dir) {
/*
* this temporary unlock is safe,
* because both dir->i_mutex are locked.
*/
di_write_unlock(a->dst_parent);
di_write_lock_parent(a->src_parent);
err = au_wr_dir_need_wh(a->src_dentry,
au_ftest_ren(a->flags, ISDIR),
&a->btgt);
di_write_unlock(a->src_parent);
di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
au_fclr_ren(a->flags, ISSAMEDIR);
} else
err = au_wr_dir_need_wh(a->src_dentry,
au_ftest_ren(a->flags, ISDIR),
&a->btgt);
if (unlikely(err < 0))
goto out_children;
if (err)
au_fset_ren(a->flags, WHSRC);
/* lock them all */
err = au_ren_lock(a);
if (unlikely(err))
goto out_children;
if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
err = au_may_ren(a);
else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
err = -ENAMETOOLONG;
if (unlikely(err))
goto out_hdir;
/* store timestamps to be revertible */
au_ren_dt(a);
/* here we go */
err = do_rename(a);
if (unlikely(err))
goto out_dt;
/* update dir attributes */
au_ren_refresh_dir(a);
/* dput/iput all lower dentries */
au_ren_refresh(a);
goto out_hdir; /* success */
out_dt:
au_ren_rev_dt(err, a);
out_hdir:
au_ren_unlock(a);
out_children:
au_nhash_wh_fre
|
请发表评论