Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list archive contents: lzop #230

Closed
wants to merge 9 commits into from
99 changes: 94 additions & 5 deletions src/fr-command-cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ list__process_line_lzop(char *line,
if (strncmp (line, "Method ", 7) == 0 || strncmp (line, "------ ", 7) == 0)
return;

printf("parsed line: %s\n", line);
FrCommand *comm = FR_COMMAND (data);
FileData *fdata;
char **fields;
Expand Down Expand Up @@ -219,7 +218,6 @@ list__process_line_lzop(char *line,

// parse original file name
filename = g_strdup (get_last_field (line, 6));
printf("original_filename: %s\n", filename);
if (filename == NULL)
filename = remove_extension_from_path (comm->filename);

Expand Down Expand Up @@ -254,7 +252,95 @@ fr_command_cfile_list__lzop(FrCommand *comm)
comm);

fr_process_begin_command (comm->process, "lzop");
fr_process_add_arg (comm->process, "-lvN");
fr_process_add_arg (comm->process, "-lvN"); // list verbose and show original name
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
fr_process_start (comm->process);
}


/**
* Parse file size from xz which was generated by uint64_to_nicestr() function
* @param str_size e.g. "3454395"
* @param str_units "B", "KiB", "MiB", "GiB", "TiB"
* @return
*/
static goffset
parse_file_size (const gchar *str_size,
const gchar *str_units)
stokito marked this conversation as resolved.
Show resolved Hide resolved
{
gdouble size_in_units = g_ascii_strtod (str_size, NULL);
guint64 size_in_bytes = size_in_units;
static const char eci_suffixes[5][4] = { "B", "KiB", "MiB", "GiB", "TiB" };
for (int i = 0; i < 5; i++) {
if (strcmp (str_units, eci_suffixes[i]) == 0) {
return size_in_bytes;
}
size_in_bytes *= 1024.0;
}
return size_in_units;
}

/* Parse xz `xz -l file.txt.xz` output:
* Strms Blocks Compressed Uncompressed Ratio Check Filename
* 1 1 496.3 KiB 3,373.4 KiB 0.147 CRC64 file.txt.xz
*/
static void
list__process_line_xz (gchar *line,
gpointer data)
stokito marked this conversation as resolved.
Show resolved Hide resolved
{
// Skip first line.
// First line have a caption with "Strms" in first column
if (strncmp (line, "Strms ", 6) == 0)
return;

FrCommand *comm = FR_COMMAND (data);
FileData *fdata;
gchar **fields;
gchar *filename;

fdata = file_data_new ();

fields = split_line (line, 6);
const gchar *field_uncompressed_size = fields[4]; // e.g. "3454395"
const gchar *field_uncompressed_units = fields[5]; // e.g. "KiB"
fdata->size = parse_file_size (field_uncompressed_size, field_uncompressed_units);
g_strfreev (fields);

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);
}

/* xz let us known only the uncompressed size. To get it run:
* $ xz -l file.txt.xz
* Strms Blocks Compressed Uncompressed Ratio Check Filename
* 1 1 496.3 KiB 3,373.4 KiB 0.147 CRC64 file.txt.xz
*/
static void
fr_command_cfile_list__xz(FrCommand *comm)
{
fr_process_set_out_line_func (FR_COMMAND (comm)->process,
list__process_line_xz,
comm);

fr_process_begin_command (comm->process, "xz");
fr_process_add_arg (comm->process, "-l");
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
fr_process_start (comm->process);
Expand All @@ -267,10 +353,13 @@ fr_command_cfile_list (FrCommand *comm)
FrCommandCFile *comm_cfile = FR_COMMAND_CFILE (comm);

if (is_mime_type (comm->mime_type, "application/x-gzip")) {
fr_command_cfile_list__gzip(comm);
fr_command_cfile_list__gzip (comm);
}
else if (is_mime_type (comm->mime_type, "application/x-lzop")) {
fr_command_cfile_list__lzop(comm);
fr_command_cfile_list__lzop (comm);
}
else if (is_mime_type (comm->mime_type, "application/x-xz")) {
fr_command_cfile_list__xz (comm);
}
else {
/* ... other compressors do not support this feature so
Expand Down