MCPcopy Create free account
hub / github.com/ading2210/linuxpdf / fs_dump_cache_load

Function fs_dump_cache_load

tinyemu/fs_net.c:1825–1889  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1823}
1824
1825void fs_dump_cache_load(FSDevice *fs1, const char *cfg_filename)
1826{
1827 FSDeviceMem *fs = (FSDeviceMem *)fs1;
1828 JSONValue cfg, val, array;
1829 char *fname;
1830 const char *preload_dir, *name;
1831 int i;
1832
1833 if (!fs_is_net(fs1))
1834 return;
1835 cfg = json_load(cfg_filename);
1836 if (json_is_error(cfg)) {
1837 fprintf(stderr, "%s\n", json_get_error(cfg));
1838 exit(1);
1839 }
1840
1841 val = json_object_get(cfg, "preload_dir");
1842 if (json_is_undefined(cfg)) {
1843 config_error:
1844 exit(1);
1845 }
1846 preload_dir = json_get_str(val);
1847 if (!preload_dir) {
1848 fprintf(stderr, "expecting preload_filename\n");
1849 goto config_error;
1850 }
1851 fs->dump_preload_dir = strdup(preload_dir);
1852
1853 init_list_head(&fs->dump_preload_list);
1854 init_list_head(&fs->dump_exclude_list);
1855
1856 array = json_object_get(cfg, "preload");
1857 if (array.type != JSON_ARRAY) {
1858 fprintf(stderr, "expecting preload array\n");
1859 goto config_error;
1860 }
1861 for(i = 0; i < array.u.array->len; i++) {
1862 val = json_array_get(array, i);
1863 name = json_get_str(val);
1864 if (!name) {
1865 fprintf(stderr, "expecting a string\n");
1866 goto config_error;
1867 }
1868 fs_dump_add_file(&fs->dump_preload_list, name);
1869 }
1870 json_free(cfg);
1871
1872 fname = compose_path(fs->dump_preload_dir, "preload.txt");
1873 fs->dump_preload_file = fopen(fname, "w");
1874 if (!fs->dump_preload_file) {
1875 perror(fname);
1876 exit(1);
1877 }
1878 free(fname);
1879
1880 fname = compose_path(fs->dump_preload_dir, "preload_archive.txt");
1881 fs->dump_preload_archive_file = fopen(fname, "w");
1882 if (!fs->dump_preload_archive_file) {

Callers 1

mainFunction · 0.85

Calls 12

fs_is_netFunction · 0.85
json_loadFunction · 0.85
json_is_errorFunction · 0.85
json_get_errorFunction · 0.85
json_object_getFunction · 0.85
json_is_undefinedFunction · 0.85
json_get_strFunction · 0.85
init_list_headFunction · 0.85
json_array_getFunction · 0.85
fs_dump_add_fileFunction · 0.85
json_freeFunction · 0.85
compose_pathFunction · 0.70

Tested by

no test coverage detected