From f7632fc60d69c8dabed600ede87f0b91319a3b7f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Nov 1998 00:52:01 +0000 Subject: [PATCH] if no local destination is provided for the transfer then provide a "ls -l" style listing of the files that would be transferred --- flist.c | 39 +++++++++++++++++++++++++++++++++++++++ generator.c | 3 +++ log.c | 24 +----------------------- main.c | 21 +++++++++++++++++++-- options.c | 2 +- rsync.h | 2 ++ rsync.yo | 3 +++ util.c | 22 ++++++++++++++++++++++ 8 files changed, 90 insertions(+), 26 deletions(-) diff --git a/flist.c b/flist.c index f5c69b9a..664f26e4 100644 --- a/flist.c +++ b/flist.c @@ -51,6 +51,36 @@ static struct exclude_struct **local_exclude_list; static void clean_flist(struct file_list *flist, int strip_root); + +static void list_file_entry(struct file_struct *f) +{ + char perms[11] = "----------"; + char *perm_map = "rwxrwxrwx"; + int i; + + for (i=0;i<9;i++) { + if (f->mode & (1<mode)) perms[0] = 'l'; + if (S_ISDIR(f->mode)) perms[0] = 'd'; + if (S_ISBLK(f->mode)) perms[0] = 'b'; + if (S_ISCHR(f->mode)) perms[0] = 'c'; + if (S_ISSOCK(f->mode)) perms[0] = 's'; + if (S_ISFIFO(f->mode)) perms[0] = 'p'; + + if (preserve_links && S_ISLNK(f->mode)) { + rprintf(FINFO,"%s %11.0f %s %s -> %s\n", + perms, + (double)f->length, timestring(f->modtime), + f_name(f), f->link); + } else { + rprintf(FINFO,"%s %11.0f %s %s\n", + perms, + (double)f->length, timestring(f->modtime), f_name(f)); + } +} + + int link_stat(const char *Path, STRUCT_STAT *Buffer) { #if SUPPORT_LINKS @@ -699,6 +729,7 @@ struct file_list *recv_file_list(int f) struct file_list *flist; unsigned char flags; int64 start_read; + extern int list_only; if (verbose && recurse && !am_server) { rprintf(FINFO,"receiving file list ... "); @@ -765,6 +796,14 @@ struct file_list *recv_file_list(int f) io_error |= read_int(f); } + if (list_only) { + int i; + for (i=0;icount;i++) { + list_file_entry(flist->files[i]); + } + } + + if (verbose > 2) rprintf(FINFO,"recv_file_list done\n"); diff --git a/generator.c b/generator.c index 99052220..06c1fa4b 100644 --- a/generator.c +++ b/generator.c @@ -165,6 +165,9 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) char *fnamecmp; char fnamecmpbuf[MAXPATHLEN]; extern char *compare_dest; + extern int list_only; + + if (list_only) return; if (verbose > 2) rprintf(FINFO,"recv_generator(%s,%d)\n",fname,i); diff --git a/log.c b/log.c index 32ae3552..732a96b7 100644 --- a/log.c +++ b/log.c @@ -26,33 +26,11 @@ static FILE *logfile; -/**************************************************************************** - return the date and time as a string -****************************************************************************/ -static char *timestring(void ) -{ - static char TimeBuf[200]; - time_t t = time(NULL); - struct tm *tm = localtime(&t); - -#ifdef HAVE_STRFTIME - strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %T",tm); -#else - strlcpy(TimeBuf, asctime(tm), sizeof(TimeBuf)-1); -#endif - - if (TimeBuf[strlen(TimeBuf)-1] == '\n') { - TimeBuf[strlen(TimeBuf)-1] = 0; - } - - return(TimeBuf); -} - static void logit(int priority, char *buf) { if (logfile) { fprintf(logfile,"%s [%d] %s", - timestring(), (int)getpid(), buf); + timestring(time(NULL)), (int)getpid(), buf); fflush(logfile); } else { syslog(priority, "%s", buf); diff --git a/main.c b/main.c index 00ccd8e8..0e379aa2 100644 --- a/main.c +++ b/main.c @@ -384,6 +384,7 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[]) int status = 0, status2 = 0; char *local_name = NULL; extern int am_sender; + extern int list_only; setup_protocol(f_out,f_in); @@ -412,6 +413,8 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[]) report(-1); exit_cleanup(status); } + + if (argc == 0) list_only = 1; send_exclude_list(f_out); @@ -462,6 +465,20 @@ static int start_client(int argc, char *argv[]) extern int am_sender; extern char *shell_cmd; + if (strncasecmp(URL_PREFIX, argv[0], strlen(URL_PREFIX)) == 0) { + char *host, *path; + + host = argv[0] + strlen(URL_PREFIX); + p = strchr(host,'/'); + if (p) { + *p = 0; + path = p+1; + } else { + path=""; + } + return start_socket_client(host, path, argc-1, argv+1); + } + p = find_colon(argv[0]); if (p) { @@ -470,7 +487,7 @@ static int start_client(int argc, char *argv[]) return start_socket_client(argv[0], p+2, argc-1, argv+1); } - if (argc < 2) { + if (argc < 1) { usage(FERROR); exit_cleanup(1); } @@ -525,7 +542,7 @@ static int start_client(int argc, char *argv[]) shell_path?shell_path:""); } - if (!am_sender && argc != 1) { + if (!am_sender && argc > 1) { usage(FERROR); exit_cleanup(1); } diff --git a/options.c b/options.c index a79443fc..082aad77 100644 --- a/options.c +++ b/options.c @@ -73,7 +73,7 @@ int rsync_port = RSYNC_PORT; int verbose = 0; int always_checksum = 0; - +int list_only = 0; void usage(int F) { diff --git a/rsync.h b/rsync.h index 7485e5d4..6bde7a46 100644 --- a/rsync.h +++ b/rsync.h @@ -23,6 +23,8 @@ #define RSYNC_NAME "rsync" #define RSYNCD_CONF "/etc/rsyncd.conf" +#define URL_PREFIX "rsync://" + #define BACKUP_SUFFIX "~" /* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is diff --git a/rsync.yo b/rsync.yo index 236aca56..411a8ce9 100644 --- a/rsync.yo +++ b/rsync.yo @@ -140,6 +140,9 @@ itemize( it() if you specify no path name on the remote server then the list of accessible paths on the server will be shown. + + it() if you specify no local destination then a listing of the + specified files on the remote server is provided ) Some paths on the remote server may require authentication. If so then diff --git a/util.c b/util.c index 7be0be30..216bb10d 100644 --- a/util.c +++ b/util.c @@ -762,3 +762,25 @@ char *sanitize_path(char *p) return(copy); } + +/**************************************************************************** + return the date and time as a string +****************************************************************************/ +char *timestring(time_t t) +{ + static char TimeBuf[200]; + struct tm *tm = localtime(&t); + +#ifdef HAVE_STRFTIME + strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %T",tm); +#else + strlcpy(TimeBuf, asctime(tm), sizeof(TimeBuf)-1); +#endif + + if (TimeBuf[strlen(TimeBuf)-1] == '\n') { + TimeBuf[strlen(TimeBuf)-1] = 0; + } + + return(TimeBuf); +} + -- 2.34.1