File name too long

Luc Santeramo luc.santeramo at univ-avignon.fr
Tue Mar 11 18:42:56 EST 2003


>With this patch, I can successfully transfer a file that has a 255-char
>filename.

Ok, thanks Paul.
I'll try this patch.

>Only thing that may be a problem is the NAME_MAX thing, but that's a
>POSIX thing, so should be relatively safe (famous last words).

wget uses URL name to create directories and store website pages.
so wget will be blocked by NAME_MAX restriction before breaking rsync jobs, 
won't he?


thanks again

Luc

>Paul Slootman
>
>diff -ru orig/rsync-2.5.6/receiver.c rsync-2.5.6/receiver.c
>--- orig/rsync-2.5.6/receiver.c 2003-01-21 00:32:17.000000000 +0100
>+++ rsync-2.5.6/receiver.c      2003-03-10 17:03:47.000000000 +0100
>@@ -166,37 +166,49 @@
>
>  static int get_tmpname(char *fnametmp, char *fname)
>  {
>-       char *f;
>-
>-       /* open tmp file */
>-       if (tmpdir) {
>-               f = strrchr(fname,'/');
>-               if (f == NULL)
>-                       f = fname;
>-               else
>-                       f++;
>-               if (strlen(tmpdir)+strlen(f)+10 > MAXPATHLEN) {
>-                       rprintf(FERROR,"filename too long\n");
>-                       return 0;
>-               }
>-               snprintf(fnametmp,MAXPATHLEN, "%s/.%s.XXXXXX",tmpdir,f);
>-               return 1;
>-       }
>-
>-       f = strrchr(fname,'/');
>+       char    *f;
>+       int     slash = 0;      /* restore the '/' ? */
>+       char    x = 0;          /* restore the shortened name (with this?) */
>+       char    *dir = "";      /* what dir to put the temp file in */
>+
>+       if (tmpdir)
>+               dir = tmpdir;
>+       f = strrchr(fname,'/'); /* is there a directory to skip in fname? */
>+       if (f == NULL) {
>+               f = fname;              /* no */
>+       }
>+       else {
>+               slash++;                /* yes */
>+               *f = 0;
>+               f++;
>+               dir = fname;
>+       }
>
>-       if (strlen(fname)+9 > MAXPATHLEN) {
>+       if (strlen(dir)+strlen(f)+1 > MAXPATHLEN) {
>                 rprintf(FERROR,"filename too long\n");
>                 return 0;
>         }
>
>-       if (f) {
>-               *f = 0;
>-               snprintf(fnametmp,MAXPATHLEN,"%s/.%s.XXXXXX",
>-                       fname,f+1);
>+       if (strlen(f)+8 > NAME_MAX || strlen(dir)+strlen(f)+9 > MAXPATHLEN) {
>+               /* temporarily shorten the name, it's just for a temp name 
>anyway */
>+               x = f[NAME_MAX-10];
>+               f[NAME_MAX-10] = 0;
>+       }
>+
>+       /* construct temp name template */
>+       if (*dir) {
>+               snprintf(fnametmp, MAXPATHLEN, "%s/.%s.XXXXXX", dir, f);
>+       }
>+       else {
>+               snprintf(fnametmp, MAXPATHLEN, ".%s.XXXXXX", f);
>+       }
>+
>+       if (x)
>+               f[NAME_MAX-10] = x; /* restore the name if necessary */
>+
>+       if (slash) {    /* restore slash if necessary */
>+               f--;
>                 *f = '/';
>-       } else {
>-               snprintf(fnametmp,MAXPATHLEN,".%s.XXXXXX",fname);
>         }
>
>         return 1;
>--
>To unsubscribe or change options: 
>http://lists.samba.org/mailman/listinfo/rsync
>Before posting, read: http://www.tuxedo.org/~esr/faqs/smart-questions.html




More information about the rsync mailing list