- Updated the address for the FSF in the opening comment.
[rsync/rsync.git] / main.c
diff --git a/main.c b/main.c
index 7ed0d39..1237447 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,23 +1,25 @@
-/* -*- c-file-style: "linux" -*-
-
-   Copyright (C) 1996-2001 by Andrew Tridgell <tridge@samba.org>
-   Copyright (C) Paul Mackerras 1996
-   Copyright (C) 2001, 2002 by Martin Pool <mbp@samba.org>
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+/*
+ * The startup routines, including main(), for rsync.
+ *
+ * Copyright (C) 1996-2001 Andrew Tridgell <tridge@samba.org>
+ * Copyright (C) 1996 Paul Mackerras
+ * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
+ * Copyright (C) 2003, 2004, 2005, 2006 Wayne Davison
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 #include "rsync.h"
 #if defined CONFIG_LOCALE && defined HAVE_LOCALE_H
@@ -189,7 +191,7 @@ static void handle_stats(int f)
        /* this is the client */
 
        if (f < 0 && !am_sender) /* e.g. when we got an empty file list. */
-               ; 
+               ;
        else if (!am_sender) {
                /* Read the first two in opposite order because the meaning of
                 * read/write swaps when switching from sender to receiver. */
@@ -438,8 +440,8 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char *path,
 
 /* The receiving side operates in one of two modes:
  *
- * 1. it enters a directory and receives one or more files, placing them
- * according to their names in the file-list.
+ * 1. it receives any number of files into a destination directory,
+ * placing them according to their names in the file-list.
  *
  * 2. it receives a single file and saves it using the name in the
  * destination path instead of its file-list name.  This requires a
@@ -480,6 +482,17 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
                                " copying more than 1 file\n");
                        exit_cleanup(RERR_FILESELECT);
                }
+               /* Caution: flist->count could be 0! */
+               if (flist->count == 1 && S_ISDIR(flist->files[0]->mode)) {
+                       rprintf(FERROR,
+                               "ERROR: cannot overwrite non-directory"
+                               " with a directory\n");
+                       exit_cleanup(RERR_FILESELECT);
+               }
+       } else if (errno != ENOENT) {
+               rsyserr(FERROR, errno, "cannot stat destination %s",
+                       full_fname(dest_path));
+               exit_cleanup(RERR_FILESELECT);
        }
 
        cp = strrchr(dest_path, '/');