-extern char *backup_suffix;
-
-static struct delete_list {
- DEV64_T dev;
- INO64_T inode;
-} *delete_list;
-static int dlist_len, dlist_alloc_len;
-
-/* yuck! This function wouldn't have been necessary if I had the sorting
- algorithm right. Unfortunately fixing the sorting algorithm would introduce
- a backward incompatibility as file list indexes are sent over the link.
-*/
-static int delete_already_done(struct file_list *flist,int j)
-{
- int i;
- STRUCT_STAT st;
-
- if (link_stat(f_name(flist->files[j]), &st)) return 1;
-
- for (i=0;i<dlist_len;i++) {
- if (st.st_ino == delete_list[i].inode &&
- st.st_dev == delete_list[i].dev)
- return 1;
- }
-
- return 0;
-}
-
-static void add_delete_entry(struct file_struct *file)
-{
- if (dlist_len == dlist_alloc_len) {
- dlist_alloc_len += 1024;
- delete_list = (struct delete_list *)Realloc(delete_list, sizeof(delete_list[0])*dlist_alloc_len);
- if (!delete_list) out_of_memory("add_delete_entry");
- }
-
- delete_list[dlist_len].dev = file->dev;
- delete_list[dlist_len].inode = file->inode;
- dlist_len++;
-
- if (verbose > 3)
- rprintf(FINFO,"added %s to delete list\n", f_name(file));
-}
-
-static void delete_one(struct file_struct *f)
-{
- if (!S_ISDIR(f->mode)) {
- if (robust_unlink(f_name(f)) != 0) {
- rprintf(FERROR,"delete_one: unlink %s: %s\n",f_name(f),strerror(errno));
- } else if (verbose) {
- rprintf(FINFO,"deleting %s\n",f_name(f));
- }
- } else {
- if (do_rmdir(f_name(f)) != 0) {
- if (errno != ENOTEMPTY && errno != EEXIST)
- rprintf(FERROR,"delete_one: rmdir %s: %s\n",
- f_name(f), strerror(errno));
- } else if (verbose) {
- rprintf(FINFO,"deleting directory %s\n",f_name(f));
- }
- }
-}
-
-
-
-
-/* this deletes any files on the receiving side that are not present
- on the sending side. For version 1.6.4 I have changed the behaviour
- to match more closely what most people seem to expect of this option */
-void delete_files(struct file_list *flist)
-{
- struct file_list *local_file_list;
- int i, j;
- char *name;
- extern int module_id;
- extern int ignore_errors;
- extern int max_delete;
- static int deletion_count;
-
- if (cvs_exclude)
- add_cvs_excludes();
-
- if (io_error && !(lp_ignore_errors(module_id) || ignore_errors)) {
- rprintf(FINFO,"IO error encountered - skipping file deletion\n");
- return;
- }
-
- for (j=0;j<flist->count;j++) {
- if (!S_ISDIR(flist->files[j]->mode) ||
- !(flist->files[j]->flags & FLAG_DELETE)) continue;
-
- if (remote_version < 19 &&
- delete_already_done(flist, j)) continue;
-
- name = strdup(f_name(flist->files[j]));
-
- if (!(local_file_list = send_file_list(-1,1,&name))) {
- free(name);
- continue;
- }
-
- if (verbose > 1)
- rprintf(FINFO,"deleting in %s\n", name);
-
- for (i=local_file_list->count-1;i>=0;i--) {
- if (max_delete && deletion_count > max_delete) break;
- if (!local_file_list->files[i]->basename) continue;
- if (remote_version < 19 &&
- S_ISDIR(local_file_list->files[i]->mode))
- add_delete_entry(local_file_list->files[i]);
- if (-1 == flist_find(flist,local_file_list->files[i])) {
- char *f = f_name(local_file_list->files[i]);
- int k = strlen(f) - strlen(backup_suffix);
-/* Hi Andrew, do we really need to play with backup_suffix here? */
- if (make_backups && ((k <= 0) ||
- (strcmp(f+k,backup_suffix) != 0))) {
- (void) make_backup(f);
- } else {
- deletion_count++;
- delete_one(local_file_list->files[i]);
- }
- }
- }
- flist_free(local_file_list);
- free(name);
- }
-}
-
+extern int cleanup_got_literal;
+extern int remove_sent_files;
+extern int append_mode;
+extern int sparse_files;
+extern int keep_partial;
+extern int checksum_seed;
+extern int inplace;
+extern int delay_updates;
+extern struct stats stats;
+extern char *stdout_format;
+extern char *tmpdir;
+extern char *partial_dir;
+extern char *basis_dir[];
+extern struct file_list *the_file_list;
+extern struct filter_list_struct server_filter_list;
+
+static struct bitbag *delayed_bits = NULL;
+static int phase = 0;
+
+
+/*
+ * get_tmpname() - create a tmp filename for a given filename
+ *
+ * If a tmpdir is defined, use that as the directory to
+ * put it in. Otherwise, the tmp filename is in the same
+ * directory as the given name. Note that there may be no
+ * directory at all in the given name!
+ *
+ * The tmp filename is basically the given filename with a
+ * dot prepended, and .XXXXXX appended (for mkstemp() to
+ * put its unique gunk in). Take care to not exceed
+ * either the MAXPATHLEN or NAME_MAX, esp. the last, as
+ * the basename basically becomes 8 chars longer. In that
+ * case, the original name is shortened sufficiently to
+ * make it all fit.
+ *
+ * Of course, there's no real reason for the tmp name to
+ * look like the original, except to satisfy us humans.
+ * As long as it's unique, rsync will work.
+ */