static void fr_command_done (FrProcess *process, FrProcError *error, gpointer data) { FrCommand *comm = FR_COMMAND (data); comm->process->restart = FALSE; if (error->type != FR_PROC_ERROR_STOPPED) fr_command_handle_error (comm, error); if (comm->process->restart) { fr_process_start (comm->process); return; } if (comm->action == FR_ACTION_LISTING_CONTENT) { /* order the list by name to speed up search */ g_ptr_array_sort (comm->files, file_data_compare_by_path); } g_signal_emit (G_OBJECT (comm), fr_command_signals[DONE], 0, comm->action, error); }
static void fr_command_zip_delete (FrCommand *comm, const char *from_file, GList *file_list) { GList *scan; fr_process_set_out_line_func (FR_COMMAND (comm)->process, process_line__common, comm); fr_process_begin_command (comm->process, "zip"); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, comm->filename); for (scan = file_list; scan; scan = scan->next) { char *escaped; escaped = escape_str (scan->data, ZIP_SPECIAL_CHARACTERS); fr_process_add_arg (comm->process, escaped); g_free (escaped); } fr_process_end_command (comm->process); }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); FrCommandIso *comm_iso = FR_COMMAND_ISO (comm); char **fields; const char *name_field; g_return_if_fail (line != NULL); if (line[0] == 'd') /* Ignore directories. */ return; if (line[0] == 'D') { g_free (comm_iso->cur_path); comm_iso->cur_path = g_strdup (get_last_field (line, 4)); } else if (line[0] == '-') { /* Is file */ const char *last_field, *first_bracket; fdata = file_data_new (); fields = split_line (line, 8); fdata->size = g_ascii_strtoull (fields[4], NULL, 10); fdata->modified = mktime_from_string (fields[5], fields[6], fields[7]); g_strfreev (fields); /* Full path */ last_field = get_last_field (line, 9); first_bracket = strchr (last_field, ']'); if (first_bracket == NULL) { file_data_free (fdata); return; } name_field = eat_spaces (first_bracket + 1); if ((name_field == NULL) || (strcmp (name_field, ".") == 0) || (strcmp (name_field, "..") == 0)) { file_data_free (fdata); return; } if (comm_iso->cur_path[0] != '/') fdata->full_path = g_strstrip (g_strconcat ("/", comm_iso->cur_path, name_field, NULL)); else fdata->full_path = g_strstrip (g_strconcat (comm_iso->cur_path, name_field, NULL)); fdata->original_path = fdata->full_path; fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); fr_command_add_file (comm, fdata); } }
static void list_command_completed (gpointer data) { FrCommandUnarchiver *unar_comm = FR_COMMAND_UNARCHIVER (data); JsonParser *parser; GError *error = NULL; parser = json_parser_new (); if (json_parser_load_from_stream (parser, unar_comm->stream, NULL, &error)) { JsonObject *root; root = json_node_get_object (json_parser_get_root (parser)); if (json_object_get_int_member (root, "lsarFormatVersion") == LSAR_SUPPORTED_FORMAT) { JsonArray *content; int i; content = json_object_get_array_member (root, "lsarContents"); for (i = 0; i < json_array_get_length (content); i++) { JsonObject *entry; FileData *fdata; const char *filename; entry = json_array_get_object_element (content, i); fdata = file_data_new (); fdata->size = json_object_get_int_member (entry, "XADFileSize"); fdata->modified = mktime_from_string (json_object_get_string_member (entry, "XADLastModificationDate")); if (json_object_has_member (entry, "XADIsEncrypted")) fdata->encrypted = json_object_get_int_member (entry, "XADIsEncrypted") == 1; filename = json_object_get_string_member (entry, "XADFileName"); if (*filename == '/') { fdata->full_path = g_strdup (filename); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", filename, NULL); fdata->original_path = fdata->full_path + 1; } fdata->link = NULL; if (json_object_has_member (entry, "XADIsDirectory")) fdata->dir = json_object_get_int_member (entry, "XADIsDirectory") == 1; if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); fr_command_add_file (FR_COMMAND (unar_comm), fdata); } } } g_object_unref (parser); }
static void fr_command_cfile_list (FrCommand *comm) { FrCommandCFile *comm_cfile = FR_COMMAND_CFILE (comm); if (is_mime_type (comm->mime_type, "application/x-gzip")) { /* gzip let us known the uncompressed size */ fr_process_set_out_line_func (FR_COMMAND (comm)->process, list__process_line, comm); fr_process_begin_command (comm->process, "gzip"); fr_process_add_arg (comm->process, "-l"); fr_process_add_arg (comm->process, "-q"); fr_process_add_arg (comm->process, comm->filename); fr_process_end_command (comm->process); fr_process_start (comm->process); } else { /* ... other compressors do not support this feature so * simply use the archive size, suboptimal but there is no * alternative. */ FileData *fdata; char *filename; fdata = file_data_new (); filename = remove_extension_from_path (comm->filename); fdata->full_path = g_strconcat ("/", file_name_from_path (filename), NULL); g_free (filename); fdata->original_path = fdata->full_path + 1; fdata->link = NULL; fdata->size = get_file_size_for_path (comm->filename); fdata->modified = get_file_mtime_for_path (comm->filename); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); comm_cfile->error.type = FR_PROC_ERROR_NONE; comm_cfile->error.status = 0; g_signal_emit_by_name (G_OBJECT (comm), "done", comm->action, &comm_cfile->error); } }
static void fr_command_tar_add (FrCommand *comm, const char *from_file, GList *file_list, const char *base_dir, gboolean update, gboolean follow_links) { FrCommandTar *c_tar = FR_COMMAND_TAR (comm); GList *scan; fr_process_set_out_line_func (FR_COMMAND (comm)->process, process_line__add, comm); begin_tar_command (comm); fr_process_add_arg (comm->process, "--force-local"); fr_process_add_arg (comm->process, "--no-recursion"); fr_process_add_arg (comm->process, "--no-wildcards"); fr_process_add_arg (comm->process, "-v"); fr_process_add_arg (comm->process, "-p"); if (follow_links) fr_process_add_arg (comm->process, "-h"); if (base_dir != NULL) { fr_process_add_arg (comm->process, "-C"); fr_process_add_arg (comm->process, base_dir); } if (can_create_a_compressed_archive (comm)) { fr_process_add_arg (comm->process, "-cf"); fr_process_add_arg (comm->process, comm->filename); add_compress_arg (comm); } else { if (comm->creating_archive) fr_process_add_arg (comm->process, "-cf"); else fr_process_add_arg (comm->process, "-rf"); fr_process_add_arg (comm->process, c_tar->uncomp_filename); } if (from_file != NULL) { fr_process_add_arg (comm->process, "-T"); fr_process_add_arg (comm->process, from_file); } fr_process_add_arg (comm->process, "--"); if (from_file == NULL) for (scan = file_list; scan; scan = scan->next) fr_process_add_arg (comm->process, scan->data); fr_process_end_command (comm->process); }
static void fr_command_start (FrProcess *process, gpointer data) { FrCommand *comm = FR_COMMAND (data); g_signal_emit (G_OBJECT (comm), fr_command_signals[START], 0, comm->action); }
static void process_line (char *line, gpointer data) { GimvImageInfo *fdata = NULL; FRCommand *comm = FR_COMMAND (data); char **fields; char *name_field; char *filename; struct stat st; g_return_if_fail (line != NULL); fields = split_line (line, 5); memset (&st, 0, sizeof (struct stat)); st.st_size = atol (fields[2]); st.st_mtime = mktime_from_string (fields[3], fields[4]); mkugid_from_string (fields[1], &st.st_uid, &st.st_gid); st.st_mode = mkmode_from_string (fields[0]); g_strfreev (fields); /* Full path */ name_field = get_last_field (line); fields = g_strsplit (name_field, " -> ", 2); if (!fields[1]) { g_strfreev (fields); fields = g_strsplit (name_field, " link to ", 2); } if (*(fields[0]) == '/') { filename = fields[0] + 1; } else { filename = fields[0]; } if (*filename && *comm->filename) { fdata = gimv_image_info_get_with_archive (filename, FR_ARCHIVE (comm->archive), &st); } if (fdata) { if (fields[1]) gimv_image_info_set_link (fdata, fields[1]); comm->file_list = g_list_prepend (comm->file_list, fdata); } g_strfreev (fields); }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); g_return_if_fail (line != NULL); if (strlen (line) == 0) return; if (! g_str_has_prefix (line, "Decompressed file size:")) return; fdata = file_data_new (); fdata->size = g_ascii_strtoull (_g_str_get_last_field (line, 4), NULL, 10); struct stat st; if (stat (comm->filename, &st) == 0) fdata->modified = st.st_mtim.tv_sec; else time(&(fdata->modified)); fdata->encrypted = FALSE; char *new_fname = g_strdup (_g_path_get_basename (comm->filename)); if (g_str_has_suffix (new_fname, ".lrz")) new_fname[strlen (new_fname) - 4] = '\0'; if (*new_fname == '/') { fdata->full_path = g_strdup (new_fname); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", new_fname, NULL); fdata->original_path = fdata->full_path + 1; } fdata->path = _g_path_remove_level (fdata->full_path); fdata->name = new_fname; fdata->dir = FALSE; fdata->link = NULL; if (fdata->name == 0) file_data_free (fdata); else fr_archive_add_file (FR_ARCHIVE (comm), fdata); }
static void process_line__common (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); if (line == NULL) return; fr_command_message (comm, line); if (comm->n_files != 0) { double fraction = (double) ++comm->n_file / (comm->n_files + 1); fr_command_progress (comm, fraction); } }
static void process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; const char *name_field; g_return_if_fail (line != NULL); fdata = file_data_new (); fields = split_line_lha (line); fdata->size = g_ascii_strtoull (fields[2], NULL, 10); fdata->modified = mktime_from_string (fields[4], fields[5], fields[6]); g_strfreev (fields); /* Full path */ name_field = get_last_field_lha (line); if (name_field && *name_field == '/') { fdata->full_path = g_strdup (name_field); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name_field, NULL); fdata->original_path = fdata->full_path + 1; } fdata->link = NULL; fdata->dir = line[0] == 'd'; if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void fr_command_zip_add (FrCommand *comm, const char *from_file, GList *file_list, const char *base_dir, gboolean update, gboolean recursive) { GList *scan; fr_process_set_out_line_func (FR_COMMAND (comm)->process, process_line__common, comm); fr_process_begin_command (comm->process, "zip"); if (base_dir != NULL) fr_process_set_working_dir (comm->process, base_dir); /* preserve links. */ fr_process_add_arg (comm->process, "-y"); if (update) fr_process_add_arg (comm->process, "-u"); add_password_arg (comm, comm->password); switch (comm->compression) { case FR_COMPRESSION_VERY_FAST: fr_process_add_arg (comm->process, "-1"); break; case FR_COMPRESSION_FAST: fr_process_add_arg (comm->process, "-3"); break; case FR_COMPRESSION_NORMAL: fr_process_add_arg (comm->process, "-6"); break; case FR_COMPRESSION_MAXIMUM: fr_process_add_arg (comm->process, "-9"); break; } fr_process_add_arg (comm->process, comm->filename); fr_process_add_arg (comm->process, "--"); for (scan = file_list; scan; scan = scan->next) fr_process_add_arg (comm->process, scan->data); fr_process_end_command (comm->process); }
static void fr_command_zip_extract (FrCommand *comm, const char *from_file, GList *file_list, const char *dest_dir, gboolean overwrite, gboolean skip_older, gboolean junk_paths) { GList *scan; fr_process_set_out_line_func (FR_COMMAND (comm)->process, process_line__common, comm); fr_process_begin_command (comm->process, "unzip"); if (dest_dir != NULL) { fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, dest_dir); } if (overwrite) fr_process_add_arg (comm->process, "-o"); else fr_process_add_arg (comm->process, "-n"); if (skip_older) fr_process_add_arg (comm->process, "-u"); if (junk_paths) fr_process_add_arg (comm->process, "-j"); add_password_arg (comm, comm->password); fr_process_add_arg (comm->process, "--"); fr_process_add_arg (comm->process, comm->filename); for (scan = file_list; scan; scan = scan->next) { char *escaped; escaped = escape_str (scan->data, ZIP_SPECIAL_CHARACTERS); fr_process_add_arg (comm->process, escaped); g_free (escaped); } fr_process_end_command (comm->process); }
static void list__process_line (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); FileData *fdata; char **fields; char *filename; fdata = file_data_new (); fields = split_line (line, 2); if (strcmp (fields[1], "-1") != 0) fdata->size = g_ascii_strtoull (fields[1], NULL, 10); g_strfreev (fields); if (fdata->size == 0) fdata->size = get_file_size (comm->filename); filename = get_uncompressed_name_from_archive (comm, comm->filename); if (filename == NULL) filename = remove_extension_from_path (comm->filename); fdata->full_path = g_strconcat ("/", file_name_from_path (filename), NULL); g_free (filename); fdata->original_path = fdata->full_path + 1; fdata->link = NULL; fdata->modified = get_file_mtime_for_path (comm->filename); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void process_line__add (char *line, gpointer data) { FrCommand *command = FR_COMMAND (data); FrArchive *archive = FR_ARCHIVE (data); if ((archive->volume_size > 0) && (strncmp (line, "Creating archive ", 17) == 0)) { char *volume_filename; GFile *volume_file; volume_filename = g_strconcat (command->filename, ".001", NULL); volume_file = g_file_new_for_path (volume_filename); fr_archive_set_multi_volume (archive, volume_file); g_object_unref (volume_file); g_free (volume_filename); } if (fr_archive_progress_get_total_files (archive) > 0) parse_progress_line (archive, "Compressing ", _("Adding \"%s\""), line); }
static void process_line__extract (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); FrArchive *archive = FR_ARCHIVE (comm); FrCommandUnarchiver *unar_comm = FR_COMMAND_UNARCHIVER (comm); if (line == NULL) return; unar_comm->n_line++; /* the first line is the name of the archive */ if (unar_comm->n_line == 1) return; if (fr_archive_progress_get_total_files (archive) > 1) fr_archive_progress (archive, fr_archive_progress_inc_completed_files (archive, 1)); else fr_archive_message (archive, line); }
static void process_line__generic (char *line, gpointer data, char *message_format) { FrCommand *comm = FR_COMMAND (data); FrArchive *archive = FR_ARCHIVE (comm); if (line == NULL) return; if (line[strlen (line) - 1] == '/') /* ignore directories */ return; if (fr_archive_progress_get_total_files (archive) > 1) { fr_archive_progress (archive, fr_archive_progress_inc_completed_files (archive, 1)); } else { char *msg = g_strdup_printf (message_format, _g_path_get_basename (line), NULL); fr_archive_message (archive, msg); g_free (msg); } }
static void process_line__extract (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); FrCommandUnarchiver *unar_comm = FR_COMMAND_UNARCHIVER (comm); if (line == NULL) return; unar_comm->n_line++; /* the first line is the name of the archive */ if (unar_comm->n_line == 1) return; if (comm->n_files > 1) { double fraction = (double) ++comm->n_file / (comm->n_files + 1); fr_command_progress (comm, CLAMP (fraction, 0.0, 1.0)); } else fr_command_message (comm, line); }
static void process_line__generic (char *line, gpointer data, char *action_msg) { FrCommand *comm = FR_COMMAND (data); char *msg; if (line == NULL) return; if (line[strlen (line) - 1] == '/') /* ignore directories */ return; msg = g_strconcat (action_msg, file_name_from_path (line), NULL); fr_command_message (comm, msg); g_free (msg); if (comm->n_files != 0) { double fraction = (double) ++comm->n_file / (comm->n_files + 1); fr_command_progress (comm, fraction); } }
static void fr_command_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { FrCommand *comm; comm = FR_COMMAND (object); switch (prop_id) { case PROP_PROCESS: g_value_set_object (value, comm->process); break; case PROP_FILE: g_value_take_object (value, g_file_new_for_path (comm->filename)); break; case PROP_MIME_TYPE: g_value_set_static_string (value, comm->mime_type); break; case PROP_PASSWORD: g_value_set_string (value, comm->password); break; case PROP_ENCRYPT_HEADER: g_value_set_boolean (value, comm->encrypt_header); break; case PROP_COMPRESSION: g_value_set_enum (value, comm->compression); break; case PROP_VOLUME_SIZE: g_value_set_uint (value, comm->volume_size); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void fr_command_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { FrCommand *comm; comm = FR_COMMAND (object); switch (prop_id) { case PROP_PROCESS: fr_command_set_process (comm, g_value_get_object (value)); break; case PROP_FILE: fr_command_set_file (comm, g_value_get_object (value)); break; case PROP_MIME_TYPE: fr_command_set_mime_type (comm, g_value_get_string (value)); break; case PROP_PASSWORD: g_free (comm->password); comm->password = g_strdup (g_value_get_string (value)); break; case PROP_ENCRYPT_HEADER: comm->encrypt_header = g_value_get_boolean (value); break; case PROP_COMPRESSION: comm->compression = g_value_get_enum (value); break; case PROP_VOLUME_SIZE: comm->volume_size = g_value_get_uint (value); break; default: break; } }
static void process_data_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; char **tmfields; struct tm tm = {0, }; const char *name; g_return_if_fail (line != NULL); if (line[0] == ' ') { /* This is the output of dpkg-deb -I */ process_metadata_line (line, comm); return; } fdata = file_data_new (); fields = split_line (line, 5); fdata->size = g_ascii_strtoull (fields[2], NULL, 10); tmfields = g_strsplit(fields[3], "-", 3); if (tmfields[2]) { tm.tm_year = atoi (tmfields[0]) - 1900; tm.tm_mon = atoi (tmfields[1]); tm.tm_mday = atoi (tmfields[2]); } g_strfreev (tmfields); tmfields = g_strsplit (fields[4], ":", 2); if (tmfields[1]) { tm.tm_hour = atoi (tmfields[0]); tm.tm_min = atoi (tmfields[1]); } g_strfreev (tmfields); fdata->modified = mktime (&tm); g_strfreev (fields); name = get_last_field (line, 6); fields = g_strsplit (name, " -> ", 2); fdata->dir = line[0] == 'd'; name = fields[0]; if (g_str_has_prefix (name, "./")) { /* Should generally be the case */ fdata->full_path = g_strdup (name + 1); fdata->original_path = fdata->full_path + 1; } else if (name[0] == '/') { fdata->full_path = g_strdup (name); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name, NULL); fdata->original_path = fdata->full_path + 1; } if (fdata->dir && (name[strlen (name) - 1] != '/')) { char *old_full_path = fdata->full_path; fdata->full_path = g_strconcat (old_full_path, "/", NULL); g_free (old_full_path); fdata->original_path = g_strdup (name); fdata->free_original_path = TRUE; } if (fields[1] != NULL) fdata->link = g_strdup (fields[1]); g_strfreev (fields); if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static char * get_uncompressed_name (FrCommandTar *c_tar, const char *e_filename) { FrCommand *comm = FR_COMMAND (c_tar); FrArchive *archive = FR_ARCHIVE (comm); char *new_name = g_strdup (e_filename); int l = strlen (new_name); if (_g_mime_type_matches (archive->mime_type, "application/x-compressed-tar")) { /* X.tgz --> X.tar * X.tar.gz --> X.tar */ if (_g_filename_has_extension (e_filename, ".tgz")) { new_name[l - 2] = 'a'; new_name[l - 1] = 'r'; } else if (_g_filename_has_extension (e_filename, ".tar.gz")) new_name[l - 3] = 0; } else if (_g_mime_type_matches (archive->mime_type, "application/x-bzip-compressed-tar")) { /* X.tbz2 --> X.tar * X.tar.bz2 --> X.tar */ if (_g_filename_has_extension (e_filename, ".tbz2")) { new_name[l - 3] = 'a'; new_name[l - 2] = 'r'; new_name[l - 1] = 0; } else if (_g_filename_has_extension (e_filename, ".tar.bz2")) new_name[l - 4] = 0; } else if (_g_mime_type_matches (archive->mime_type, "application/x-tarz")) { /* X.taz --> X.tar * X.tar.Z --> X.tar */ if (_g_filename_has_extension (e_filename, ".taz")) new_name[l - 1] = 'r'; else if (_g_filename_has_extension (e_filename, ".tar.Z")) new_name[l - 2] = 0; } else if (_g_mime_type_matches (archive->mime_type, "application/x-lrzip-compressed-tar")) { /* X.tlrz --> X.tar * X.tar.lrz --> X.tar */ if (_g_filename_has_extension (e_filename, ".tlrz")) { new_name[l - 3] = 'a'; new_name[l - 2] = 'r'; new_name[l - 1] = 0; } else if (_g_filename_has_extension (e_filename, ".tar.lrz")) new_name[l - 4] = 0; } else if (_g_mime_type_matches (archive->mime_type, "application/x-lzip-compressed-tar")) { /* X.tlz --> X.tar * X.tar.lz --> X.tar */ if (_g_filename_has_extension (e_filename, ".tlz")) { new_name[l - 2] = 'a'; new_name[l - 1] = 'r'; } else if (_g_filename_has_extension (e_filename, ".tar.lz")) new_name[l - 3] = 0; } else if (_g_mime_type_matches (archive->mime_type, "application/x-lzma-compressed-tar")) { /* X.tar.lzma --> X.tar * (There doesn't seem to be a shorthand suffix) */ if (_g_filename_has_extension (e_filename, ".tar.lzma")) new_name[l - 5] = 0; } else if (_g_mime_type_matches (archive->mime_type, "application/x-xz-compressed-tar")) { /* X.tar.xz --> X.tar * (There doesn't seem to be a shorthand suffix) */ if (_g_filename_has_extension (e_filename, ".tar.xz")) new_name[l - 3] = 0; } else if (_g_mime_type_matches (archive->mime_type, "application/x-lzop-compressed-tar")) { /* X.tzo --> X.tar * X.tar.lzo --> X.tar */ if (_g_filename_has_extension (e_filename, ".tzo")) { new_name[l - 2] = 'a'; new_name[l - 1] = 'r'; } else if (_g_filename_has_extension (e_filename, ".tar.lzo")) new_name[l - 4] = 0; } else if (_g_mime_type_matches (archive->mime_type, "application/x-7z-compressed-tar")) { /* X.tar.7z --> X.tar */ if (_g_filename_has_extension (e_filename, ".tar.7z")) new_name[l - 3] = 0; } return new_name; }
static void list__process_line (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); FrCommandArj *arj_comm = FR_COMMAND_ARJ (comm); g_return_if_fail (line != NULL); if (! arj_comm->list_started) { if (strncmp (line, "--------", 8) == 0) { arj_comm->list_started = TRUE; arj_comm->line_no = 1; } return; } if (strncmp (line, "--------", 8) == 0) { arj_comm->list_started = FALSE; return; } if (g_regex_match (arj_comm->filename_line_regex, line, 0, NULL)) { /* Read the filename. */ FileData *fdata; const char *name_field; arj_comm->line_no = 1; arj_comm->fdata = fdata = file_data_new (); name_field = get_last_field (line, 2); if (*name_field == '/') { fdata->full_path = g_strdup (name_field); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name_field, NULL); fdata->original_path = fdata->full_path + 1; } fdata->link = NULL; fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); } else if (arj_comm->line_no == 2) { /* Read file size and date. */ FileData *fdata; char **fields; fdata = arj_comm->fdata; /* read file info. */ fields = split_line (line, 10); fdata->size = g_ascii_strtoull (fields[2], NULL, 10); fdata->modified = mktime_from_string (fields[5], fields[6]); if ((strcmp (fields[1], "MS-DOS") == 0) || (strcmp (fields[1], "WIN32") == 0)) fdata->encrypted = (g_ascii_strcasecmp (fields[7], "11") == 0); else fdata->encrypted = (g_ascii_strcasecmp (fields[9], "11") == 0); g_strfreev (fields); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); arj_comm->fdata = NULL; } arj_comm->line_no++; }
static void process_line (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); FrCommandUnstuff *unstuff_comm = FR_COMMAND_UNSTUFF (comm); const char *str_start; char *filename, *real_filename; int i; FileData *fdata; g_return_if_fail (line != NULL); if (strstr (line, "progressEvent - ")) { const char *ssize; guint size; ssize = strstr (line, "progressEvent - ") + strlen ("progressEvent - "); if (ssize[0] == '\0') size = 0; else size = g_ascii_strtoull (ssize, NULL, 10); if (unstuff_comm->fdata != NULL) unstuff_comm->fdata->size = size; return; } if (strstr (line, "fileEvent") == NULL) return; if (strstr (line, unstuff_comm->target_dir + 1) == NULL) return; /* Look for the filename, ends with a comma */ str_start = strstr (line, unstuff_comm->target_dir + 1); str_start = str_start + strlen (unstuff_comm->target_dir) - 1; if (str_start[0] != '/') str_start--; if (str_start[0] == '.') str_start--; i = 0; while (str_start[i] != '\0' && str_start[i] != ',') { i++; } /* This is not supposed to happen */ g_return_if_fail (str_start[i] != '\0'); filename = g_strndup (str_start, i); /* Same thing with the real filename */ str_start = strstr (line, unstuff_comm->target_dir); i = 0; while (str_start[i] != '\0' && str_start[i] != ',') { i++; } real_filename = g_strndup (str_start, i); fdata = file_data_new (); fdata->full_path = filename; fdata->original_path = filename; fdata->link = NULL; fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); fdata->size = 0; fdata->modified = time (NULL); unstuff_comm->fdata = fdata; fr_command_add_file (comm, fdata); unlink (real_filename); g_free (real_filename); }
static void process_line (char *line, gpointer data) { FileData *fdata; FrCommandAce *ace_comm = FR_COMMAND_ACE (data); FrCommand *comm = FR_COMMAND (data); char **fields = NULL; const char *field_name = NULL; g_return_if_fail (line != NULL); if (ace_comm->command_type == FR_ACE_COMMAND_UNKNOWN) { if (g_str_has_prefix (line, "UNACE")) { if (strstr (line, "public version") != NULL) ace_comm->command_type = FR_ACE_COMMAND_PUBLIC; else ace_comm->command_type = FR_ACE_COMMAND_NONFREE; } return; } if (! ace_comm->list_started) { if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) { if (g_str_has_prefix (line, "Date")) ace_comm->list_started = TRUE; } else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE) { if (g_str_has_prefix (line, " Date")) ace_comm->list_started = TRUE; } return; } fdata = file_data_new (); if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) fields = g_strsplit (line, "|", 6); else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE) fields = split_line (line, 5); if ((fields == NULL) || (fields[0] == NULL) || (n_fields (fields) < 5)) return; fdata->size = g_ascii_strtoull (fields[3], NULL, 10); fdata->modified = mktime_from_string (fields[0], fields[1]); if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) { field_name = fields[5]; field_name = field_name + 1; } else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE) field_name = get_last_field (line, 6); g_assert (field_name != NULL); if (field_name[0] != '/') { fdata->full_path = g_strconcat ("/", field_name, NULL); fdata->original_path = fdata->full_path + 1; } else { fdata->full_path = g_strdup (field_name); fdata->original_path = fdata->full_path; } g_strfreev (fields); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; int date_idx; char *field_date, *field_time, *field_size, *field_name; char *name; g_return_if_fail (line != NULL); date_idx = _g_line_get_index_from_pattern (line, "%n%n%n%n-%n%n-%n%n %n%n:%n%n"); if (date_idx < 0) return; fdata = file_data_new (); field_size = _g_line_get_prev_field (line, date_idx, 1); fdata->size = g_ascii_strtoull (field_size, NULL, 10); g_free (field_size); field_date = _g_line_get_next_field (line, date_idx, 1); field_time = _g_line_get_next_field (line, date_idx, 2); fdata->modified = mktime_from_string (field_date, field_time); g_free (field_date); g_free (field_time); /* Full path */ field_name = tar_get_last_field (line, date_idx, 3); fields = g_strsplit (field_name, " -> ", 2); if (fields[1] == NULL) { g_strfreev (fields); fields = g_strsplit (field_name, " link to ", 2); } name = g_strcompress (fields[0]); if (*name == '/') { fdata->full_path = g_strdup (name); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name, NULL); fdata->original_path = fdata->full_path + 1; } g_free (name); name = g_filename_from_utf8 (fdata->original_path, -1, NULL, NULL, NULL); if (name) fdata->original_path = name; if (fields[1] != NULL) fdata->link = g_strdup (fields[1]); g_strfreev (fields); g_free (field_name); fdata->dir = line[0] == 'd'; if (fdata->dir) fdata->name = _g_path_get_dir_name (fdata->full_path); else fdata->name = g_strdup (_g_path_get_basename (fdata->full_path)); fdata->path = _g_path_remove_level (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_archive_add_file (FR_ARCHIVE (comm), fdata); }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; const char *name_field; char *name; int ofs = 0; g_return_if_fail (line != NULL); fdata = file_data_new (); #ifdef __sun fields = split_line (line, 9); fdata->size = g_ascii_strtoull (fields[4], NULL, 10); fdata->modified = mktime_from_string (fields[5], fields[6], fields[8]); g_strfreev (fields); name_field = get_last_field (line, 10); #else /* !__sun */ /* Handle char and block device files */ if ((line[0] == 'c') || (line[0] == 'b')) { fields = split_line (line, 9); ofs = 1; fdata->size = 0; /* FIXME: We should also specify the content type */ } else { fields = split_line (line, 8); fdata->size = g_ascii_strtoull (fields[4], NULL, 10); } fdata->modified = mktime_from_string (fields[5+ofs], fields[6+ofs], fields[7+ofs]); g_strfreev (fields); name_field = get_last_field (line, 9+ofs); #endif /* !__sun */ fields = g_strsplit (name_field, " -> ", 2); if (fields[1] == NULL) { g_strfreev (fields); fields = g_strsplit (name_field, " link to ", 2); } fdata->dir = line[0] == 'd'; name = g_strcompress (fields[0]); if (*(fields[0]) == '/') { fdata->full_path = g_strdup (name); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name, NULL); fdata->original_path = fdata->full_path + 1; } if (fdata->dir && (name[strlen (name) - 1] != '/')) { char *old_full_path = fdata->full_path; fdata->full_path = g_strconcat (old_full_path, "/", NULL); g_free (old_full_path); fdata->original_path = g_strdup (name); fdata->free_original_path = TRUE; } g_free (name); if (fields[1] != NULL) fdata->link = g_strcompress (fields[1]); g_strfreev (fields); if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; int date_idx; char *field_month, *field_day, *field_time, *field_year; char *field_size, *field_name; g_return_if_fail (line != NULL); fdata = file_data_new (); date_idx = file_list__get_index_from_pattern (line, "%c%c%c %a%n %n%n:%n%n %n%n%n%n"); field_size = file_list__get_prev_field (line, date_idx, 1); fdata->size = g_ascii_strtoull (field_size, NULL, 10); g_free (field_size); field_month = file_list__get_next_field (line, date_idx, 1); field_day = file_list__get_next_field (line, date_idx, 2); field_time = file_list__get_next_field (line, date_idx, 3); field_year = file_list__get_next_field (line, date_idx, 4); fdata->modified = mktime_from_string (field_time, field_day, field_month, field_year); g_free (field_day); g_free (field_month); g_free (field_year); g_free (field_time); /* Full path */ field_name = ar_get_last_field (line, date_idx, 5); fields = g_strsplit (field_name, " -> ", 2); if (fields[0] == NULL) { g_strfreev (fields); g_free (field_name); file_data_free (fdata); return; } if (fields[1] == NULL) { g_strfreev (fields); fields = g_strsplit (field_name, " link to ", 2); } if (*(fields[0]) == '/') { fdata->full_path = g_strdup (fields[0]); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", fields[0], NULL); fdata->original_path = fdata->full_path + 1; } if (fields[1] != NULL) fdata->link = g_strdup (fields[1]); g_strfreev (fields); g_free (field_name); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; const char *name_field; gint line_l; g_return_if_fail (line != NULL); /* check whether unzip gave the empty archive warning. */ if (FR_COMMAND_ZIP (comm)->is_empty) return; line_l = strlen (line); if (line_l == 0) return; if (strcmp (line, EMPTY_ARCHIVE_WARNING) == 0) { FR_COMMAND_ZIP (comm)->is_empty = TRUE; return; } /* ignore lines that do not describe a file or a * directory. */ if ((line[0] != '?') && (line[0] != 'd') && (line[0] != '-')) return; /**/ fdata = file_data_new (); fields = split_line (line, 7); fdata->size = g_ascii_strtoull (fields[3], NULL, 10); fdata->modified = mktime_from_string (fields[6]); fdata->encrypted = (*fields[4] == 'B') || (*fields[4] == 'T'); g_strfreev (fields); /* Full path */ name_field = get_last_field (line, 8); if (*name_field == '/') { fdata->full_path = g_strdup (name_field); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name_field, NULL); fdata->original_path = fdata->full_path + 1; } fdata->link = NULL; fdata->dir = line[0] == 'd'; if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }