Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, May 2007
Determining case sensitivity of filesystem in Qt


Message 1 in thread

I wonder if there is any function in Qt that will tell me if the
filesystem is case-sensitive or not (something like
QDir::isOnCaseSensitiveFilesystem() ). I looked in QFile, QDir and
QFileInfo documentation, but I found no such function.

I may do some simple test like "if window then case insensitive, else
sensitive" but thay may not be perfect - in linux you can have fat32
case-insensitive partition mounted for example.

Is there some clean way to find case sensitivity of filesystem in Qt,
or do I have to resort to guesses by O.S.?

Martin Petricek

--
 [ signature omitted ] 

Message 2 in thread

BH schrieb:
> I wonder if there is any function in Qt that will tell me if the
> filesystem is case-sensitive or not (something like
> QDir::isOnCaseSensitiveFilesystem() ). I looked in QFile, QDir and
> QFileInfo documentation, but I found no such function.
> [...]

What about this:

bool isOnCaseSensitiveFilesystem (const QString &filename)
{
    QFileInfo   upperFI (filename.toUpper ());
    QFileInfo   lowerFI (filename.toLower ());

    return (upperFI == lowerFI);
}

However, this has some caveats:
- "filename" must exist
- "filename" must contain letters

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

-- 
 [ signature omitted ] 

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Message 3 in thread

Will this work on systems that have a mixture of case-sensitive and
case-insensitive mounts? Case sensitivity can change for different
directories.

Keith

On 05-09-2007 1:03 AM, "Rainer Wiesenfarth" wrote:

> BH schrieb:
>> I wonder if there is any function in Qt that will tell me if the
>> filesystem is case-sensitive or not (something like
>> QDir::isOnCaseSensitiveFilesystem() ). I looked in QFile, QDir and
>> QFileInfo documentation, but I found no such function.
>> [...]
> 
> What about this:
> 
> bool isOnCaseSensitiveFilesystem (const QString &filename)
> {
>     QFileInfo   upperFI (filename.toUpper ());
>     QFileInfo   lowerFI (filename.toLower ());
> 
>     return (upperFI == lowerFI);
> }
> 
> However, this has some caveats:
> - "filename" must exist
> - "filename" must contain letters
> 
> Best Regards / Mit freundlichen Grüßen
> Rainer Wiesenfarth


--
 [ signature omitted ] 

Message 4 in thread

Keith Esau schrieb:
> Will this work on systems that have a mixture of case-sensitive and
> case-insensitive mounts? Case sensitivity can change for different
> directories.

Probably yes. On Linux, file.dat != FILE.DAT on FAT filesystems. Try 
with a USB stick.

Martin

-- 
 [ signature omitted ] 

Message 5 in thread

On Wednesday 09 May 2007 02:37:46 BH wrote:
> I wonder if there is any function in Qt that will tell me if the
> filesystem is case-sensitive or not (something like
> QDir::isOnCaseSensitiveFilesystem() ). I looked in QFile, QDir and
> QFileInfo documentation, but I found no such function.
>
> I may do some simple test like "if window then case insensitive, else
> sensitive" but thay may not be perfect - in linux you can have fat32
> case-insensitive partition mounted for example.
>
> Is there some clean way to find case sensitivity of filesystem in Qt,
> or do I have to resort to guesses by O.S.?
>
> Martin Petricek

Try this:

    QFileInfo info(fileName);
    QFSFileEngine fe(fileInfo.absoluteFilePath());
    return fe.caseSensitive();

-Benjamin Meyer

--
 [ signature omitted ] 

Message 6 in thread

> 
> On Wednesday 09 May 2007 02:37:46 BH wrote:
> > I wonder if there is any function in Qt that will tell me if the
> > filesystem is case-sensitive or not (something like
> > QDir::isOnCaseSensitiveFilesystem() ). I looked in QFile, QDir and
> > QFileInfo documentation, but I found no such function.
> >
> > I may do some simple test like "if window then case insensitive,
else
> > sensitive" but thay may not be perfect - in linux you can have fat32
> > case-insensitive partition mounted for example.
> >
> > Is there some clean way to find case sensitivity of filesystem in
Qt,
> > or do I have to resort to guesses by O.S.?
> >
> > Martin Petricek
> 
> Try this:
> 
>     QFileInfo info(fileName);
>     QFSFileEngine fe(fileInfo.absoluteFilePath());
>     return fe.caseSensitive();
> 
> -Benjamin Meyer
> 
My only concern with this would be the comment in the doc...


