How to fix error: Name is too long

Ask for help and report issues not specific to either the Mac OS X or GTK+ versions of Transmission
fidoman
Posts: 8
Joined: Thu Aug 04, 2011 7:10 am

Re: How to fix error: Name is too long

Post by fidoman »

Since nobody here understand what is UTF-8 I've written patch for some name trimming by 255 bytes.
This is draft with some debug output to file and it requires hard refinement.

Code: Select all

*** utils.c-orig        2011-08-14 12:24:00.645183544 +0400
--- utils.c     2011-08-14 17:32:02.242301478 +0400
***************
*** 583,597 ****
--- 583,612 ----
      return 0;
  }
  
+ #define NAME_DEBUG
+ #ifdef NAME_DEBUG
+ FILE *name_log=NULL;
+ #endif
+ 
  char*
  tr_buildPath( const char *first_element, ... )
  {
      size_t bufLen = 0;
      const char * element;
      char * buf;
+ /*    char * buf2;*/
      char * pch;
      va_list vl;
  
+ #ifdef NAME_DEBUG
+     size_t lastLen;
+     size_t namePos;
+     unsigned char checksum = 0;
+     if( name_log == NULL) {
+         name_log = fopen("/tmp/name_debug.log", "wb");
+     }
+ #endif
+ 
      /* pass 1: allocate enough space for the string */
      va_start( vl, first_element );
      element = first_element;
***************
*** 600,605 ****
--- 615,625 ----
          element = va_arg( vl, const char* );
      }
      pch = buf = tr_new( char, bufLen );
+ 
+ #ifdef NAME_DEBUG
+     /*buf2 = tr_new( char, bufLen );*/
+ #endif
+ 
      va_end( vl );
  
      /* pass 2: build the string piece by piece */
***************
*** 607,612 ****
--- 627,635 ----
      element = first_element;
      while( element ) {
          const size_t elementLen = strlen( element );
+ #ifdef NAME_DEBUG
+       lastLen=elementLen;
+ #endif
          memcpy( pch, element, elementLen );
          pch += elementLen;
          *pch++ = TR_PATH_DELIMITER;
***************
*** 621,626 ****
--- 644,690 ----
  
      /* sanity checks & return */
      assert( pch - buf == (off_t)bufLen );
+ #ifdef NAME_DEBUG
+     namePos=bufLen;
+     while( namePos && buf[namePos-1] != TR_PATH_DELIMITER ) {
+         namePos--;
+     }
+     fprintf(name_log, "name at %7d len %7d buf %7d %s\n", namePos, bufLen-namePos-1, bufLen, buf);
+     /* if length>255
+     ... find start of extension, let it be a string end
+     ... cut from file name by excess length
+     ... if first char after cut if 0b10xxxxxx (utf8 continuation) cut more until start of UTF-8 character
+     */
+     if( (bufLen-namePos-1) > 255 ) {
+       size_t excess=bufLen-namePos-1-255+2; /* 2 bytes for control sum */
+       size_t extPos;
+       size_t cutPos;
+       extPos=bufLen;
+       while( extPos>namePos && buf[extPos-1] != '.' ) { /* finish after dot or at string start */
+          extPos--;
+       }
+       if( extPos<(namePos+excess+4) ) { /* +4 - reserve for utf-8 truncating */
+         /* too long extension or dot was not found, reset to end of string */
+         extPos=bufLen;
+       }
+       extPos--; /* go to point to dot or to zero at string end */
+ 
+       cutPos = extPos  -excess;
+       while( cutPos>namePos && ((buf[cutPos]&0xC0)==0x80) ) { /* remove UTF-8 continuations */
+         cutPos--;
+       }
+       /*strcpy( buf2, buf );*/
+       for( size_t counter = cutPos; counter<=extPos; counter++ ) {
+         checksum ^= buf[counter];
+       }
+       sprintf( buf+cutPos, "%02X", checksum );
+       strcpy( buf+cutPos+2, buf+extPos );
+       fprintf( name_log, "Cutted %d at %d ext %d result: %s\n", excess, cutPos, extPos, buf );
+ /*      tr_free( buf2 );*/
+       
+     };
+     
+ #endif
      return buf;
  }
blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: How to fix error: Name is too long

Post by blacke4dawn »

So I took a little deeper look into UTF-8.

It can actually have up to 4 bytes long characters but it is fully backwards compatible by being identical with the ASCII table for the first 128 characters. So unless they use strange national characters this is effectively a non-issue.

And trimming it would not be necessary if you just convert it to your national extended ASCII table instead. But as I have pointed out, this should be done on the OS level. Really, if every program would have to work around such (and similar) limitations then what would be the point in having a standardized interface for those functions?


