void Path::decompress(const std::string& compressedfilepath, const std::string& directorypath) { namespace fs = boost::filesystem; namespace fe = boost::system; fs::path path(directorypath); if (fs::exists(path) and fs::is_directory(path)) { #if BOOST_VERSION > 104500 fe::error_code ec; fs::current_path(path, ec); if (fs::current_path() == path) { extract_archive(compressedfilepath.c_str(), directorypath.c_str()); } #else try { fs::current_path(path); if (fs::current_path() == path) { extract_archive(compressedfilepath.c_str(), directorypath.c_str()); } } catch (const std::exception &e) { throw utils::InternalError(fmt(_("Failed de extract archive: %1%")) % e.what()); } #endif } }
int vt_mode_extract(struct vt_options* opt) { int error = 0; unsigned int input_file; for (input_file = 0; input_file < opt->input_files_count; input_file++) { vaht_archive* archive = vaht_archive_open(opt->input_files[input_file]); if (archive == NULL) { vt_error(opt, "file \"%s\" is not a valid MHK archive", opt->input_files[input_file]); return 1; } vt_log(opt, "extracting %s ...", opt->input_files[input_file]); char* out = opt->output; if (out == NULL) { out = "."; } /* create "out" */ if (create_directory(opt, out)) return 1; /* special handling if output provided, only one archive */ if (opt->output != NULL && opt->input_files_count == 1) { if (create_directory(opt, out)) { vaht_archive_close(archive); return 1; } error = extract_archive(opt, archive, out); } else { char* newout = construct_output_path(opt, out, opt->input_files[input_file]); if (create_directory(opt, newout)) { free(newout); vaht_archive_close(archive); return 1; } error = extract_archive(opt, archive, newout); free(newout); } vaht_archive_close(archive); if (error) break; } return error; }
static char *unarchive(struct gzip_handle *src_stream, FILE * out_stream, file_header_t * (*get_headers) (struct gzip_handle *), void (*free_headers) (file_header_t *), const int extract_function, const char *prefix, const char **extract_names, int *err) { file_header_t *file_entry; int extract_flag; int i; char *buffer = NULL; *err = 0; archive_offset = 0; while ((file_entry = get_headers(src_stream)) != NULL) { extract_flag = TRUE; if (extract_names != NULL) { int found_flag = FALSE; char *p = file_entry->name; if (p[0] == '.' && p[1] == '/') p += 2; for (i = 0; extract_names[i] != 0; i++) { if (strcmp(extract_names[i], p) == 0) { found_flag = TRUE; break; } } if (extract_function & extract_exclude_list) { if (found_flag == TRUE) { extract_flag = FALSE; } } else { /* If its not found in the include list dont extract it */ if (found_flag == FALSE) { extract_flag = FALSE; } } } if (extract_flag == TRUE) { buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix, err); *err = 0; /* XXX: ignore extraction errors */ if (*err) { free_headers(file_entry); break; } } else { /* seek past the data entry */ seek_forward(src_stream, file_entry->size); } free_headers(file_entry); } return buffer; }
static int do_command(ProgramMode mode, char *filename, LHAOptions *options, char **filters, unsigned int num_filters) { FILE *fstream; LHAInputStream *stream; LHAReader *reader; LHAFilter filter; int result; if (!strcmp(filename, "-")) { fstream = stdin; } else { fstream = fopen(filename, "rb"); if (fstream == NULL) { fprintf(stderr, "LHa: Error: %s %s\n", filename, strerror(errno)); exit(-1); } } stream = lha_input_stream_from_FILE(fstream); reader = lha_reader_new(stream); lha_filter_init(&filter, reader, filters, num_filters); result = 1; switch (mode) { case MODE_LIST: list_file_basic(&filter, options, fstream); break; case MODE_LIST_VERBOSE: list_file_verbose(&filter, options, fstream); break; case MODE_CRC_CHECK: result = test_file_crc(&filter, options); break; case MODE_EXTRACT: result = extract_archive(&filter, options); break; case MODE_UNKNOWN: break; } lha_reader_free(reader); lha_input_stream_free(stream); fclose(fstream); return result; }
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *), const int extract_function, const char *prefix, char **extract_names) { file_header_t *file_entry; int extract_flag; int i; char *buffer = NULL; archive_offset = 0; while ((file_entry = get_headers(src_stream)) != NULL) { extract_flag = TRUE; if (extract_names != NULL) { int found_flag = FALSE; for(i = 0; extract_names[i] != 0; i++) { if (strcmp(extract_names[i], file_entry->name) == 0) { found_flag = TRUE; break; } } if (extract_function & extract_exclude_list) { if (found_flag == TRUE) { extract_flag = FALSE; } } else { /* If its not found in the include list dont extract it */ if (found_flag == FALSE) { extract_flag = FALSE; } } } if (extract_flag == TRUE) { buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix); } else { /* seek past the data entry */ seek_sub_file(src_stream, file_entry->size); } free(file_entry->name); /* may be null, but doesn't matter */ free(file_entry->link_name); free(file_entry); } return(buffer); }
package* load_package(std::string path) { extract_archive(path, std::string("./temp/")); package* pkg = new package; std::ifstream description("./temp/DESCRIPTION"); std::getline(description, pkg->description); // licencja może być wielolinijkowa, póki co nie jest to obsługiwane std::ifstream licence("./temp/LICENCE"); std::getline(licence, pkg->licence); std::ifstream version("./temp/VERSION"); std::getline(version, pkg->version); std::ifstream name("./temp/NAME"); std::getline(name, pkg->name); std::ifstream dependencies("./temp/DEPENDENCIES"); std::string dep; while(std::getline(dependencies, dep)) pkg->dependencies.push_back(dep); std::ifstream files("./temp/INSTALL"); std::string ins; while(std::getline(files, ins)) { std::string::iterator eq_sign = std::find(ins.begin(), ins.end(), '='); std::string::iterator eq_sign_min1 = eq_sign - 1; std::string::iterator eq_sign_plus2 = eq_sign + 2; std::string file = std::string(ins.begin(), eq_sign_min1); std::string destination = std::string(eq_sign_plus2, ins.end()); pkg->files.push_back(make_pair(file, destination)); } return pkg; }
GFile * fetch_archive (const gchar *url, const gchar *sha, const gchar *module_name, GFile *destination, guint strip_components, GError **error) { g_autoptr(GFile) archive_file = NULL; g_autoptr(GFile) source_dir = NULL; g_autoptr(SoupURI) uri = NULL; g_autofree char *archive_name = NULL; GError *local_error = NULL; source_dir = g_file_get_child (destination, module_name); if (!g_file_make_directory_with_parents (source_dir, NULL, &local_error)) { if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { g_propagate_error (error, local_error); return NULL; } g_error_free (local_error); } uri = soup_uri_new (url); archive_name = g_path_get_basename (soup_uri_get_path (uri)); archive_file = g_file_get_child (source_dir, archive_name); if (!download_archive (uri, sha, archive_file, error)) return NULL; if (!extract_archive (source_dir, archive_file, strip_components, error)) return NULL; return g_steal_pointer (&source_dir); }
/** * Extract the archive stored at the given @path. This function * returns -1 if an error occurred, otherwise 0. */ int extract_archive_from_file(const char *path) { struct archive *archive = NULL; CallbackData *data = NULL; int status2; int status; archive = archive_read_new(); if (archive == NULL) { note(NULL, ERROR, INTERNAL, "can't initialize archive structure"); status = -1; goto end; } status = archive_read_support_format_cpio(archive); if (status != ARCHIVE_OK) { note(NULL, ERROR, INTERNAL, "can't set archive format: %s", archive_error_string(archive)); status = -1; goto end; } status = archive_read_support_format_gnutar(archive); if (status != ARCHIVE_OK) { note(NULL, ERROR, INTERNAL, "can't set archive format: %s", archive_error_string(archive)); status = -1; goto end; } status = archive_read_support_filter_gzip(archive); if (status != ARCHIVE_OK) { note(NULL, ERROR, INTERNAL, "can't add archive filter: %s", archive_error_string(archive)); status = -1; goto end; } status = archive_read_support_filter_lzop(archive); if (status != ARCHIVE_OK) { note(NULL, ERROR, INTERNAL, "can't add archive filter: %s", archive_error_string(archive)); status = -1; goto end; } data = talloc_zero(NULL, CallbackData); if (data == NULL) { note(NULL, ERROR, INTERNAL, "can't allocate callback data"); status = -1; goto end; } data->path = talloc_strdup(data, path); if (data->path == NULL) { note(NULL, ERROR, INTERNAL, "can't allocate callback data path"); status = -1; goto end; } status = archive_read_open(archive, data, open_callback, read_callback, close_callback); if (status != ARCHIVE_OK) { /* Don't complain if no error message were registered, * ie. when testing for a self-extracting archive. */ if (archive_error_string(archive) != NULL) note(NULL, ERROR, INTERNAL, "can't read archive: %s", archive_error_string(archive)); status = -1; goto end; } status = extract_archive(archive); end: if (archive != NULL) { status2 = archive_read_close(archive); if (status2 != ARCHIVE_OK) { note(NULL, WARNING, INTERNAL, "can't close archive: %s", archive_error_string(archive)); } status2 = archive_read_free(archive); if (status2 != ARCHIVE_OK) { note(NULL, WARNING, INTERNAL, "can't free archive: %s", archive_error_string(archive)); } } TALLOC_FREE(data); return status; }