Mercurial > gftp.yaz
comparison lib/protocols.c @ 850:1c8d6b6b7950
2006-11-16 Brian Masney <masneyb@gftp.org>
* lib/protocols.c - skip over the hidden files when doing a recursive
transfer if the shown_hidden_files option is disabled. (closes #321573)
author | masneyb |
---|---|
date | Fri, 17 Nov 2006 01:20:58 +0000 |
parents | 8263cc35c027 |
children | 83d39217749c |
comparison
equal
deleted
inserted
replaced
849:0cf4d8c46b82 | 850:1c8d6b6b7950 |
---|---|
1859 | 1859 |
1860 | 1860 |
1861 static GHashTable * | 1861 static GHashTable * |
1862 gftp_gen_dir_hash (gftp_request * request, int *ret) | 1862 gftp_gen_dir_hash (gftp_request * request, int *ret) |
1863 { | 1863 { |
1864 intptr_t show_hidden_files; | |
1864 GHashTable * dirhash; | 1865 GHashTable * dirhash; |
1865 gftp_file * fle; | 1866 gftp_file * fle; |
1866 off_t *newsize; | 1867 off_t *newsize; |
1867 | 1868 |
1869 *ret = gftp_list_files (request); | |
1870 if (*ret != 0) | |
1871 return (NULL); | |
1872 | |
1868 dirhash = g_hash_table_new (string_hash_function, string_hash_compare); | 1873 dirhash = g_hash_table_new (string_hash_function, string_hash_compare); |
1869 *ret = gftp_list_files (request); | 1874 gftp_lookup_request_option (request, "show_hidden_files", &show_hidden_files); |
1870 if (*ret == 0) | 1875 |
1871 { | 1876 fle = g_malloc0 (sizeof (*fle)); |
1872 fle = g_malloc0 (sizeof (*fle)); | 1877 while (gftp_get_next_file (request, NULL, fle) > 0) |
1873 while (gftp_get_next_file (request, NULL, fle) > 0) | 1878 { |
1874 { | 1879 if (!show_hidden_files && *fle->file == '.' && |
1875 newsize = g_malloc (sizeof (*newsize)); | 1880 strcmp (fle->file, "..") != 0) |
1876 *newsize = fle->size; | 1881 { |
1877 g_hash_table_insert (dirhash, fle->file, newsize); | |
1878 fle->file = NULL; | |
1879 gftp_file_destroy (fle, 0); | 1882 gftp_file_destroy (fle, 0); |
1880 } | 1883 continue; |
1881 gftp_end_transfer (request); | 1884 } |
1882 g_free (fle); | 1885 |
1883 } | 1886 newsize = g_malloc (sizeof (*newsize)); |
1884 else | 1887 *newsize = fle->size; |
1885 { | 1888 g_hash_table_insert (dirhash, fle->file, newsize); |
1886 g_hash_table_destroy (dirhash); | 1889 fle->file = NULL; |
1887 dirhash = NULL; | 1890 gftp_file_destroy (fle, 0); |
1888 } | 1891 } |
1892 | |
1893 gftp_end_transfer (request); | |
1894 g_free (fle); | |
1889 | 1895 |
1890 return (dirhash); | 1896 return (dirhash); |
1891 } | 1897 } |
1892 | 1898 |
1893 | 1899 |
1912 | 1918 |
1913 | 1919 |
1914 static GList * | 1920 static GList * |
1915 gftp_get_dir_listing (gftp_transfer * transfer, int getothdir, int *ret) | 1921 gftp_get_dir_listing (gftp_transfer * transfer, int getothdir, int *ret) |
1916 { | 1922 { |
1923 intptr_t show_hidden_files; | |
1917 GHashTable * dirhash; | 1924 GHashTable * dirhash; |
1918 GList * templist; | 1925 GList * templist; |
1919 gftp_file * fle; | 1926 gftp_file * fle; |
1920 off_t *newsize; | 1927 off_t *newsize; |
1921 char *newname; | 1928 char *newname; |
1922 | 1929 |
1930 gftp_lookup_request_option (transfer->fromreq, "show_hidden_files", | |
1931 &show_hidden_files); | |
1932 | |
1923 if (getothdir && transfer->toreq != NULL) | 1933 if (getothdir && transfer->toreq != NULL) |
1924 { | 1934 { |
1925 dirhash = gftp_gen_dir_hash (transfer->toreq, ret); | 1935 dirhash = gftp_gen_dir_hash (transfer->toreq, ret); |
1926 if (*ret == GFTP_EFATAL) | 1936 if (*ret == GFTP_EFATAL) |
1927 return (NULL); | 1937 return (NULL); |
1938 | 1948 |
1939 fle = g_malloc (sizeof (*fle)); | 1949 fle = g_malloc (sizeof (*fle)); |
1940 templist = NULL; | 1950 templist = NULL; |
1941 while (gftp_get_next_file (transfer->fromreq, NULL, fle) > 0) | 1951 while (gftp_get_next_file (transfer->fromreq, NULL, fle) > 0) |
1942 { | 1952 { |
1943 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0) | 1953 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0 || |
1954 (!show_hidden_files && *fle->file == '.')) | |
1944 { | 1955 { |
1945 gftp_file_destroy (fle, 0); | 1956 gftp_file_destroy (fle, 0); |
1946 continue; | 1957 continue; |
1947 } | 1958 } |
1948 | 1959 |