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 preserve_links;
25 extern int preserve_perms;
26 extern int preserve_devices;
27 extern int preserve_uid;
28 extern int preserve_gid;
29 extern int preserve_times;
30 extern int always_checksum;
33 extern int remote_version;
35 void (*send_file_entry)(struct file_struct *file,int f) = NULL;
36 void (*receive_file_entry)(struct file_struct *file,
37 unsigned char flags,int f) = NULL;
40 void send_file_entry_v10(struct file_struct *file,int f)
43 static mode_t last_mode=0;
44 static dev_t last_dev=0;
45 static uid_t last_uid=0;
46 static gid_t last_gid=0;
47 static char lastdir[MAXPATHLEN]="";
59 if (file->mode == last_mode) flags |= SAME_MODE;
60 if (file->dev == last_dev) flags |= SAME_DEV;
61 if (file->uid == last_uid) flags |= SAME_UID;
62 if (file->gid == last_gid) flags |= SAME_GID;
64 if (strncmp(file->name,lastdir,strlen(lastdir)) == 0) {
66 p = file->name + strlen(lastdir);
73 write_byte(f,strlen(p));
75 write_int(f,strlen(p));
76 write_buf(f,p,strlen(p));
77 write_int(f,(int)file->modtime);
78 write_int(f,(int)file->length);
79 if (!(flags & SAME_MODE))
80 write_int(f,(int)file->mode);
81 if (preserve_uid && !(flags & SAME_UID))
82 write_int(f,(int)file->uid);
83 if (preserve_gid && !(flags & SAME_GID))
84 write_int(f,(int)file->gid);
85 if (preserve_devices && IS_DEVICE(file->mode) && !(flags & SAME_DEV))
86 write_int(f,(int)file->dev);
89 if (preserve_links && S_ISLNK(file->mode)) {
90 write_int(f,strlen(file->link));
91 write_buf(f,file->link,strlen(file->link));
95 if (always_checksum) {
96 write_buf(f,file->sum,SUM_LENGTH);
99 last_mode = file->mode;
100 last_dev = file->dev;
101 last_uid = file->uid;
102 last_gid = file->gid;
103 p = strrchr(file->name,'/');
105 int l = (int)(p - file->name) + 1;
106 strncpy(lastdir,file->name,l);
115 void receive_file_entry_v10(struct file_struct *file,
116 unsigned char flags,int f)
118 static mode_t last_mode=0;
119 static dev_t last_dev=0;
120 static uid_t last_uid=0;
121 static gid_t last_gid=0;
122 static char lastdir[MAXPATHLEN]="";
126 if (flags & SAME_DIR) {
128 l2 = strlen(lastdir);
134 file->name = (char *)malloc(l1+l2+1);
135 if (!file->name) out_of_memory("receive_file_entry");
137 strncpy(file->name,lastdir,l2);
138 read_buf(f,file->name+l2,l1);
139 file->name[l1+l2] = 0;
141 file->modtime = (time_t)read_int(f);
142 file->length = (off_t)read_int(f);
143 file->mode = (flags & SAME_MODE) ? last_mode : (mode_t)read_int(f);
145 file->uid = (flags & SAME_UID) ? last_uid : (uid_t)read_int(f);
147 file->gid = (flags & SAME_GID) ? last_gid : (gid_t)read_int(f);
148 if (preserve_devices && IS_DEVICE(file->mode))
149 file->dev = (flags & SAME_DEV) ? last_dev : (dev_t)read_int(f);
152 if (preserve_links && S_ISLNK(file->mode)) {
154 file->link = (char *)malloc(l+1);
155 if (!file->link) out_of_memory("receive_file_entry");
156 read_buf(f,file->link,l);
162 read_buf(f,file->sum,SUM_LENGTH);
164 last_mode = file->mode;
165 last_dev = file->dev;
166 last_uid = file->uid;
167 last_gid = file->gid;
168 p = strrchr(file->name,'/');
170 int l = (int)(p - file->name) + 1;
171 strncpy(lastdir,file->name,l);
181 void setup_protocol(void)
183 if (remote_version == 10) {
184 send_file_entry = send_file_entry_v10;
185 receive_file_entry = receive_file_entry_v10;
187 send_file_entry = send_file_entry_v11;
188 receive_file_entry = receive_file_entry_v11;