diff --git a/indra/llfilesystem/llfilesystem.cpp b/indra/llfilesystem/llfilesystem.cpp index 6d3b7511a5..8e1d4f12b6 100644 --- a/indra/llfilesystem/llfilesystem.cpp +++ b/indra/llfilesystem/llfilesystem.cpp @@ -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); // measure cache performance - BOOL success = TRUE; + // 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; + } } } // @@ -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); } } //