Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Tridgell committed Dec 17, 1997
1 parent cbbe489 commit 82306bf
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 20 deletions.
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 17 additions & 3 deletions flist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions hlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 38 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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},
Expand All @@ -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'},
Expand All @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -781,3 +813,4 @@ int main(int argc,char *argv[])

return status | status2;
}

26 changes: 20 additions & 6 deletions rsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions rsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ extern int errno;
#define SUPPORT_LINKS HAVE_READLINK
#define SUPPORT_HARD_LINKS HAVE_LINK

#if !SUPPORT_LINKS
#define lstat stat
#endif

#ifndef HAVE_LCHOWN
#define lchown chown
#endif
Expand Down

0 comments on commit 82306bf

Please sign in to comment.