"bool QAbstractFileEngine::caseSensitive () const   [virtual]
Should return true if the underlying file system is case-sensitive;
otherwise return false.

This virtual function must be reimplemented by all subclasses."

The "Should" worries me... however, it could be because it may be which
file systems are being mixed and matched, and how they are mixed and
match.

For instance, a Samba mount on linux to a windows box, may provide case
insensitivity to files on that mount (not sure... just speculating) or
it may be samba version dependent...

Also, NFS mounts from windows to linux may be client dependent or server
dependent...  

Who knows with windows to OSX or vice versa...  That could be the
"Should" portion.

Scott


--
 [ signature omitted ] 

Message 7 in thread

Hi,

> Who knows with windows to OSX or vice versa...  That could be the
> "Should" portion.

Only QFSFileEngine inherits QAbstractFileEngine. QFSFileEngine and especially 
caseSensitive() are implemented in platform-dependent files:
	src/corelib/io/qfsfileengine_win.cpp
	src/corelib/io/qfsfileengine_unix.cpp
Therefore if you find caseSensitive() doesn't work, it should be reported as a 
bug.

The "should" applies to filesystems that are not accessed through the regular 
OS API, for example a distant file-system accessed directly through SSH or FTP 
at the application level.

--
 [ signature omitted ] 

Message 8 in thread

On Wednesday 09 May 2007 09:34:36 Scott Aron Bloom wrote:
> > On Wednesday 09 May 2007 02:37:46 BH wrote:
> > > I wonder if there is any function in Qt that will tell me if the
> > > filesystem is case-sensitive or not (something like
> > > QDir::isOnCaseSensitiveFilesystem() ). I looked in QFile, QDir and
> > > QFileInfo documentation, but I found no such function.
> > >
> > > I may do some simple test like "if window then case insensitive,
>
> else
>
> > > sensitive" but thay may not be perfect - in linux you can have fat32
> > > case-insensitive partition mounted for example.
> > >
> > > Is there some clean way to find case sensitivity of filesystem in
>
> Qt,
>
> > > or do I have to resort to guesses by O.S.?
> > >
> > > Martin Petricek
> >
> > Try this:
> >
> >     QFileInfo info(fileName);
> >     QFSFileEngine fe(fileInfo.absoluteFilePath());
> >     return fe.caseSensitive();
> >
> > -Benjamin Meyer
>
> My only concern with this would be the comment in the doc...
>
>
> "bool QAbstractFileEngine::caseSensitive () const   [virtual]
> Should return true if the underlying file system is case-sensitive;
> otherwise return false.
>
> This virtual function must be reimplemented by all subclasses."
>
> The "Should" worries me... however, it could be because it may be which
> file systems are being mixed and matched, and how they are mixed and
> match.
>
> For instance, a Samba mount on linux to a windows box, may provide case
> insensitivity to files on that mount (not sure... just speculating) or
> it may be samba version dependent...
>
> Also, NFS mounts from windows to linux may be client dependent or server
> dependent...
>
> Who knows with windows to OSX or vice versa...  That could be the
> "Should" portion.
>
> Scott

Sorry yah I was mistaken, those functions today simply return true/false and 
don't do any file system checking.

-Benjamin Meyer

--
 [ signature omitted ] 

Message 9 in thread

Hi,

> Sorry yah I was mistaken, those functions today simply return true/false and 
> don't do any file system checking.

I think that's because it's supposed to work like that.

The only exception I know of is that on Windows the registry can be modified 
to make the OS case sensitive. However this functionality doesn't seem to be 
much used out there (I've heard many programs start not working properly if 
you do that) therefore it's currently not implemented in Qt.

--
 [ signature omitted ] 

Message 10 in thread

Yes, the QFSFileEngine::caseSensitive() is what I've been looking for,
though I've coded the thing not to rely on filesystem being case
sensitive or not in the meantime :)

On 5/9/07, Dimitri <dimitri@xxxxxxxxxxxxx> wrote:
...
> The only exception I know of is that on Windows the registry can be modified
> to make the OS case sensitive. However this functionality doesn't seem to be
> much used out there (I've heard many programs start not working properly if
> you do that) therefore it's currently not implemented in Qt.

If you mount ext2 using some driver (like ext2ifs) you can have local
case sensitive filesystem even on Windows. Though having in one
directory two filenames that differ only in case is usually a bad
practice, even on filesystems that allow it. I think the driver
somehow tries to emulate the case-insensitivity of windows filesystem,
but I'm not sure and different ext2 drivers may behave ...
differently.

Martin Petricek

--
 [ signature omitted ]