2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* compatability routines for older rsync protocol versions */
24 extern int csum_length;
26 extern int preserve_links;
27 extern int preserve_perms;
28 extern int preserve_devices;
29 extern int preserve_uid;
30 extern int preserve_gid;
31 extern int preserve_times;
32 extern int always_checksum;
35 extern int remote_version;
37 void (*send_file_entry)(struct file_struct *file,int f) = NULL;
38 void (*receive_file_entry)(struct file_struct *file,
39 unsigned char flags,int f) = NULL;
42 void send_file_entry_v10(struct file_struct *file,int f)
45 static mode_t last_mode=0;
46 static dev_t last_dev=0;
47 static uid_t last_uid=0;
48 static gid_t last_gid=0;
49 static char lastdir[MAXPATHLEN]="";
61 if (file->mode == last_mode) flags |= SAME_MODE;
62 if (file->dev == last_dev) flags |= SAME_DEV;
63 if (file->uid == last_uid) flags |= SAME_UID;
64 if (file->gid == last_gid) flags |= SAME_GID;
66 if (strncmp(file->name,lastdir,strlen(lastdir)) == 0) {
68 p = file->name + strlen(lastdir);
75 write_byte(f,strlen(p));
77 write_int(f,strlen(p));
78 write_buf(f,p,strlen(p));
79 write_int(f,(int)file->modtime);
80 write_int(f,(int)file->length);
81 if (!(flags & SAME_MODE))
82 write_int(f,(int)file->mode);
83 if (preserve_uid && !(flags & SAME_UID))
84 write_int(f,(int)file->uid);
85 if (preserve_gid && !(flags & SAME_GID))
86 write_int(f,(int)file->gid);
87 if (preserve_devices && IS_DEVICE(file->mode) && !(flags & SAME_DEV))
88 write_int(f,(int)file->dev);
91 if (preserve_links && S_ISLNK(file->mode)) {
92 write_int(f,strlen(file->link));
93 write_buf(f,file->link,strlen(file->link));
97 if (always_checksum) {
98 write_buf(f,file->sum,csum_length);
101 last_mode = file->mode;
102 last_dev = file->dev;
103 last_uid = file->uid;
104 last_gid = file->gid;
105 p = strrchr(file->name,'/');
107 int l = (int)(p - file->name) + 1;
108 strncpy(lastdir,file->name,l);
117 void receive_file_entry_v10(struct file_struct *file,
118 unsigned char flags,int f)
120 static mode_t last_mode=0;
121 static dev_t last_dev=0;
122 static uid_t last_uid=0;
123 static gid_t last_gid=0;
124 static char lastdir[MAXPATHLEN]="";
128 if (flags & SAME_DIR) {
130 l2 = strlen(lastdir);
136 file->name = (char *)malloc(l1+l2+1);
137 if (!file->name) out_of_memory("receive_file_entry");
139 strncpy(file->name,lastdir,l2);
140 read_buf(f,file->name+l2,l1);
141 file->name[l1+l2] = 0;
143 file->modtime = (time_t)read_int(f);
144 file->length = (off_t)read_int(f);
145 file->mode = (flags & SAME_MODE) ? last_mode : (mode_t)read_int(f);
147 file->uid = (flags & SAME_UID) ? last_uid : (uid_t)read_int(f);
149 file->gid = (flags & SAME_GID) ? last_gid : (gid_t)read_int(f);
150 if (preserve_devices && IS_DEVICE(file->mode))
151 file->dev = (flags & SAME_DEV) ? last_dev : (dev_t)read_int(f);
154 if (preserve_links && S_ISLNK(file->mode)) {
156 file->link = (char *)malloc(l+1);
157 if (!file->link) out_of_memory("receive_file_entry");
158 read_buf(f,file->link,l);
164 read_buf(f,file->sum,csum_length);
166 last_mode = file->mode;
167 last_dev = file->dev;
168 last_uid = file->uid;
169 last_gid = file->gid;
170 p = strrchr(file->name,'/');
172 int l = (int)(p - file->name) + 1;
173 strncpy(lastdir,file->name,l);
183 void setup_protocol(void)
185 if (remote_version == 10) {
186 send_file_entry = send_file_entry_v10;
187 receive_file_entry = receive_file_entry_v10;
189 send_file_entry = send_file_entry_v11;
190 receive_file_entry = receive_file_entry_v11;