本文整理汇总了C++中do_rename函数的典型用法代码示例。如果您正苦于以下问题:C++ do_rename函数的具体用法?C++ do_rename怎么用?C++ do_rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_rename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
//.........这里部分代码省略.........
示例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;
}
示例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;
}
示例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();
}
示例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);
//.........这里部分代码省略.........