fix random crash when installing with disk cache or pkgs in zip files
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ add_executable(ezremote_client
|
||||
|
||||
add_self(ezremote_client)
|
||||
|
||||
add_pkg(ezremote_client ${CMAKE_SOURCE_DIR}/data "RMTC00001" "ezRemote Client" "01.39" 32 0)
|
||||
add_pkg(ezremote_client ${CMAKE_SOURCE_DIR}/data "RMTC00001" "ezRemote Client" "01.40" 32 0)
|
||||
|
||||
target_link_libraries(ezremote_client
|
||||
c
|
||||
|
||||
+38
-6
@@ -56,7 +56,10 @@ size_t SplitFile::Read(char *buf, size_t buf_size, size_t offset)
|
||||
while ((block_num >= this->file_blocks.size() && !this->complete) ||
|
||||
(block_num < this->file_blocks.size() && this->file_blocks[block_num]->status == BLOCK_STATUS_NOT_EXISTS))
|
||||
{
|
||||
sem_wait(&this->block_ready);
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec += 2;
|
||||
sem_timedwait(&this->block_ready, &ts);
|
||||
}
|
||||
|
||||
block = this->file_blocks[block_num];
|
||||
@@ -120,7 +123,10 @@ size_t SplitFile::Read(char *buf, size_t buf_size, size_t offset)
|
||||
while ((block_num > this->file_blocks.size() - 1 && !this->complete) ||
|
||||
this->file_blocks[block_num]->status == BLOCK_STATUS_NOT_EXISTS)
|
||||
{
|
||||
sem_wait(&this->block_ready);
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec += 2;
|
||||
sem_timedwait(&this->block_ready, &ts);
|
||||
}
|
||||
|
||||
block = this->file_blocks[block_num];
|
||||
@@ -128,7 +134,7 @@ size_t SplitFile::Read(char *buf, size_t buf_size, size_t offset)
|
||||
|
||||
// delete blocks before the first read offset block. Assumuption, that reads are always
|
||||
// forward and won't read previously already read blocks. For safety, keeping only current block and 2 previous blocks
|
||||
for (int j=0; j < first_block_num - 2; j++)
|
||||
for (int j=0; j < first_block_num - 13; j++)
|
||||
{
|
||||
if (this->file_blocks[j]->status == BLOCK_STATUS_CREATED)
|
||||
{
|
||||
@@ -142,12 +148,13 @@ size_t SplitFile::Read(char *buf, size_t buf_size, size_t offset)
|
||||
}
|
||||
}
|
||||
|
||||
this->read_offset = offset + total_bytes_read;
|
||||
return total_bytes_read;
|
||||
}
|
||||
|
||||
size_t SplitFile::Write(char *buf, size_t buf_size)
|
||||
{
|
||||
size_t bytes_written;
|
||||
size_t bytes_written = 0;
|
||||
size_t block_space_remaining;
|
||||
size_t bytes_to_write;
|
||||
|
||||
@@ -155,6 +162,9 @@ size_t SplitFile::Write(char *buf, size_t buf_size)
|
||||
size_t total_bytes_written = 0;
|
||||
size_t remaining_to_write = buf_size;
|
||||
|
||||
if (this->IsClosed())
|
||||
return -1;
|
||||
|
||||
while (remaining_to_write > 0 && !this->complete)
|
||||
{
|
||||
block_space_remaining = this->block_size - block_in_progress->size;
|
||||
@@ -186,6 +196,7 @@ size_t SplitFile::Write(char *buf, size_t buf_size)
|
||||
block_in_progress = NewBlock();
|
||||
}
|
||||
}
|
||||
this->write_offset += total_bytes_written;
|
||||
|
||||
return total_bytes_written;
|
||||
}
|
||||
@@ -195,6 +206,8 @@ int SplitFile::Close()
|
||||
if (this->complete)
|
||||
return 0;
|
||||
|
||||
this->complete = true;
|
||||
|
||||
if (block_in_progress->fd != nullptr)
|
||||
{
|
||||
fflush(block_in_progress->fd);
|
||||
@@ -204,9 +217,28 @@ int SplitFile::Close()
|
||||
block_in_progress->status = BLOCK_STATUS_CREATED;
|
||||
block_in_progress->is_last = true;
|
||||
this->file_blocks.push_back(block_in_progress);
|
||||
this->complete = true;
|
||||
sem_post(&this->block_ready);
|
||||
|
||||
// Wait until file is fully read, if file isn't full read
|
||||
// in 5 mins then go ahead and delete all file chunks
|
||||
int retries = 10;
|
||||
size_t prev_read_offset = 0;
|
||||
while (this->read_offset != this->write_offset && retries > 0)
|
||||
{
|
||||
if (prev_read_offset == this->read_offset)
|
||||
retries--;
|
||||
prev_read_offset = this->read_offset;
|
||||
sceKernelUsleep(1000000);
|
||||
}
|
||||
sceKernelUsleep(5000000);
|
||||
|
||||
for (size_t j = 0; j < this->file_blocks.size(); j++)
|
||||
{
|
||||
if (this->file_blocks[j] != nullptr && this->file_blocks[j]->status == BLOCK_STATUS_CREATED)
|
||||
{
|
||||
remove(this->file_blocks[j]->block_file.c_str());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -226,4 +258,4 @@ FileBlock *SplitFile::NewBlock()
|
||||
block->fd = fopen(block->block_file.c_str(), "w");
|
||||
|
||||
return block;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <semaphore.h>
|
||||
#include <pthread.h>
|
||||
|
||||
enum FileBlockStatus
|
||||
@@ -35,8 +36,9 @@ public:
|
||||
|
||||
private:
|
||||
std::vector<FileBlock*> file_blocks;
|
||||
size_t write_offset;
|
||||
size_t write_offset = 0;
|
||||
size_t block_size;
|
||||
size_t read_offset;
|
||||
std::string path;
|
||||
int write_error;
|
||||
bool complete;
|
||||
@@ -46,4 +48,4 @@ private:
|
||||
FileBlock *NewBlock();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user