improve speed of installing from compress file by increase read buffer

This commit is contained in:
Chee Yee
2024-02-10 00:27:18 -08:00
parent f83629d107
commit 7a908ebf1b
6 changed files with 20 additions and 32 deletions
+3 -3
View File
@@ -786,7 +786,7 @@ namespace Actions
void *ExtractArchivePkg(void *argp)
{
ssize_t len;
char buffer[ARCHIVE_TRANSFER_SIZE];
char *buffer = (char*) malloc(ARCHIVE_TRANSFER_SIZE);
ArchivePkgInstallData *install_data = (ArchivePkgInstallData*) argp;
SplitFile *sp = install_data->split_file;
@@ -795,7 +795,7 @@ namespace Actions
sp->Open();
while (!install_data->stop_write_thread)
{
len = archive_read_data(install_data->archive_entry->archive, buffer, sizeof buffer);
len = archive_read_data(install_data->archive_entry->archive, buffer, ARCHIVE_TRANSFER_SIZE);
if (len == 0)
break;
@@ -814,7 +814,7 @@ namespace Actions
}
sp->Close();
free(buffer);
return NULL;
}
-23
View File
@@ -33,12 +33,6 @@ static bool s_bgft_initialized = false;
static std::map<std::string, ArchivePkgInstallData *> archive_pkg_install_data_list;
struct BackgroundArchiveInstallInfo
{
ArchivePkgInstallData *pkg_data;
std::string path;
};
namespace INSTALLER
{
int Init(void)
@@ -870,21 +864,4 @@ namespace INSTALLER
}
void *InstallArchivePkgThread(void *argp)
{
BackgroundArchiveInstallInfo *bg_install_info = (BackgroundArchiveInstallInfo*) argp;
InstallArchivePkg(bg_install_info->path , bg_install_info->pkg_data);
free(bg_install_info);
return NULL;
}
void StartInstallArchivePkg(const std::string &path, ArchivePkgInstallData* pkg_data)
{
BackgroundArchiveInstallInfo *bg_install_info = (BackgroundArchiveInstallInfo*) malloc(sizeof(BackgroundArchiveInstallInfo));
memset(bg_install_info, 0, sizeof(BackgroundArchiveInstallInfo));
bg_install_info->pkg_data = pkg_data;
bg_install_info->path = path;
int res = pthread_create(&bk_install_thid, NULL, InstallArchivePkgThread, bg_install_info);
}
}
-1
View File
@@ -149,5 +149,4 @@ namespace INSTALLER
void AddArchivePkgInstallData(const std::string &hash, ArchivePkgInstallData *pkg_data);
void RemoveArchivePkgInstallData(const std::string &hash);
bool InstallArchivePkg(const std::string &path, ArchivePkgInstallData* pkg_data);
void StartInstallArchivePkg(const std::string &path, ArchivePkgInstallData* pkg_data);
}
+8 -2
View File
@@ -1193,10 +1193,16 @@ namespace HttpServer
install_data->split_file = sp;
install_data->stop_write_thread = false;
int res = pthread_create(&install_data->thread, NULL, Actions::ExtractArchivePkg, install_data);
int ret = pthread_create(&install_data->thread, NULL, Actions::ExtractArchivePkg, install_data);
INSTALLER::InstallArchivePkg(entry->filename, install_data);
ret = INSTALLER::InstallArchivePkg(entry->filename, install_data);
free(entry);
if (ret == 0)
{
failed(res, 200, lang_strings[STR_FAIL_INSTALL_FROM_URL_MSG]);
return;
}
}
else
{
+8 -2
View File
@@ -288,29 +288,35 @@ namespace ZipUtil
static int extract2fd(struct archive *a, const std::string &pathname, int fd)
{
ssize_t len;
unsigned char buffer[ARCHIVE_TRANSFER_SIZE];
unsigned char *buffer = (unsigned char *) malloc(ARCHIVE_TRANSFER_SIZE);
/* loop over file contents and write to fd */
for (int n = 0;; n++)
{
len = archive_read_data(a, buffer, sizeof buffer);
len = archive_read_data(a, buffer, ARCHIVE_TRANSFER_SIZE);
if (len == 0)
{
free(buffer);
return 1;
}
if (len < 0)
{
sprintf(status_message, "error archive_read_data('%s')", pathname.c_str());
free(buffer);
return 0;
}
if (write(fd, buffer, len) != len)
{
sprintf(status_message, "error write('%s')", pathname.c_str());
free(buffer);
return 0;
}
}
free(buffer);
return 1;
}
+1 -1
View File
@@ -10,7 +10,7 @@
#include "common.h"
#include "fs.h"
#define ARCHIVE_TRANSFER_SIZE (512 * 1024)
#define ARCHIVE_TRANSFER_SIZE 5242880
static uint8_t MAGIC_ZIP_1[4] = {0x50, 0x4B, 0x03, 0x04};
static uint8_t MAGIC_ZIP_2[4] = {0x50, 0x4B, 0x05, 0x06};