Ticket #3174: parse_ls_vga.c.patch
File parse_ls_vga.c.patch, 8.8 KB (added by slavazanko, 10 years ago) |
---|
-
lib/vfs/parse_ls_vga.c
diff --git a/lib/vfs/parse_ls_vga.c b/lib/vfs/parse_ls_vga.c index c102b7d..765047d 100644
a b vfs_parse_ls_lga (const char *p, struct stat * s, char **filename, char **linkna 687 687 return FALSE; 688 688 689 689 if (!vfs_parse_filetype (p, &skipped, &s->st_mode)) 690 goto error; 690 { 691 /* Microsoft FTP Server format: 692 * 11-29-14 11:30PM <DIR> 3 693 * 11-08-14 10:53PM 524148736 1 3.txt 694 */ 695 p_copy = g_strdup (p); 696 num_cols = vfs_split_text (p_copy); 697 if (num_cols < 4 || !vfs_parse_filedate (0, &s->st_mtime)) 698 goto error; 699 if (is_num(2)) 700 { 701 s->st_size = (off_t) g_ascii_strtoll (columns[2], NULL, 10); 702 s->st_mode |= S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IFREG; 703 } 704 else if(!strcmp (columns[2], "<DIR>")) 705 s->st_mode |= S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH | S_IFDIR; 706 else 707 goto error; 708 idx = 3; 709 if (num_spaces) 710 *num_spaces = 0; 711 goto OK; 712 } 691 713 p += skipped; 692 714 693 715 if (*p == ' ') /* Notwell 4 */ … … vfs_parse_ls_lga (const char *p, struct stat * s, char **filename, char **linkna 791 813 idx = vfs_parse_filedate (idx, &s->st_mtime); 792 814 if (!idx) 793 815 goto error; 794 /* Use resulting time value */795 s->st_atime = s->st_ctime = s->st_mtime;796 /* s->st_dev and s->st_ino must be initialized by vfs_s_new_inode () */797 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE798 s->st_blksize = 512;799 #endif800 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS801 s->st_blocks = (s->st_size + 511) / 512;802 #endif803 816 804 817 if (num_spaces != NULL) 805 818 { … … vfs_parse_ls_lga (const char *p, struct stat * s, char **filename, char **linkna 831 844 } 832 845 else 833 846 { 847 OK: 834 848 /* Extract the filename from the string copy, not from the columns 835 849 * this way we have a chance of entering hidden directories like ". ." 836 850 */ … … vfs_parse_ls_lga (const char *p, struct stat * s, char **filename, char **linkna 847 861 *linkname = NULL; 848 862 } 849 863 864 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE 865 s->st_blksize = 512; 866 #endif 867 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS 868 s->st_blocks = (s->st_size + 511) / 512; 869 #endif 870 /* Use resulting time value */ 871 s->st_atime = s->st_ctime = s->st_mtime; 872 /* s->st_dev and s->st_ino must be initialized by vfs_s_new_inode () */ 873 850 874 if (t) 851 875 { 852 876 int p2 = strlen (t); -
tests/lib/vfs/vfs_parse_ls_lga.c
diff --git a/tests/lib/vfs/vfs_parse_ls_lga.c b/tests/lib/vfs/vfs_parse_ls_lga.c index 1751e18..2d3f324 100644
a b fill_stat_struct (struct stat *etalon_stat, int iterator) 111 111 switch (iterator) 112 112 { 113 113 case 0: 114 case 2: 115 case 3: 114 116 etalon_stat->st_dev = 0; 115 117 etalon_stat->st_ino = 0; 116 118 etalon_stat->st_mode = 0x41fd; … … fill_stat_struct (struct stat *etalon_stat, int iterator) 140 142 etalon_stat->st_mtime = 1268431200; 141 143 etalon_stat->st_ctime = 1268431200; 142 144 break; 143 case 2: 144 etalon_stat->st_dev = 0; 145 etalon_stat->st_ino = 0; 146 etalon_stat->st_mode = 0x41fd; 147 etalon_stat->st_nlink = 10; 148 etalon_stat->st_uid = 500; 149 etalon_stat->st_gid = 500; 145 case 4: 146 etalon_stat->st_mode = 0040755; 147 etalon_stat->st_nlink = 1; 148 etalon_stat->st_uid = 0; 149 etalon_stat->st_gid = 0; 150 150 etalon_stat->st_rdev = 0; 151 etalon_stat->st_size = 4096;151 etalon_stat->st_size = 0; 152 152 etalon_stat->st_blksize = 512; 153 etalon_stat->st_blocks = 8;154 etalon_stat->st_atime = 1 308838140;155 etalon_stat->st_mtime = 1 308838140;156 etalon_stat->st_ctime = 1 308838140;153 etalon_stat->st_blocks = 0; 154 etalon_stat->st_atime = 1268431200; 155 etalon_stat->st_mtime = 1268431200; 156 etalon_stat->st_ctime = 1268431200; 157 157 break; 158 case 3: 159 etalon_stat->st_dev = 0; 160 etalon_stat->st_ino = 0; 161 etalon_stat->st_mode = 0x41fd; 162 etalon_stat->st_nlink = 10; 163 etalon_stat->st_uid = 500; 164 etalon_stat->st_gid = 500; 158 case 5: 159 etalon_stat->st_mode = 0100644; 160 etalon_stat->st_nlink = 1; 161 etalon_stat->st_uid = 0; 162 etalon_stat->st_gid = 0; 165 163 etalon_stat->st_rdev = 0; 166 etalon_stat->st_size = 4096;164 etalon_stat->st_size = 524148736; 167 165 etalon_stat->st_blksize = 512; 168 etalon_stat->st_blocks = 8;169 etalon_stat->st_atime = 1 308838140;170 etalon_stat->st_mtime = 1 308838140;171 etalon_stat->st_ctime = 1 308838140;166 etalon_stat->st_blocks = 1023728; 167 etalon_stat->st_atime = 1268431200; 168 etalon_stat->st_mtime = 1268431200; 169 etalon_stat->st_ctime = 1268431200; 172 170 break; 173 171 } 174 172 } … … static const struct test_vfs_parse_ls_lga_ds 214 212 NULL, 215 213 0 216 214 }, 215 { /* 4. */ 216 "11-29-14 11:30PM <DIR> 3", 217 1, 218 "3", 219 NULL, 220 0 221 }, 222 { /* 5. */ 223 "11-08-14 10:53PM 524148736 1 3.txt", 224 1, 225 "1 3.txt", 226 NULL, 227 0 228 } 217 229 }; 218 230 /* *INDENT-ON* */ 219 231 … … END_PARAMETRIZED_TEST 270 282 271 283 /* --------------------------------------------------------------------------------------------- */ 272 284 285 #define init_ent(ent, ls_output) \ 286 ent = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); \ 287 vfs_parse_ls_lga (ls_output \ 288 , &ent->ino->st, &ent->name, &ent->ino->linkname, &filepos); \ 289 vfs_s_store_filename_leading_spaces (ent, filepos); \ 290 vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent); 291 273 292 /* @Test */ 274 293 /* *INDENT-OFF* */ 275 294 START_TEST (test_vfs_parse_ls_lga_reorder) … … START_TEST (test_vfs_parse_ls_lga_reorder) 277 296 { 278 297 /* given */ 279 298 size_t filepos = 0; 280 struct vfs_s_entry *ent1, *ent2, *ent3 ;299 struct vfs_s_entry *ent1, *ent2, *ent3, *ent4, *ent5; 281 300 282 301 vfs_parse_ls_lga_init (); 283 302 284 /* init ent1 */ 285 ent1 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); 286 vfs_parse_ls_lga 287 ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root1", &ent1->ino->st, 288 &ent1->name, &ent1->ino->linkname, &filepos); 289 vfs_s_store_filename_leading_spaces (ent1, filepos); 290 vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent1); 291 292 293 /* init ent2 */ 294 ent2 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); 295 vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root2", 296 &ent2->ino->st, &ent2->name, &ent2->ino->linkname, &filepos); 297 vfs_s_store_filename_leading_spaces (ent2, filepos); 298 vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent2); 299 300 /* init ent3 */ 301 ent3 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); 302 vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..", 303 &ent3->ino->st, &ent3->name, &ent3->ino->linkname, &filepos); 304 vfs_s_store_filename_leading_spaces (ent3, filepos); 305 vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent3); 303 init_ent (ent1, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root1"); 304 init_ent (ent2, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root2"); 305 init_ent (ent3, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 .."); 306 init_ent (ent4, test_vfs_parse_ls_lga_ds[4].input_string); 307 init_ent (ent5, test_vfs_parse_ls_lga_ds[5].input_string); 306 308 307 309 /* when */ 308 310 vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ()); … … START_TEST (test_vfs_parse_ls_lga_unaligned) 336 338 { 337 339 /* given */ 338 340 size_t filepos = 0; 339 struct vfs_s_entry *ent[ 4];341 struct vfs_s_entry *ent[6]; 340 342 341 343 vfs_parse_ls_lga_init (); 342 344 … … START_TEST (test_vfs_parse_ls_lga_unaligned) 345 347 parce_one_line (2, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 .."); 346 348 parce_one_line (3, 347 349 "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root 0"); 350 parce_one_line (4, "11-29-14 11:30PM <DIR> 3"); 351 parce_one_line (5, "11-08-14 10:53PM 524148736 1 3.txt"); 352 348 353 349 354 /* when */ 350 355 vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ()); … … START_TEST (test_vfs_parse_ls_lga_unaligned) 354 359 mctest_assert_str_eq (ent[0]->name, "build_root1"); 355 360 mctest_assert_str_eq (ent[1]->name, " build_root2"); 356 361 mctest_assert_str_eq (ent[3]->name, " build_root 0"); 362 mctest_assert_str_eq (ent[4]->name, "3"); 363 mctest_assert_str_eq (ent[5]->name, "1 3.txt"); 357 364 } 358 365 /* *INDENT-OFF* */ 359 366 END_TEST