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

List:       kde-devel
Subject:    Re: An interesting problem: determining filename length
From:       "Joris Guisson" <joris.guisson () gmail ! com>
Date:       2009-01-08 8:42:49
Message-ID: 6bc528f40901080042w701eacdfu57bd80873e72a677 () mail ! gmail ! com
[Download RAW message or body]

OK, that clears up some things, I was a bit confused by PATH_MAX and
NAME_MAX and just decided to use the minimum of the two.

Thanks

Joris,

On Wed, Jan 7, 2009 at 9:13 PM, Thiago Macieira <thiago@kde.org> wrote:
> 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
>
>
>>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
>
>
 
>> 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