Commit e4db2f5c authored by Drake Arconis's avatar Drake Arconis
Browse files

Make LLAPRFile able to handle large file io properly

parent 2738def2
......@@ -295,7 +295,7 @@ apr_status_t LLAPRFile::close()
return ret ;
}
apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool, S32* sizep)
apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool, apr_off_t* sizep)
{
apr_status_t s ;
......@@ -317,12 +317,12 @@ apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, LLV
}
else if (sizep)
{
S32 file_size = 0;
apr_off_t file_size = 0;
apr_off_t offset = 0;
if (apr_file_seek(mFile, APR_END, &offset) == APR_SUCCESS)
{
llassert_always(offset <= 0x7fffffff);
file_size = (S32)offset;
file_size = (apr_off_t)offset;
offset = 0;
apr_file_seek(mFile, APR_SET, &offset);
}
......@@ -375,7 +375,7 @@ apr_pool_t* LLAPRFile::getAPRFilePool(apr_pool_t* pool)
}
// File I/O
S32 LLAPRFile::read(void *buf, S32 nbytes)
apr_size_t LLAPRFile::read(void *buf, apr_size_t nbytes)
{
if(!mFile)
{
......@@ -392,12 +392,12 @@ S32 LLAPRFile::read(void *buf, S32 nbytes)
}
else
{
llassert_always(sz <= 0x7fffffff);
return (S32)sz;
//llassert_always(sz <= 0x7fffffff);
return (apr_size_t)sz;
}
}
S32 LLAPRFile::write(const void *buf, S32 nbytes)
apr_size_t LLAPRFile::write(const void *buf, apr_size_t nbytes)
{
if(!mFile)
{
......@@ -414,12 +414,12 @@ S32 LLAPRFile::write(const void *buf, S32 nbytes)
}
else
{
llassert_always(sz <= 0x7fffffff);
return (S32)sz;
//llassert_always(sz <= 0x7fffffff);
return (apr_size_t)sz;
}
}
S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset)
apr_off_t LLAPRFile::seek(apr_seek_where_t where, apr_off_t offset)
{
return LLAPRFile::seek(mFile, where, offset) ;
}
......@@ -469,7 +469,7 @@ apr_file_t* LLAPRFile::open(const std::string& filename, LLVolatileAPRPool* pool
}
//static
S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset)
apr_off_t LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, apr_off_t offset)
{
if(!file_handle)
{
......@@ -496,12 +496,12 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset)
else
{
llassert_always(apr_offset <= 0x7fffffff);
return (S32)apr_offset;
return (apr_off_t)apr_offset;
}
}
//static
S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
apr_size_t LLAPRFile::readEx(const std::string& filename, void *buf, apr_off_t offset, apr_size_t nbytes, LLVolatileAPRPool* pool)
{
//*****************************************
apr_file_t* file_handle = open(filename, pool, APR_READ|APR_BINARY);
......@@ -533,18 +533,18 @@ S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nb
}
else
{
llassert_always(bytes_read <= 0x7fffffff);
//llassert_always(bytes_read <= 0x7fffffff);
}
}
//*****************************************
close(file_handle, pool) ;
//*****************************************
return (S32)bytes_read;
return (apr_size_t)bytes_read;
}
//static
S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
apr_size_t LLAPRFile::writeEx(const std::string& filename, void *buf, apr_off_t offset, apr_size_t nbytes, LLVolatileAPRPool* pool)
{
apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY;
if (offset < 0)
......@@ -583,7 +583,7 @@ S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 n
}
else
{
llassert_always(bytes_written <= 0x7fffffff);
//llassert_always(bytes_written <= 0x7fffffff);
}
}
......@@ -591,7 +591,7 @@ S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 n
LLAPRFile::close(file_handle, pool);
//*****************************************
return (S32)bytes_written;
return (apr_size_t)bytes_written;
}
//static
......@@ -653,7 +653,7 @@ bool LLAPRFile::isExist(const std::string& filename, LLVolatileAPRPool* pool, ap
}
//static
S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool)
apr_off_t LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool)
{
apr_file_t* apr_file;
apr_finfo_t info;
......@@ -677,7 +677,7 @@ S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool)
if (s == APR_SUCCESS)
{
return (S32)info.size;
return (apr_off_t)info.size;
}
else
{
......
......@@ -166,17 +166,17 @@ public:
LLAPRFile(const LLAPRFile&) = delete;
LLAPRFile& operator=(const LLAPRFile&) = delete;
apr_status_t open(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool = nullptr, S32* sizep = nullptr);
apr_status_t open(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool = nullptr, apr_off_t* sizep = nullptr);
apr_status_t open(const std::string& filename, apr_int32_t flags, BOOL use_global_pool); //use gAPRPoolp.
apr_status_t close() ;
// Returns actual offset, -1 if seek fails
S32 seek(apr_seek_where_t where, S32 offset);
apr_off_t seek(apr_seek_where_t where, apr_off_t offset);
apr_status_t eof() { return apr_file_eof(mFile);}
// Returns bytes read/written, 0 if read/write fails:
S32 read(void* buf, S32 nbytes);
S32 write(const void* buf, S32 nbytes);
apr_size_t read(void* buf, apr_size_t nbytes);
apr_size_t write(const void* buf, apr_size_t nbytes);
apr_file_t* getFileHandle() {return mFile;}
......@@ -193,19 +193,19 @@ public:
private:
static apr_file_t* open(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags);
static apr_status_t close(apr_file_t* file, LLVolatileAPRPool* pool) ;
static S32 seek(apr_file_t* file, apr_seek_where_t where, S32 offset);
static apr_off_t seek(apr_file_t* file, apr_seek_where_t where, apr_off_t offset);
public:
// returns false if failure:
static bool remove(const std::string& filename, LLVolatileAPRPool* pool = nullptr);
static bool rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool = nullptr);
static bool isExist(const std::string& filename, LLVolatileAPRPool* pool = nullptr, apr_int32_t flags = APR_READ);
static S32 size(const std::string& filename, LLVolatileAPRPool* pool = nullptr);
static apr_off_t size(const std::string& filename, LLVolatileAPRPool* pool = nullptr);
static bool makeDir(const std::string& dirname, LLVolatileAPRPool* pool = nullptr);
static bool removeDir(const std::string& dirname, LLVolatileAPRPool* pool = nullptr);
// Returns bytes read/written, 0 if read/write fails:
static S32 readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = nullptr);
static S32 writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = nullptr); // offset<0 means append
static apr_size_t readEx(const std::string& filename, void *buf, apr_off_t offset, apr_size_t nbytes, LLVolatileAPRPool* pool = nullptr);
static apr_size_t writeEx(const std::string& filename, void *buf, apr_off_t offset, apr_size_t nbytes, LLVolatileAPRPool* pool = nullptr); // offset<0 means append
//*******************************************************************************************************************************
};
......
......@@ -2098,11 +2098,10 @@ bool LLImageFormatted::load(const std::string &filename, int load_size)
{
resetLastError();
S32 file_size = 0;
LLAPRFile infile ;
infile.open(filename, LL_APR_RB, nullptr, &file_size);
apr_file_t* apr_file = infile.getFileHandle();
if (!apr_file)
apr_off_t file_size = 0;
LLAPRFile infile;
apr_status_t s = infile.open(filename, LL_APR_RB, nullptr, &file_size);
if (s != APR_SUCCESS)
{
setLastError("Unable to open file for reading", filename);
return false;
......@@ -2120,9 +2119,8 @@ bool LLImageFormatted::load(const std::string &filename, int load_size)
}
bool res;
U8 *data = allocateData(load_size);
apr_size_t bytes_read = load_size;
apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
if (s != APR_SUCCESS || (S32) bytes_read != load_size)
apr_size_t bytes_read = infile.read(data, load_size);
if (bytes_read == 0 || bytes_read != load_size)
{
deleteData();
setLastError("Unable to read file",filename);
......
......@@ -41,7 +41,7 @@ bool LLImageDimensionsInfo::load(const std::string& src_filename,U32 codec)
mSrcFilename = src_filename;
S32 file_size = 0;
apr_off_t file_size = 0;
apr_status_t s = mInfile.open(src_filename, LL_APR_RB, nullptr, &file_size);
if (s != APR_SUCCESS)
......
......@@ -354,11 +354,10 @@ bool LLImageJ2C::loadAndValidate(const std::string &filename)
resetLastError();
S32 file_size = 0;
LLAPRFile infile ;
infile.open(filename, LL_APR_RB, nullptr, &file_size);
apr_file_t* apr_file = infile.getFileHandle() ;
if (!apr_file)
apr_off_t file_size = 0;
LLAPRFile infile;
apr_status_t s = infile.open(filename, LL_APR_RB, nullptr, &file_size);
if (s != APR_SUCCESS)
{
setLastError("Unable to open file for reading", filename);
res = false;
......@@ -371,11 +370,10 @@ bool LLImageJ2C::loadAndValidate(const std::string &filename)
else
{
U8 *data = (U8*)ll_aligned_malloc_16(file_size);
apr_size_t bytes_read = file_size;
apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
infile.close() ;
apr_size_t bytes_read = infile.read(data, (apr_size_t) file_size);
infile.close();
if (s != APR_SUCCESS || (S32)bytes_read != file_size)
if ((bytes_read == 0) || (bytes_read != (apr_size_t) file_size))
{
ll_aligned_free_16(data);
setLastError("Unable to read entire file");
......
......@@ -2081,7 +2081,7 @@ void LLVFS::dumpFiles()
LLVFSFileSpecifier file_spec = it->first;
LLVFSFileBlock *file_block = it->second;
S32 length = file_block->mLength;
S32 size = file_block->mSize;
apr_size_t size = (apr_size_t)file_block->mSize;
if (length != BLOCK_LENGTH_INVALID && size > 0)
{
LLUUID id = file_spec.mFileID;
......
......@@ -196,12 +196,12 @@ BOOL LLFloaterBvhPreview::postBuild()
// loading a bvh file
// now load bvh file
S32 file_size;
apr_off_t file_size;
LLAPRFile infile ;
infile.open(mFilenameAndPath, LL_APR_RB, nullptr, &file_size);
apr_status_t s = infile.open(mFilenameAndPath, LL_APR_RB, nullptr, &file_size);
if (!infile.getFileHandle())
if (s != APR_SUCCESS)
{
LL_WARNS() << "Can't open BVH file:" << mFilename << LL_ENDL;
}
......
......@@ -428,10 +428,10 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile()
LLBVHLoader* loaderp = nullptr;
LLAPRFile infile;
S32 file_size;
apr_off_t file_size;
infile.open(getFileName(), LL_APR_RB, nullptr, &file_size);
if (!infile.getFileHandle())
apr_status_t s = infile.open(getFileName(), LL_APR_RB, nullptr, &file_size);
if (s != APR_SUCCESS)
{
LL_WARNS() << "Can't open BVH file:" << getFileName() << LL_ENDL;
}
......@@ -521,10 +521,10 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile()
setAssetType(assetType);
// copy this file into the vfs for upload
S32 file_size;
apr_off_t file_size;
LLAPRFile infile;
infile.open(filename, LL_APR_RB, NULL, &file_size);
if (infile.getFileHandle())
apr_status_t s = infile.open(filename, LL_APR_RB, NULL, &file_size);
if (s == APR_SUCCESS)
{
LLVFile file(gVFS, getAssetId(), assetType, LLVFile::WRITE);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment