mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-01-20 04:48:05 -05:00
*** empty log message ***
This commit is contained in:
3
README
3
README
@@ -22,6 +22,7 @@ Basically you use rsync just like rcp, but rsync has many additional options.
|
||||
|
||||
Here is a brief description of available options:
|
||||
|
||||
Options:
|
||||
-v, --verbose increase verbosity
|
||||
-c, --checksum always checksum
|
||||
-a, --archive archive mode (same as -rlptDog)
|
||||
@@ -30,6 +31,7 @@ Here is a brief description of available options:
|
||||
-b, --backup make backups (default ~ extension)
|
||||
-u, --update update only (don't overwrite newer files)
|
||||
-l, --links preserve soft links
|
||||
-L, --copy-links treat soft links like regular files
|
||||
-H, --hard-links preserve hard links
|
||||
-p, --perms preserve permissions
|
||||
-o, --owner preserve owner (root only)
|
||||
@@ -38,6 +40,7 @@ Here is a brief description of available options:
|
||||
-t, --times preserve times
|
||||
-S, --sparse handle sparse files efficiently
|
||||
-n, --dry-run show what would have been transferred
|
||||
-W, --whole-file copy whole files, no incremental checks
|
||||
-x, --one-file-system don't cross filesystem boundaries
|
||||
-B, --block-size SIZE checksum blocking size
|
||||
-e, --rsh COMMAND specify rsh replacement
|
||||
|
||||
@@ -40,6 +40,8 @@ echo no)
|
||||
AC_FUNC_MEMCMP
|
||||
AC_FUNC_MMAP
|
||||
AC_FUNC_UTIME_NULL
|
||||
AC_FUNC_SETPGRP
|
||||
AC_FUNC_GETPGRP
|
||||
AC_CHECK_FUNCS(waitpid strtok pipe getcwd mkdir strdup strerror chown chmod mknod)
|
||||
AC_CHECK_FUNCS(fchmod fstat strchr bcopy bzero readlink link utime utimes)
|
||||
AC_CHECK_FUNCS(memmove getopt_long lchown setlinebuf)
|
||||
|
||||
20
flist.c
20
flist.c
@@ -42,12 +42,26 @@ extern int preserve_uid;
|
||||
extern int preserve_gid;
|
||||
extern int preserve_times;
|
||||
extern int relative_paths;
|
||||
extern int copy_links;
|
||||
|
||||
static char **local_exclude_list = NULL;
|
||||
|
||||
static void clean_fname(char *name);
|
||||
|
||||
|
||||
int link_stat(const char *Path, struct stat *Buffer)
|
||||
{
|
||||
#if SUPPORT_LINKS
|
||||
if (copy_links) {
|
||||
return stat(Path, Buffer);
|
||||
} else {
|
||||
return lstat(Path, Buffer);
|
||||
}
|
||||
#else
|
||||
return stat(Path, Buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
This function is used to check if a file should be included/excluded
|
||||
from the list of files based on its name and type etc
|
||||
@@ -68,7 +82,7 @@ static dev_t filesystem_dev;
|
||||
static void set_filesystem(char *fname)
|
||||
{
|
||||
struct stat st;
|
||||
if (lstat(fname,&st) != 0) return;
|
||||
if (link_stat(fname,&st) != 0) return;
|
||||
filesystem_dev = st.st_dev;
|
||||
}
|
||||
|
||||
@@ -241,7 +255,7 @@ static struct file_struct *make_file(char *fname)
|
||||
|
||||
bzero(sum,SUM_LENGTH);
|
||||
|
||||
if (lstat(fname,&st) != 0) {
|
||||
if (link_stat(fname,&st) != 0) {
|
||||
fprintf(FERROR,"%s: %s\n",
|
||||
fname,strerror(errno));
|
||||
return NULL;
|
||||
@@ -416,7 +430,7 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
|
||||
strcat(fname,".");
|
||||
}
|
||||
|
||||
if (lstat(fname,&st) != 0) {
|
||||
if (link_stat(fname,&st) != 0) {
|
||||
fprintf(FERROR,"%s : %s\n",fname,strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
4
hlink.c
4
hlink.c
@@ -116,8 +116,8 @@ void do_hard_links(struct file_list *flist)
|
||||
hlink_list[i].inode == hlink_list[i-1].inode) {
|
||||
struct stat st1,st2;
|
||||
|
||||
if (lstat(hlink_list[i-1].name,&st1) != 0) continue;
|
||||
if (lstat(hlink_list[i].name,&st2) != 0) {
|
||||
if (link_stat(hlink_list[i-1].name,&st1) != 0) continue;
|
||||
if (link_stat(hlink_list[i].name,&st2) != 0) {
|
||||
if (!dry_run && link(hlink_list[i-1].name,hlink_list[i].name) != 0) {
|
||||
if (verbose > 0)
|
||||
fprintf(FINFO,"link %s => %s : %s\n",
|
||||
|
||||
43
main.c
43
main.c
@@ -30,6 +30,8 @@ char *backup_suffix = BACKUP_SUFFIX;
|
||||
static char *rsync_path = RSYNC_NAME;
|
||||
|
||||
int make_backups = 0;
|
||||
int whole_file = 0;
|
||||
int copy_links = 0;
|
||||
int preserve_links = 0;
|
||||
int preserve_hard_links = 0;
|
||||
int preserve_perms = 0;
|
||||
@@ -115,6 +117,10 @@ static void server_options(char **args,int *argc)
|
||||
argstr[x++] = 'n';
|
||||
if (preserve_links)
|
||||
argstr[x++] = 'l';
|
||||
if (copy_links)
|
||||
argstr[x++] = 'L';
|
||||
if (whole_file)
|
||||
argstr[x++] = 'W';
|
||||
if (preserve_hard_links)
|
||||
argstr[x++] = 'H';
|
||||
if (preserve_uid)
|
||||
@@ -163,8 +169,8 @@ static void server_options(char **args,int *argc)
|
||||
int do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f_out)
|
||||
{
|
||||
char *args[100];
|
||||
int i,argc=0;
|
||||
char *tok,*p;
|
||||
int i,argc=0, ret;
|
||||
char *tok,*p,*dir=NULL;
|
||||
|
||||
if (!local_server) {
|
||||
if (!cmd)
|
||||
@@ -200,7 +206,7 @@ int do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f_out)
|
||||
server_options(args,&argc);
|
||||
|
||||
if (path && *path) {
|
||||
char *dir = strdup(path);
|
||||
dir = strdup(path);
|
||||
p = strrchr(dir,'/');
|
||||
if (p && !relative_paths) {
|
||||
*p = 0;
|
||||
@@ -226,7 +232,10 @@ int do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f_out)
|
||||
fprintf(FERROR,"\n");
|
||||
}
|
||||
|
||||
return piped_child(args,f_in,f_out);
|
||||
ret = piped_child(args,f_in,f_out);
|
||||
if (dir) free(dir);
|
||||
|
||||
return ret;
|
||||
|
||||
oom:
|
||||
out_of_memory("do_cmd");
|
||||
@@ -404,6 +413,7 @@ static void usage(FILE *f)
|
||||
fprintf(f,"-b, --backup make backups (default ~ extension)\n");
|
||||
fprintf(f,"-u, --update update only (don't overwrite newer files)\n");
|
||||
fprintf(f,"-l, --links preserve soft links\n");
|
||||
fprintf(f,"-L, --copy-links treat soft links like regular files\n");
|
||||
fprintf(f,"-H, --hard-links preserve hard links\n");
|
||||
fprintf(f,"-p, --perms preserve permissions\n");
|
||||
fprintf(f,"-o, --owner preserve owner (root only)\n");
|
||||
@@ -412,6 +422,7 @@ static void usage(FILE *f)
|
||||
fprintf(f,"-t, --times preserve times\n");
|
||||
fprintf(f,"-S, --sparse handle sparse files efficiently\n");
|
||||
fprintf(f,"-n, --dry-run show what would have been transferred\n");
|
||||
fprintf(f,"-W, --whole-file copy whole files, no incremental checks\n");
|
||||
fprintf(f,"-x, --one-file-system don't cross filesystem boundaries\n");
|
||||
fprintf(f,"-B, --block-size SIZE checksum blocking size\n");
|
||||
fprintf(f,"-e, --rsh COMMAND specify rsh replacement\n");
|
||||
@@ -433,7 +444,7 @@ static void usage(FILE *f)
|
||||
enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
|
||||
OPT_EXCLUDE_FROM,OPT_DELETE,OPT_RSYNC_PATH};
|
||||
|
||||
static char *short_options = "oblHpguDCtcahvrRIxnSe:B:z";
|
||||
static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:z";
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"version", 0, 0, OPT_VERSION},
|
||||
@@ -459,6 +470,8 @@ static struct option long_options[] = {
|
||||
{"devices", 0, 0, 'D'},
|
||||
{"perms", 0, 0, 'p'},
|
||||
{"links", 0, 0, 'l'},
|
||||
{"copy-links", 0, 0, 'L'},
|
||||
{"whole-file", 0, 0, 'W'},
|
||||
{"hard-links", 0, 0, 'H'},
|
||||
{"owner", 0, 0, 'o'},
|
||||
{"group", 0, 0, 'g'},
|
||||
@@ -469,6 +482,10 @@ static struct option long_options[] = {
|
||||
{"compress", 0, 0, 'z'},
|
||||
{0,0,0,0}};
|
||||
|
||||
RETSIGTYPE sigusr1_handler(int val) {
|
||||
exit_cleanup(1);
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
int pid, status = 0, status2 = 0;
|
||||
@@ -483,6 +500,13 @@ int main(int argc,char *argv[])
|
||||
struct file_list *flist;
|
||||
char *local_name = NULL;
|
||||
|
||||
#ifdef SETPGRP_VOID
|
||||
setpgrp();
|
||||
#else
|
||||
setpgrp(0,0);
|
||||
#endif
|
||||
signal(SIGUSR1, sigusr1_handler);
|
||||
|
||||
starttime = time(NULL);
|
||||
am_root = (getuid() == 0);
|
||||
|
||||
@@ -556,6 +580,14 @@ int main(int argc,char *argv[])
|
||||
preserve_links=1;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
copy_links=1;
|
||||
break;
|
||||
|
||||
case 'W':
|
||||
whole_file=1;
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
#if SUPPORT_HARD_LINKS
|
||||
preserve_hard_links=1;
|
||||
@@ -781,3 +813,4 @@ int main(int argc,char *argv[])
|
||||
|
||||
return status | status2;
|
||||
}
|
||||
|
||||
|
||||
26
rsync.c
26
rsync.c
@@ -30,6 +30,7 @@ extern int remote_version;
|
||||
|
||||
extern char *backup_suffix;
|
||||
|
||||
extern int whole_file;
|
||||
extern int block_size;
|
||||
extern int update_only;
|
||||
extern int make_backups;
|
||||
@@ -200,7 +201,7 @@ static int set_perms(char *fname,struct file_struct *file,struct stat *st,
|
||||
if (dry_run) return 0;
|
||||
|
||||
if (!st) {
|
||||
if (lstat(fname,&st2) != 0) {
|
||||
if (link_stat(fname,&st2) != 0) {
|
||||
fprintf(FERROR,"stat %s : %s\n",fname,strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
@@ -264,7 +265,7 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
|
||||
if (verbose > 2)
|
||||
fprintf(FERROR,"recv_generator(%s,%d)\n",fname,i);
|
||||
|
||||
statret = lstat(fname,&st);
|
||||
statret = link_stat(fname,&st);
|
||||
|
||||
if (S_ISDIR(file->mode)) {
|
||||
if (dry_run) return;
|
||||
@@ -404,6 +405,12 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
|
||||
return;
|
||||
}
|
||||
|
||||
if (whole_file) {
|
||||
write_int(f_out,i);
|
||||
send_sums(NULL,f_out);
|
||||
return;
|
||||
}
|
||||
|
||||
/* open the file */
|
||||
fd = open(fname,O_RDONLY);
|
||||
|
||||
@@ -533,7 +540,6 @@ static void delete_one(struct file_struct *f)
|
||||
static void delete_files(struct file_list *flist)
|
||||
{
|
||||
struct file_list *local_file_list;
|
||||
char *dot=".";
|
||||
int i, j;
|
||||
char *last_name=NULL;
|
||||
|
||||
@@ -566,9 +572,17 @@ static char *cleanup_fname = NULL;
|
||||
|
||||
void exit_cleanup(int code)
|
||||
{
|
||||
if (cleanup_fname)
|
||||
unlink(cleanup_fname);
|
||||
exit(code);
|
||||
if (cleanup_fname)
|
||||
unlink(cleanup_fname);
|
||||
signal(SIGUSR1, SIG_IGN);
|
||||
if (code) {
|
||||
#ifdef GETPGRP_VOID
|
||||
kill(-getpgrp(), SIGUSR1);
|
||||
#else
|
||||
kill(-getpgrp(getpid()), SIGUSR1);
|
||||
#endif
|
||||
}
|
||||
exit(code);
|
||||
}
|
||||
|
||||
void sig_int(void)
|
||||
|
||||
Reference in New Issue
Block a user