However, I just have to ask you how many characters is it in the original file or folder name that generates this error.
fidoman
Posts: 8
Joined: Thu Aug 04, 2011 7:10 am

Re: How to fix error: Name is too long

Post by fidoman »

Hello.

Modern operating systems don't convert unicode to national charset - they use it in unicode-generation encodings (UCS-2 in Windows, UTF-8 in Linux and Solaris, but I don't know about BSD)/

Here goes piece of log generated with patch:

Code: Select all

long name at 45 len 377 buf 423: /tank/data/torrents/Флора и фауна/Семенов Тань-Шаньский А.П. Пределы и зоогеографические подразделения Палеарктической области для наземных сухопутных животных на основании географического распределения жесткокрылых насекомых. Л., 1935.djvu
Cutted 124 at 292 ext 417 result: /tank/data/torrents/Флора и фауна/Семенов Тань-Шаньский А.П. Пределы и зоогеографические подразделения Палеарктической области для наземных сухопутных животных на осн1B.djvu
After "long names" go position of filename part, length of filename, full path length and original path.
After "Cutted" - bytes to remove, position of cutting, position of file extension being preserved.

Length of filename is 377 bytes (this is length of raw C string). It is encoded in UTF-8. If we transcode it to UTF-16, we will get length of 206 wide characters. It easily fit onto Windows NTFS, as it use UCS-2 encoding and allows 255 wide characters, effectively 510 bytes.
But utf-8 presentation requires 377 bytes, so cannot be used as filename in unixes, as they limit name by 255 bytes, and, I repeat, modern OS'es doesn't use national codepages and do write utf-8 filenames to disk structures as-is.

Alternative to trimming is encoding to legacy charset, but it again should be done in transmission and will result in unability to view filenames by standard OS utilities.
Doing trimming at filesystem layer may be possible but it requires hard knowledge of OS internal APIs. I don't know tools that allow it.
In linux LD_PRELOAD for transmission may be alternative to patching, to replace open and stat functions with trimming wrappers, but I don't know how to do same in solaris.
msm93
Posts: 1
Joined: Wed Oct 21, 2015 2:09 pm

Re: How to fix error: Name is too long

Post by msm93 »

i recommend you to use "Long Path Tool " its an amazing tool
aiden carter
Posts: 1
Joined: Tue Nov 08, 2016 5:53 pm

Long Path Tool

Post by aiden carter »

The Long path tool is the very best program for error, unlock solution.
Try it and solved your problem.
I used the long path tool and I solved my error, unlocks problem solution.
llazarte
Posts: 1
Joined: Sun Dec 11, 2016 5:58 am

Re: How to fix error: Name is too long

Post by llazarte »

A simple solution that worked for me is:
1. Instead of opening the .torrent file, download it
2. Change its name to something short, say short.torrent
3. Open transmission with the command: transmission short.torrent
frank1982
Posts: 1
Joined: Mon Apr 03, 2017 6:52 am

Re: How to fix error: Name is too long

Post by frank1982 »

Try Long Path Tool as it can remove any problems that you might have.
hunderson
Posts: 1
Joined: Tue Apr 18, 2017 1:43 pm

Re: How to fix error: Name is too long

Post by hunderson »

I often use (long path tool) for this.You can try it for yourself and you will se how good it is.
gabriel3
Posts: 1
Joined: Wed May 10, 2017 3:41 pm

Re: How to fix error: Name is too long

Post by gabriel3 »

Try Long Path Tool
piercerob
Posts: 2
Joined: Sat Aug 19, 2017 2:16 am

Re: How to fix error: Name is too long

Post by piercerob »

People occasionally face this problem in Windows. Long Path Tool is simple solution for this.
unblocktheplanet
Posts: 10
Joined: Mon Dec 07, 2009 10:25 am

Re: How to fix error: Name is too long

Post by unblocktheplanet »

Still a problem in MacOS 10.13.4. This torrent: https://www.demonoid.pw/files/details/3 ... F0eVlFQT09
Sure want to list to those 50GB of Zappa boots!
Anybody ever find a workaround?
diman82
Posts: 1
Joined: Thu Aug 02, 2018 9:14 pm

Re: How to fix error: Name is too long

Post by diman82 »

The only workaround is downloading a torrent file (NOT magnet linking) and manually trimming the long name.
cfpp2p
Posts: 290
Joined: Sat Aug 08, 2009 3:14 pm

Re: How to fix error: Name is too long

Post by cfpp2p »

You can't just edit a .torrent metadata file name. The hash will change and the torrent will no longer work.
Post Reply