Qt file resize behaves weirdly in Linux
-
Here is my code snippet
@QFile temfile(fileUrl);
if(temfile.open(QIODevice::WriteOnly) == false)
{
qDebug()<<"Unable to create file!";
return;
}
if(temfile.resize(5073741824) == false) // 5GB
{
qDebug()<<"Insufficient disk space!";
return;
}
temfile.close();@Now on Windows, if the NTFS filesystem has less than 5GB disk space, it displays
@Insufficient disk space!@
But on Linux (Ubuntu 12.10) the file is resized even if there is less space. On right click properties file size is even displayed as 5GB but it is not accounted for somehow. I can create as many 5GB files as I want due to which above code check fails.
When I start writing into file (suppose 200MB) only then the size is accounted for 200MB but displayed as 5GB.
Is there any solution for this? I want this to behave as it behaves on Windows.
-
Hi,
This is more an OS file handling problem rather than Qt's. There's not much it can do for that.
-
I suspect this is happening due to sparse file handling. http://en.wikipedia.org/wiki/Sparse_file
Off hand, I'm not sure how to prevent it other than by attempting to write.