void xa_tar_delete (XArchive *archive,GSList *files) { gchar *e_filename,*command = NULL; GSList *_files,*list = NULL; GString *names = g_string_new(""); _files = files; while (_files) { e_filename = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#"); g_string_prepend (names,e_filename); g_string_prepend_c (names,' '); _files = _files->next; } g_slist_foreach(files,(GFunc)g_free,NULL); g_slist_free(files); if (is_tar_compressed(archive->type)) xa_add_delete_bzip2_gzip_lzma_compressed_tar(names,archive,0); else { command = g_strconcat (tar, " --delete -vf ",archive->escaped_path," ",names->str,NULL); list = g_slist_append(list,command); xa_run_command (archive,list); if (archive->status == XA_ARCHIVESTATUS_DELETE) xa_reload_archive_content(archive); } }
void xa_arj_add (XArchive *archive,GString *files,gchar *compression_string) { GSList *list = NULL; gchar *command = NULL; if (archive->location_entry_path != NULL) archive->working_dir = g_strdup(archive->tmp); if (compression_string == NULL) compression_string = "1"; if (archive->passwd != NULL) command = g_strconcat ( "arj a ", archive->update ? "-u " : "", archive->freshen ? "-f " : "", archive->remove_files ? "-d1 " : "", "-g" , archive->passwd , " -i ", "-m",compression_string," ", archive->escaped_path,files->str,NULL); else command = g_strconcat ( "arj a ", archive->update ? "-u " : "", archive->freshen ? "-f " : "", archive->remove_files ? "-d1 " : "", " -i ", "-m",compression_string," ", archive->escaped_path,files->str,NULL); g_string_free(files,TRUE); list = g_slist_append(list,command); xa_run_command (archive,list); xa_reload_archive_content(archive); }
void xa_7zip_delete (XArchive *archive,GSList *names) { gchar *command,*exe,*e_filename = NULL; GSList *list = NULL,*_names; GString *files = g_string_new(""); if (sevenzr) exe = "7zr d "; if (sevenza) exe = "7za d "; _names = names; while (_names) { e_filename = xa_escape_filename((gchar*)_names->data,"$'`\"\\!?* ()[]&|:;<>#"); g_string_prepend (files,e_filename); g_string_prepend_c (files,' '); _names = _names->next; } g_slist_foreach(names,(GFunc)g_free,NULL); g_slist_free(names); command = g_strconcat (exe,archive->escaped_path," ",files->str,NULL); g_string_free(files,TRUE); list = g_slist_append(list,command); xa_run_command (archive,list); if (archive->status == XA_ARCHIVESTATUS_DELETE) xa_reload_archive_content(archive); }
gboolean xa_7zip_extract(XArchive *archive,GSList *files) { gchar *command,*e_filename = NULL; GSList *list = NULL,*_files = NULL; GString *names = g_string_new(""); gboolean result = FALSE; _files = files; while (_files) { e_filename = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#"); g_string_prepend (names,e_filename); g_string_prepend_c (names,' '); _files = _files->next; } g_slist_foreach(_files,(GFunc)g_free,NULL); g_slist_free(_files); if (archive->passwd != NULL) command = g_strconcat ("7za " , archive->full_path ? "x" : "e", " -p",archive->passwd, archive->overwrite ? " -aoa" : " -aos", " -bd ", archive->escaped_path,names->str , " -o",archive->extraction_path,NULL); else command = g_strconcat ( "7za " , archive->full_path ? "x" : "e", archive->overwrite ? " -aoa" : " -aos", " -bd ", archive->escaped_path,names->str , " -o",archive->extraction_path,NULL); g_string_free(names,TRUE); list = g_slist_append(list,command); result = xa_run_command (archive,list); return result; }
gboolean xa_rpm_extract(XArchive *archive,GSList *files) { gchar *command = NULL,*e_filename = NULL; GSList *list = NULL,*_files = NULL; GString *names = g_string_new(""); gboolean result = FALSE; _files = files; while (_files) { e_filename = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#"); g_string_prepend (names,e_filename); g_string_prepend_c (names,' '); _files = _files->next; } g_slist_foreach(files,(GFunc)g_free,NULL); g_slist_free(files); chdir (archive->extraction_path); command = g_strconcat ( "sh -c \"cpio -id" , names->str," < ",archive->tmp,"/file.cpio\"",NULL); g_string_free(names,TRUE); list = g_slist_append(list,command); result = xa_run_command (archive,list); return result; }
gboolean xa_deb_extract(XArchive *archive,GSList *files) { gchar *command; GSList *list = NULL,*_files = NULL; GString *names = g_string_new(""); gboolean result = FALSE; _files = files; while (_files) { g_string_prepend (names,(gchar*)_files->data); g_string_prepend_c (names,' '); _files = _files->next; } g_slist_foreach(files,(GFunc)g_free,NULL); g_slist_free(files); chdir (archive->extraction_path); command = g_strconcat ("ar x ",archive->escaped_path," ",names->str,NULL); if (command != NULL) { g_string_free(names,FALSE); list = g_slist_append(list,command); result = xa_run_command (archive,list); } return result; }
void xa_open_rpm (XArchive *archive) { unsigned short int i; int response; GSList *list = NULL; FILE *stream; gboolean result; signal (SIGPIPE, SIG_IGN); stream = fopen ( archive->path , "r" ); if (stream == NULL) { gchar *msg = g_strdup_printf (_("Can't open RPM file %s:") , archive->path); response = xa_show_message_dialog (GTK_WINDOW (xa_main_window) , GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK, msg,g_strerror(errno)); g_free (msg); return; } archive->can_extract = archive->has_properties = TRUE; archive->can_add = archive->has_sfx = archive->has_test = FALSE; archive->dummy_size = 0; archive->nr_of_files = 0; archive->nc = 8; archive->format ="RPM"; char *names[]= {(_("Points to")),(_("Size")),(_("Permission")),(_("Date")),(_("Hard Link")),(_("Owner")),(_("Group")),NULL}; GType types[]= {GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_POINTER}; archive->column_types = g_malloc0(sizeof(types)); for (i = 0; i < 10; i++) archive->column_types[i] = types[i]; xa_create_liststore (archive,names); /* Create a unique temp dir in /tmp */ result = xa_create_temp_directory (archive); if (!result) return; /* Now I run dd to have the bzip2 / gzip compressed cpio archive in /tmp */ gchar *command = g_strconcat ( "sh -c \"rpm2cpio ",archive->escaped_path," > ",archive->tmp, "/file.cpio\"",NULL); list = NULL; list = g_slist_append(list,command); result = xa_run_command (archive,list); if (result == FALSE) { gtk_widget_set_sensitive(Stop_button,FALSE); xa_set_button_state (1,1,1,1,archive->can_add,archive->can_extract,0,archive->has_test,archive->has_properties,archive->has_passwd,0); gtk_label_set_text(GTK_LABEL(total_label),""); return; } /* And finally cpio to receive the content */ command = g_strconcat ("sh -c \"cpio -tv < ",archive->tmp,"/file.cpio\"",NULL); archive->parse_output = xa_get_cpio_line_content; xa_spawn_async_process (archive,command); g_free(command); }
void xa_unar_test (XArchive *archive) { gchar *password_str, *command; password_str = xa_unar_password_str(archive); command = g_strconcat(archiver[archive->type].program[0], " -t", password_str, " ", archive->path[1], NULL); g_free(password_str); xa_run_command(archive, command); g_free(command); }
void xa_tar_delete (XArchive *archive, GSList *file_list) { GString *files; gchar *command; files = xa_quote_filenames(file_list, NULL, TRUE); command = g_strconcat(archiver[XARCHIVETYPE_TAR].program[0], " --delete --no-recursion --no-wildcards -f ", archive->path[2], files->str, NULL); if (archive->type != XARCHIVETYPE_TAR) { xa_run_command(archive, command); g_free(command); command = xa_gzip_et_al_get_command(archiver[xa_tar_get_compressor_type(archive)].program[0], archive->path[2], archive->path[0], archive->password, xa_tar_get_compressor_type(archive)); } g_string_free(files, TRUE); xa_run_command(archive, command); g_free(command); }
void xa_7zip_test (XArchive *archive) { gchar *command = NULL; GSList *list = NULL; archive->status = XA_ARCHIVESTATUS_TEST; if (archive->passwd != NULL) command = g_strconcat ( "7za t -p" , archive->passwd , " " , archive->escaped_path, NULL); else command = g_strconcat ("7za t " , archive->escaped_path, NULL); list = g_slist_append(list,command); xa_run_command (archive,list); }
void xa_arj_test (XArchive *archive) { gchar *command = NULL; GSList *list = NULL; archive->status = XA_ARCHIVESTATUS_TEST; if (archive->passwd != NULL) command = g_strconcat ("arj t -g" , archive->passwd , " -i " , archive->escaped_path, NULL); else command = g_strconcat (unarj ? "unarj t " : "arj t -i -y - ", archive->escaped_path, NULL); list = g_slist_append(list,command); xa_run_command (archive,list); }
gboolean xa_extract_tar_without_directories (gchar *string,XArchive *archive,gchar *files_to_extract) { gchar *command = NULL, *e_filename = NULL; GSList *list = NULL; GSList *files = NULL; GString *names = g_string_new(""); gboolean result; result = xa_create_temp_directory (archive); if (!result) return FALSE; if (strlen(files_to_extract) == 0) { gtk_tree_model_foreach(GTK_TREE_MODEL(archive->liststore),(GtkTreeModelForeachFunc) xa_concat_filenames,&files); while (files) { e_filename = xa_escape_filename((gchar*)files->data,"$'`\"\\!?* ()[]&|:;<>#"); g_string_prepend_c (names,' '); g_string_prepend (names,e_filename); files = files->next; } g_slist_foreach(files,(GFunc)g_free,NULL); g_slist_free(files); files_to_extract = names->str; } command = g_strconcat (string, archive->escaped_path, #ifdef __FreeBSD__ archive->overwrite ? " " : " -k", #else archive->overwrite ? " --overwrite" : " --keep-old-files", " --no-wildcards ", #endif archive->tar_touch ? " --touch" : "", "-C ",archive->tmp," ",files_to_extract,NULL); list = g_slist_append(list,command); if (strstr(files_to_extract,"/") || strcmp(archive->tmp,archive->extraction_path) != 0) { archive->working_dir = g_strdup(archive->tmp); command = g_strconcat ("mv -f ",files_to_extract," ",archive->extraction_path,NULL); list = g_slist_append(list,command); } g_string_free(names,TRUE); return xa_run_command (archive,list); }
gboolean xa_arj_extract(XArchive *archive,GSList *files) { gchar *command,*e_filename = NULL; GSList *list = NULL,*_files = NULL; GString *names = g_string_new(""); gboolean result = FALSE; _files = files; while (_files) { e_filename = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#"); g_string_prepend (names,e_filename); g_string_prepend_c (names,' '); _files = _files->next; } g_slist_foreach(_files,(GFunc)g_free,NULL); g_slist_free(_files); if (archive->passwd != NULL) command = g_strconcat ( "arj ",archive->full_path ? "x" : "e", " -g",archive->passwd, archive->overwrite ? "" : " -n" , " -i " , archive->freshen ? "-f " : "" , archive->update ? "-u " : " ", "-y ", archive->escaped_path , " ",archive->extraction_path,names->str,NULL); else { if (unarj) command = g_strconcat ( "sh -c \"cd ", archive->extraction_path, " && unarj ", archive->full_path ? "x" : "e", " ", archive->escaped_path, "\"", NULL ); else command = g_strconcat ( "arj ",archive->full_path ? "x" : "e", archive->overwrite ? "" : " -n" , " -i " , archive->freshen ? "-f " : "", archive->update ? "-u " : " ", "-y ", archive->escaped_path , " ",archive->extraction_path,names->str,NULL); } g_string_free(names,TRUE); list = g_slist_append(list,command); result = xa_run_command (archive,list); return result; }
void xa_rar_test (XArchive *archive) { gchar *rar = NULL; gchar *command = NULL; GSList *list = NULL; if (unrar) rar = "unrar"; else rar = "rar"; archive->status = XA_ARCHIVESTATUS_TEST; if (archive->passwd != NULL) command = g_strconcat (rar," t -idp -p" , archive->passwd ," " , archive->escaped_path, NULL); else command = g_strconcat (rar," t -idp " , archive->escaped_path, NULL); list = g_slist_append(list,command); xa_run_command (archive,list); }
void xa_7zip_add (XArchive *archive,GString *files,gchar *compression_string) { GSList *list = NULL; gchar *command,*exe = NULL; if (sevenzr) exe = "7zr "; if (sevenza) exe = "7za "; if (archive->location_entry_path != NULL) archive->working_dir = g_strdup(archive->tmp); if (compression_string == NULL) compression_string = "5"; if (archive->passwd != NULL) command = g_strconcat ( exe, archive->update ? "u " : "a ", archive->solid_archive ? "-ms=on " : "-ms=off ", "-p" , archive->passwd, " ", archive->escaped_path," ", "-mx=",compression_string,"", files->str,NULL); else command = g_strconcat ( exe, archive->update ? "u " : "a ", archive->solid_archive ? "-ms=on " : "-ms=off ", archive->escaped_path," ", "-mx=",compression_string,"", files->str,NULL); g_string_free(files,TRUE); list = g_slist_append(list,command); xa_run_command (archive,list); xa_reload_archive_content(archive); }
void xa_add_delete_bzip2_gzip_lzma_compressed_tar (GString *files,XArchive *archive,gboolean add) { gchar *command,*executable = NULL,*filename = NULL; gboolean result; GSList *list = NULL; switch (archive->type) { case XARCHIVETYPE_TAR_BZ2: executable = "bzip2 -f "; filename = "dummy.bz2"; break; case XARCHIVETYPE_TAR_GZ: executable = "gzip -f "; filename = "dummy.gz"; break; case XARCHIVETYPE_TAR_LZMA: executable = "lzma -f "; filename = "dummy.lzma"; break; case XARCHIVETYPE_TAR_LZOP: executable = "lzop -f "; filename = "dummy.lzo"; break; default: break; } /* Let's copy the archive to /tmp first */ result = xa_create_temp_directory(archive); if (!result) return; /* Let's copy the archive to /tmp first */ command = g_strconcat ("cp -a ",archive->escaped_path," ",archive->tmp,"/",filename,NULL); list = g_slist_append(list,command); command = g_strconcat (executable,"-d ",archive->tmp,"/",filename,NULL); list = g_slist_append(list,command); if (add) command = g_strconcat (tar, " ", archive->add_recurse ? "" : "--no-recursion ", archive->remove_files ? "--remove-files " : "", archive->update ? "-uvvf " : "-rvvf ", archive->tmp,"/dummy", files->str , NULL ); else command = g_strconcat (tar," --no-wildcards --delete -f ",archive->tmp,"/dummy ",files->str,NULL); list = g_slist_append(list,command); command = g_strconcat (executable,archive->tmp,"/dummy",NULL); list = g_slist_append(list,command); /* Let's move the modified archive from /tmp to the original archive location */ command = g_strconcat ("mv ",archive->tmp,"/",filename," ",archive->escaped_path,NULL); list = g_slist_append(list,command); xa_run_command (archive,list); if (archive->status == XA_ARCHIVESTATUS_DELETE || archive->status == XA_ARCHIVESTATUS_ADD) xa_reload_archive_content(archive); }
gboolean xa_tar_extract(XArchive *archive,GSList *files) { gchar *command,*e_filename = NULL; GSList *list = NULL,*_files = NULL; GString *names = g_string_new(""); gboolean result = FALSE; _files = files; while (_files) { e_filename = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#"); g_string_prepend_c (names,' '); g_string_prepend (names,e_filename); _files = _files->next; } g_slist_foreach(files,(GFunc)g_free,NULL); g_slist_free(files); switch (archive->type) { case XARCHIVETYPE_TAR: if (archive->full_path) { command = g_strconcat (tar, " -xvf " , archive->escaped_path, #ifdef __FreeBSD__ archive->overwrite ? " " : " -k", #else archive->overwrite ? " --overwrite" : " --keep-old-files", #endif archive->tar_touch ? " --touch" : "", " -C ",archive->extraction_path," ",names->str,NULL); } else { result = xa_extract_tar_without_directories ( "tar -xvf ",archive,names->str); command = NULL; } break; case XARCHIVETYPE_TAR_BZ2: if (archive->full_path) { command = g_strconcat (tar, " -xjvf " , archive->escaped_path, #ifdef __FreeBSD__ archive->overwrite ? " " : " -k", #else archive->overwrite ? " --overwrite" : " --keep-old-files", #endif archive->tar_touch ? " --touch" : "", " -C ",archive->extraction_path," ",names->str,NULL); } else { result = xa_extract_tar_without_directories ( "tar -xjvf ",archive,names->str); command = NULL; } break; case XARCHIVETYPE_TAR_GZ: if (archive->full_path == 1) { command = g_strconcat (tar, " -xzvf " , archive->escaped_path, #ifdef __FreeBSD__ archive->overwrite ? " " : " -k", #else archive->overwrite ? " --overwrite" : " --keep-old-files", #endif archive->tar_touch ? " --touch" : "", " -C ",archive->extraction_path," ",names->str,NULL); } else { result = xa_extract_tar_without_directories ( "tar -xzvf ",archive,names->str); command = NULL; } break; case XARCHIVETYPE_TAR_LZMA: if (archive->full_path == 1) { command = g_strconcat (tar, " --use-compress-program=lzma -xvf " , archive->escaped_path, #ifdef __FreeBSD__ archive->overwrite ? " " : " -k", #else archive->overwrite ? " --overwrite" : " --keep-old-files", #endif archive->tar_touch ? " --touch" : "", " -C ",archive->extraction_path," ",names->str,NULL); } else { result = xa_extract_tar_without_directories ( "tar --use-compress-program=lzma -xvf ",archive,names->str); command = NULL; } break; case XARCHIVETYPE_TAR_LZOP: if (archive->full_path == 1) { command = g_strconcat (tar, " --use-compress-program=lzop -xvf " , archive->escaped_path, #ifdef __FreeBSD__ archive->overwrite ? " " : " -k", #else archive->overwrite ? " --overwrite" : " --keep-old-files", #endif archive->tar_touch ? " --touch" : "", " -C ",archive->extraction_path," ",names->str,NULL); } else { result = xa_extract_tar_without_directories ( "tar --use-compress-program=lzop -xvf ",archive,names->str); command = NULL; } break; case XARCHIVETYPE_LZMA: result = lzma_bzip2_extract(archive,NULL); command = NULL; break; case XARCHIVETYPE_LZOP: result = lzma_bzip2_extract(archive,NULL); command = NULL; break; case XARCHIVETYPE_BZIP2: result = lzma_bzip2_extract(archive,NULL); command = NULL; break; case XARCHIVETYPE_GZIP: result = gzip_extract(archive,NULL); command = NULL; break; default: command = NULL; } if (command != NULL) { g_string_free(names,TRUE); list = g_slist_append(list,command); result = xa_run_command (archive,list); } return result; }
void xa_tar_add (XArchive *archive,GString *files,gchar *compression_string) { GSList *list = NULL; gchar *command = NULL; if (archive->location_entry_path != NULL) archive->working_dir = g_strdup(archive->tmp); switch (archive->type) { case XARCHIVETYPE_TAR: if ( g_file_test (archive->escaped_path,G_FILE_TEST_EXISTS)) command = g_strconcat (tar, " ", archive->add_recurse ? "" : "--no-recursion ", archive->remove_files ? "--remove-files " : "", archive->update ? "-uvvf " : "-rvvf ", archive->escaped_path, files->str , NULL ); else command = g_strconcat (tar, " ", archive->add_recurse ? "" : "--no-recursion ", archive->remove_files ? "--remove-files " : "", "-cvvf ",archive->escaped_path, files->str , NULL ); break; case XARCHIVETYPE_TAR_BZ2: if ( g_file_test ( archive->escaped_path , G_FILE_TEST_EXISTS ) ) xa_add_delete_bzip2_gzip_lzma_compressed_tar (files,archive,1); else command = g_strconcat (tar, " ", archive->add_recurse ? "" : "--no-recursion ", archive->remove_files ? "--remove-files " : "", "-cvvjf ",archive->escaped_path, files->str , NULL ); break; case XARCHIVETYPE_TAR_GZ: if ( g_file_test ( archive->escaped_path , G_FILE_TEST_EXISTS ) ) xa_add_delete_bzip2_gzip_lzma_compressed_tar (files,archive,1); else command = g_strconcat (tar, " ", archive->add_recurse ? "" : "--no-recursion ", archive->remove_files ? "--remove-files " : "", "-cvvzf ",archive->escaped_path, files->str , NULL ); break; case XARCHIVETYPE_TAR_LZMA: if ( g_file_test ( archive->escaped_path , G_FILE_TEST_EXISTS ) ) xa_add_delete_bzip2_gzip_lzma_compressed_tar (files,archive,1); else command = g_strconcat (tar, " ", archive->add_recurse ? "" : "--no-recursion ", archive->remove_files ? "--remove-files " : "", "--use-compress-program=lzma -cvvf ",archive->escaped_path, files->str , NULL ); break; case XARCHIVETYPE_TAR_LZOP: if ( g_file_test ( archive->escaped_path , G_FILE_TEST_EXISTS ) ) xa_add_delete_bzip2_gzip_lzma_compressed_tar (files,archive,1); else command = g_strconcat (tar, " ", archive->add_recurse ? "" : "--no-recursion ", archive->remove_files ? "--remove-files " : "", "--use-compress-program=lzop -cvvf ",archive->escaped_path, files->str , NULL ); break; case XARCHIVETYPE_BZIP2: command = g_strconcat("sh -c \"bzip2 -c ",files->str,"> ",archive->escaped_path,"\"",NULL); break; case XARCHIVETYPE_GZIP: command = g_strconcat("sh -c \"gzip -c ",files->str,"> ",archive->escaped_path,"\"",NULL); break; case XARCHIVETYPE_LZMA: command = g_strconcat("sh -c \"lzma -c ",files->str,"> ",archive->escaped_path,"\"",NULL); break; case XARCHIVETYPE_LZOP: command = g_strconcat("sh -c \"lzop -c ",files->str,"> ",archive->escaped_path,"\"",NULL); break; default: command = NULL; } if (command != NULL) { g_string_free(files,TRUE); list = g_slist_append(list,command); xa_run_command (archive,list); xa_reload_archive_content(archive); } }
static int xa_rpm2cpio (XArchive *archive) { unsigned char bytes[HDRSIG_ENTRY_INFO_LEN]; int datalen, entries; long offset; gchar *cpio_z, *ibs, *command, *executable; GSList *list; FILE *stream; signal(SIGPIPE, SIG_IGN); stream = fopen(archive->path, "r"); if (stream == NULL) { gchar *msg = g_strdup_printf(_("Can't open RPM file %s:"), archive->path); xa_show_message_dialog(GTK_WINDOW(xa_main_window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, msg, g_strerror(errno)); g_free(msg); return -1; } /* Signature section */ if (fseek(stream, SIGNATURE_START, SEEK_CUR) == -1) { fclose (stream); xa_show_message_dialog (GTK_WINDOW (xa_main_window),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't fseek to position 104:"),g_strerror(errno)); return -1; } if (fread(bytes, 1, HDRSIG_ENTRY_INFO_LEN, stream) != HDRSIG_ENTRY_INFO_LEN) { fclose ( stream ); xa_show_message_dialog (GTK_WINDOW (xa_main_window),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't read data from file:"),g_strerror(errno)); return -1; } entries = 256 * (256 * (256 * bytes[0] + bytes[1]) + bytes[2]) + bytes[3]; datalen = 256 * (256 * (256 * bytes[4] + bytes[5]) + bytes[6]) + bytes[7]; datalen += (16 - (datalen % 16)) % 16; // header section is aligned offset = HDRSIG_ENTRY_INDEX_LEN * entries + datalen; /* Header section */ if (fseek(stream, offset, SEEK_CUR)) { fclose (stream); xa_show_message_dialog (GTK_WINDOW (xa_main_window),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't fseek in file:"),g_strerror(errno)); return -1; } if (fread(bytes, 1, HDRSIG_ENTRY_INFO_LEN, stream) != HDRSIG_ENTRY_INFO_LEN) { fclose ( stream ); xa_show_message_dialog (GTK_WINDOW (xa_main_window),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't read data from file:"),g_strerror(errno)); return -1; } entries = 256 * (256 * (256 * bytes[0] + bytes[1]) + bytes[2]) + bytes[3]; datalen = 256 * (256 * (256 * bytes[4] + bytes[5]) + bytes[6]) + bytes[7]; offset = HDRSIG_ENTRY_INDEX_LEN * entries + datalen; offset += ftell(stream); // offset from top fclose(stream); /* create a unique temp dir in /tmp */ if (!xa_create_temp_directory(archive)) return -1; cpio_z = g_strconcat(archive->tmp, "/xa-tmp.cpio_z", NULL); ibs = g_strdup_printf("%lu", offset); /* run dd to have the payload (compressed cpio archive) in /tmp */ command = g_strconcat("dd if=", archive->escaped_path, " ibs=", ibs, " skip=1 of=", cpio_z, NULL); list = g_slist_append(NULL, command); g_free(ibs); if (!xa_run_command(archive, list)) { g_free(cpio_z); return -1; } switch (xa_detect_archive_type(cpio_z)) { case XARCHIVETYPE_GZIP: executable = "gzip -dc "; break; case XARCHIVETYPE_BZIP2: executable = "bzip2 -dc "; break; default: executable = "xz -dc "; break; } command = g_strconcat("sh -c \"", executable, cpio_z, " > ", archive->tmp, "/xa-tmp.cpio\"", NULL); list = g_slist_append(NULL, command); g_free(cpio_z); if (!xa_run_command(archive, list)) return 0; return 1; }