END_TEST /* --------------------------------------------------------------------------------------------- */ START_TEST (test_vfs_parse_ls_lga_reorder) { size_t filepos = 0; struct vfs_s_entry *ent1, *ent2, *ent3; int i; vfs_parse_ls_lga_init(); ent1 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); i = ent1->ino->st.st_nlink; if (! vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root1", &ent1->ino->st, &ent1->name, &ent1->ino->linkname, &filepos)) { fail ("An error occured while parse ls output"); return; } vfs_s_store_filename_leading_spaces (ent1, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent1); ent2 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); i = ent2->ino->st.st_nlink; if (! vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root2", &ent2->ino->st, &ent2->name, &ent2->ino->linkname, &filepos)) { fail ("An error occured while parse ls output"); return; } vfs_s_store_filename_leading_spaces (ent2, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent2); ent3 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); i = ent3->ino->st.st_nlink; if (! vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..", &ent3->ino->st, &ent3->name, &ent3->ino->linkname, &filepos)) { fail ("An error occured while parse ls output"); return; } vfs_s_store_filename_leading_spaces (ent3, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent3); vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ()); fail_unless(strcmp(ent1->name, " build_root1") == 0, "\nactual '%s'\nnot equal to '%s'\n", ent1->name, " build_root1"); fail_unless(strcmp(ent2->name, " build_root2") == 0, "\nactual '%s'\nnot equal to '%s'\n", ent2->name, " build_root2"); }
/* *INDENT-OFF* */ END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ /* @Test */ /* *INDENT-OFF* */ START_TEST (test_vfs_parse_ls_lga_reorder) /* *INDENT-ON* */ { /* given */ size_t filepos = 0; struct vfs_s_entry *ent1, *ent2, *ent3; vfs_parse_ls_lga_init (); /* init ent1 */ ent1 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root1", &ent1->ino->st, &ent1->name, &ent1->ino->linkname, &filepos); vfs_s_store_filename_leading_spaces (ent1, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent1); /* init ent2 */ ent2 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root2", &ent2->ino->st, &ent2->name, &ent2->ino->linkname, &filepos); vfs_s_store_filename_leading_spaces (ent2, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent2); /* init ent3 */ ent3 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..", &ent3->ino->st, &ent3->name, &ent3->ino->linkname, &filepos); vfs_s_store_filename_leading_spaces (ent3, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent3); /* when */ vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ()); /* then */ mctest_assert_str_eq (ent1->name, " build_root1"); mctest_assert_str_eq (ent2->name, " build_root2"); }
/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (test_vfs_parse_ls_lga, test_vfs_parse_ls_lga_ds) /* *INDENT-ON* */ { /* given */ size_t filepos = 0; struct stat etalon_stat; static struct stat test_stat; char *filename = NULL; char *linkname = NULL; gboolean actual_result; vfs_parse_ls_lga_init (); etalon_stat.st_blocks = 0; etalon_stat.st_size = 0; etalon_stat.st_mode = 0; fill_stat_struct (&etalon_stat, _i); /* when */ actual_result = vfs_parse_ls_lga (data->input_string, &test_stat, &filename, &linkname, &filepos); /* then */ mctest_assert_int_eq (actual_result, data->expected_result); mctest_assert_str_eq (filename, data->expected_filename); mctest_assert_str_eq (linkname, data->expected_linkname); mctest_assert_int_eq (etalon_stat.st_dev, test_stat.st_dev); mctest_assert_int_eq (etalon_stat.st_ino, test_stat.st_ino); mctest_assert_int_eq (etalon_stat.st_mode, test_stat.st_mode); mctest_assert_int_eq (etalon_stat.st_uid, test_stat.st_uid); mctest_assert_int_eq (etalon_stat.st_gid, test_stat.st_gid); mctest_assert_int_eq (etalon_stat.st_rdev, test_stat.st_rdev); mctest_assert_int_eq (etalon_stat.st_size, test_stat.st_size); mctest_assert_int_eq (etalon_stat.st_blksize, test_stat.st_blksize); mctest_assert_int_eq (etalon_stat.st_blocks, test_stat.st_blocks); /* FIXME: these commented checks are related to time zone! mctest_assert_int_eq (etalon_stat.st_atime, test_stat.st_atime); mctest_assert_int_eq (etalon_stat.st_mtime, test_stat.st_mtime); mctest_assert_int_eq (etalon_stat.st_ctime, test_stat.st_ctime); */ }
static void check_vfs_parse_ls_lga_call(const char *input_data, int etalon_result, const char *etalon_filename, const char *etalon_linkname, struct stat etalon_stat, size_t *filepos) { static struct stat test_stat; char *filename = NULL; char *linkname = NULL; gboolean result; result = vfs_parse_ls_lga (input_data, &test_stat, &filename, &linkname, filepos); fail_if (result != etalon_result, "\nactual result: %d\netalon result: %d\n", result, etalon_result); fail_unless((filename != NULL && etalon_filename != NULL && strcmp(filename, etalon_filename) == 0) || (filename == NULL && etalon_filename == filename), "\nactual filename '%s'\netalon filename '%s'", filename, etalon_filename); fail_unless((linkname != NULL && etalon_linkname != NULL && strcmp(linkname, etalon_linkname) == 0) || (linkname == NULL && etalon_linkname == linkname), "\nactual linkname '%s'\netalon linkname '%s'", linkname, etalon_linkname); check_stat_struct(etalon_stat, test_stat, input_data); }
static void process_ls_line (const char *line) { struct stat st; char *filename, *linkname; gboolean success; memset (&st, 0, sizeof st); filename = NULL; linkname = NULL; success = vfs_parse_ls_lga (line, &st, &filename, &linkname, NULL); if (!success) error_count++; if (opt_output_format == FORMAT_YAML) yaml_dump_record (success, line, &st, filename, linkname); else ls_dump_record (success, line, &st, filename, linkname); g_free (filename); g_free (linkname); }
/* * Main loop for reading an archive. * Return 0 on success, -1 on error. */ static int extfs_read_archive (int fstype, const char *name, struct archive **pparc) { FILE *extfsd; char *buffer; struct archive *current_archive; char *current_file_name, *current_link_name; if ((extfsd = extfs_open_archive (fstype, name, ¤t_archive)) == NULL) { message (1, MSG_ERROR, _("Cannot open %s archive\n%s"), extfs_prefixes[fstype], name); return -1; } buffer = g_malloc (4096); while (fgets (buffer, 4096, extfsd) != NULL) { struct stat hstat; current_link_name = NULL; if (vfs_parse_ls_lga (buffer, &hstat, ¤t_file_name, ¤t_link_name)) { struct entry *entry, *pent; struct inode *inode; char *p, *q, *cfn = current_file_name; if (*cfn) { if (*cfn == '/') cfn++; p = strchr (cfn, 0); if (p != cfn && *(p - 1) == '/') *(p - 1) = 0; p = strrchr (cfn, '/'); if (p == NULL) { p = cfn; q = strchr (cfn, 0); } else { *(p++) = 0; q = cfn; } if (S_ISDIR (hstat.st_mode) && (!strcmp (p, ".") || !strcmp (p, ".."))) goto read_extfs_continue; pent = extfs_find_entry (current_archive->root_entry, q, 1, 0); if (pent == NULL) { /* FIXME: Should clean everything one day */ g_free (buffer); pclose (extfsd); close_error_pipe (1, _("Inconsistent extfs archive")); return -1; } entry = g_new (struct entry, 1); entry->name = g_strdup (p); entry->next_in_dir = NULL; entry->dir = pent; if (pent->inode->last_in_subdir) { pent->inode->last_in_subdir->next_in_dir = entry; pent->inode->last_in_subdir = entry; } if (!S_ISLNK (hstat.st_mode) && current_link_name != NULL) { pent = extfs_find_entry (current_archive->root_entry, current_link_name, 0, 0); if (pent == NULL) { /* FIXME: Should clean everything one day */ g_free (buffer); pclose (extfsd); close_error_pipe (1, _("Inconsistent extfs archive")); return -1; } else { entry->inode = pent->inode; pent->inode->nlink++; } } else { inode = g_new (struct inode, 1); entry->inode = inode; inode->local_filename = NULL; inode->inode = (current_archive->inode_counter)++; inode->nlink = 1; inode->dev = current_archive->rdev; inode->archive = current_archive; inode->mode = hstat.st_mode; #ifdef HAVE_STRUCT_STAT_ST_RDEV inode->rdev = hstat.st_rdev; #else inode->rdev = 0; #endif inode->uid = hstat.st_uid; inode->gid = hstat.st_gid; inode->size = hstat.st_size; inode->mtime = hstat.st_mtime; inode->atime = hstat.st_atime; inode->ctime = hstat.st_ctime; inode->first_in_subdir = NULL; inode->last_in_subdir = NULL; if (current_link_name != NULL && S_ISLNK (hstat.st_mode)) { inode->linkname = current_link_name; current_link_name = NULL; } else { if (S_ISLNK (hstat.st_mode)) inode->mode &= ~S_IFLNK; /* You *DON'T* want to do this always */ inode->linkname = NULL; } if (S_ISDIR (hstat.st_mode)) extfs_make_dots (entry); } } read_extfs_continue: g_free (current_file_name); g_free (current_link_name); } } g_free (buffer); /* Check if extfs 'list' returned 0 */ if (pclose (extfsd) != 0) { extfs_free (current_archive); close_error_pipe (1, _("Inconsistent extfs archive")); return -1; } close_error_pipe (1, NULL); *pparc = current_archive; return 0; }