[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: An interesting problem: determining filename length
From:       Thiago Macieira <thiago () kde ! org>
Date:       2009-01-07 20:13:05
Message-ID: 200901072113.12396.thiago () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Joris Guisson wrote:
> As you might be aware there is a filename length limit on most
> operating systems, when you create a file with a longer name you run
> into trouble. Seeing that a bittorrent client has no control over the
> filenames in a torrent, it can encounter the problem that the
> filenames are too long, so obviously it needs to shorten long
> filenames. I'm now trying to figure out a way to determine the length
> of a filename.
> 
> Easy, you would think, however suppose the filename is in a QString,
> using QString::length() will give you wrong results, seeing that it
> will give you the number of characters and a character may take up
> more bytes then one. So my second approach was to use
> QFile::encodeName(filename).length(), this also does not work, it
> overestimates the length of names containing both latin and cyrillic
> characters. For example :
> 
> /home/joris/ktorrent/downloads/VIA POUYSHIE SERDCA-Zolotaja kollekcija
> VIA[LP,CD,EP]/ВИА ПОЮЩИЕ СЕ ДЦА-1976-Миньон Г62-05667-8 \
> Песни АнатолияДнепрова/02. Лицо в \
> ладонях(А.Днепров-И.Кохановский).mp3 
> Using QFile::encodeName will result in a length of 273 which is longer
> then the limit on linux (255), however creating the file without
> shortening it, works without any problems. My guess is that the latin
> characters are probably
> 
> So does anybody know how you actually determine the length of a such a
> filename ? Preferably in a portable manner, and obviously it must work
> will all posible characters in a filename.

The limit is of 255 characters in each path component, and 4096 bytes for 
the whole path. (At least when I tested with pathconf(2) on my Linux)

So if you want to be perfectly sure, you have to decompose the path in 
components and successively call pathconf for the combinations. If any 
element is longer than the result for the components leading to it, then 
you shorten.

Finally, remember that this code is pointless on Windows, where pathname 
limits are much stricter, the list of forbidden characters is huge, and 
file names are given in Unicode already.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358


["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic