Simple cache viewer: Add file read/write checks

master
Ansariel 2021-05-12 13:49:15 +02:00
parent 8d2ed39cf2
commit 438bced137
1 changed files with 27 additions and 19 deletions

View File

@ -162,7 +162,9 @@ S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType fi
BOOL LLFileSystem::read(U8* buffer, S32 bytes)
{
FSZoneC(tracy::Color::Gold); // <FS:Beq> measure cache performance
BOOL success = TRUE;
// <FS:Ansariel> Cache fixes
//BOOL success = TRUE;
BOOL success = FALSE;
std::string id;
mFileID.toString(id);
@ -197,14 +199,18 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes)
LLFILE* file = LLFile::fopen(filename, "rb");
if (file)
{
fseek(file, mPosition, SEEK_SET);
mBytesRead = fread(buffer, 1, bytes, file);
fclose(file);
mPosition += mBytesRead;
if (!mBytesRead)
if (fseek(file, mPosition, SEEK_SET) == 0)
{
success = FALSE;
mBytesRead = fread(buffer, 1, bytes, file);
fclose(file);
mPosition += mBytesRead;
// It probably would be correct to check for mBytesRead == bytes,
// but that will break avatar rezzing...
if (mBytesRead)
{
success = TRUE;
}
}
}
// </FS:Ansariel>
@ -295,10 +301,10 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes)
LLFILE* ofs = LLFile::fopen(filename, "a+b");
if (ofs)
{
fwrite(buffer, 1, bytes, ofs);
S32 bytes_written = fwrite(buffer, 1, bytes, ofs);
mPosition = ftell(ofs);
fclose(ofs);
success = TRUE;
success = (bytes_written == bytes);
}
}
else if (mMode == READ_WRITE)
@ -306,21 +312,23 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes)
LLFILE* ofs = LLFile::fopen(filename, "r+b");
if (ofs)
{
fseek(ofs, mPosition, SEEK_SET);
fwrite(buffer, 1, bytes, ofs);
mPosition = ftell(ofs);
fclose(ofs);
success = TRUE;
if (fseek(ofs, mPosition, SEEK_SET) == 0)
{
S32 bytes_written = fwrite(buffer, 1, bytes, ofs);
mPosition = ftell(ofs);
fclose(ofs);
success = (bytes_written == bytes);
}
}
else
{
ofs = LLFile::fopen(filename, "wb");
if (ofs)
{
fwrite(buffer, 1, bytes, ofs);
S32 bytes_written = fwrite(buffer, 1, bytes, ofs);
mPosition = ftell(ofs);
fclose(ofs);
success = TRUE;
success = (bytes_written == bytes);
}
}
}
@ -329,10 +337,10 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes)
LLFILE* ofs = LLFile::fopen(filename, "wb");
if (ofs)
{
fwrite(buffer, 1, bytes, ofs);
S32 bytes_written = fwrite(buffer, 1, bytes, ofs);
mPosition = ftell(ofs);
fclose(ofs);
success = TRUE;
success = (bytes_written == bytes);
}
}
// </FS:Ansariel>