Browse Source

Remove .zip plugin file after extracting it

tags/v0.3.1
Andrew Belt 7 years ago
parent
commit
e8cc50b935
1 changed files with 29 additions and 14 deletions
  1. +29
    -14
      src/plugin.cpp

+ 29
- 14
src/plugin.cpp View File

@@ -124,17 +124,13 @@ void pluginDestroy() {
// CURL and libzip helpers // CURL and libzip helpers
//////////////////// ////////////////////



static void extractZip(const char *filename, const char *dir) {
static int extractZipHandle(zip_t *za, const char *dir) {
int err = 0; int err = 0;
zip_t *za = zip_open(filename, 0, &err);
if (!za) return;
if (err) goto cleanup;

for (int i = 0; i < zip_get_num_entries(za, 0); i++) { for (int i = 0; i < zip_get_num_entries(za, 0); i++) {
zip_stat_t zs; zip_stat_t zs;
err = zip_stat_index(za, i, 0, &zs); err = zip_stat_index(za, i, 0, &zs);
if (err) goto cleanup;
if (err)
return err;
int nameLen = strlen(zs.name); int nameLen = strlen(zs.name);


char path[MAXPATHLEN]; char path[MAXPATHLEN];
@@ -142,11 +138,13 @@ static void extractZip(const char *filename, const char *dir) {


if (zs.name[nameLen - 1] == '/') { if (zs.name[nameLen - 1] == '/') {
err = mkdir(path, 0755); err = mkdir(path, 0755);
if (err) goto cleanup;
if (err)
return err;
} }
else { else {
zip_file_t *zf = zip_fopen_index(za, i, 0); zip_file_t *zf = zip_fopen_index(za, i, 0);
if (!zf) goto cleanup;
if (!zf)
return 1;


FILE *outFile = fopen(path, "wb"); FILE *outFile = fopen(path, "wb");
if (!outFile) if (!outFile)
@@ -161,13 +159,26 @@ static void extractZip(const char *filename, const char *dir) {
} }


err = zip_fclose(zf); err = zip_fclose(zf);
assert(!err);
if (err)
return err;
fclose(outFile); fclose(outFile);
} }
} }
return 0;
}

static int extractZip(const char *filename, const char *dir) {
int err = 0;
zip_t *za = zip_open(filename, 0, &err);
if (!za)
return 1;

if (!err) {
err = extractZipHandle(za, dir);
}


cleanup:
zip_close(za); zip_close(za);
return err;
} }


//////////////////// ////////////////////
@@ -236,9 +247,13 @@ static void pluginRefreshPlugin(json_t *pluginJ) {
bool success = requestDownload(download, filename, &downloadProgress); bool success = requestDownload(download, filename, &downloadProgress);
if (success) { if (success) {
// Unzip file // Unzip file
extractZip(filename.c_str(), "plugins");
// Load plugin
loadPlugin(slug);
int err = extractZip(filename.c_str(), "plugins");
if (!err) {
// Load plugin
loadPlugin(slug);
// Delete zip
remove(filename.c_str());
}
} }


downloadName = ""; downloadName = "";


Loading…
Cancel
Save