I assume there's some good reason for the way filenames are faithfully
maintained as temp files, but it's a little frustrating when you get
"filename too long" messages as a result... with no indication of what
file it was it's complaining about.
The obvious fix is to simply generate a tmpname and have done with it.
Possibly safer, truncate the filename, in case there's some reason for
the filename being maintained (to restart the download? I don't know, it
seems like this would fail for files in tmpdir...).
Anyway...
--- rsync-2.5.6-orig/receiver.c Mon Jan 20 23:32:17 2003
+++ rsync-2.5.6/receiver.c Mon Aug 25 10:13:37 2003
@@ -163,33 +163,51 @@
}
}
-
static int get_tmpname(char *fnametmp, char *fname)
{
- char *f;
+ char *f, holder;
+ size_t len;
+
+ if(strlen(fname) > MAXPATHLEN) {
+ rprintf(FERROR,"%s: filename too long\n", fname);
+ return 0;
+ }
+
+ holder = 0;
/* open tmp file */
if (tmpdir) {
+ int tlen;
f = strrchr(fname,'/');
if (f == NULL)
f = fname;
else
f++;
- if (strlen(tmpdir)+strlen(f)+10 > MAXPATHLEN) {
- rprintf(FERROR,"filename too long\n");
+ tlen = strlen(tmpdir) + 10;
+ if(tlen > MAXPATHLEN) {
+ rprintf(FERROR,"%s: filename too long\n", tmpdir);
return 0;
}
+ len = strlen(f);
+ if (len + tlen > MAXPATHLEN) {
+ len = MAXPATHLEN - tlen;
+ holder = f[len];
+ f[len] = 0;
+ }
snprintf(fnametmp,MAXPATHLEN, "%s/.%s.XXXXXX",tmpdir,f);
+ if(holder) f[len] = holder;
return 1;
}
- f = strrchr(fname,'/');
-
- if (strlen(fname)+9 > MAXPATHLEN) {
- rprintf(FERROR,"filename too long\n");
- return 0;
+ len = strlen(fname);
+ if (len + 10 > MAXPATHLEN) {
+ len = MAXPATHLEN - 10;
+ holder = fname[len];
+ fname[len] = 0;
}
+ f = strrchr(fname,'/');
+
if (f) {
*f = 0;
snprintf(fnametmp,MAXPATHLEN,"%s/.%s.XXXXXX",
@@ -198,6 +216,7 @@
} else {
snprintf(fnametmp,MAXPATHLEN,".%s.XXXXXX",fname);
}
+ if(holder) fname[len] = holder;
return 1;
}