From 9e750b9b0552bb7e072e97a9f29eba7656f77444 Mon Sep 17 00:00:00 2001 From: Fufu Fang Date: Sun, 17 Nov 2024 23:50:05 +0000 Subject: [PATCH] added the option zero-len-is-dir --- src/config.c | 2 ++ src/config.h | 2 ++ src/link.c | 14 ++++++++++---- src/main.c | 5 +++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/config.c b/src/config.c index af20dbe..dd6adc2 100644 --- a/src/config.c +++ b/src/config.c @@ -49,6 +49,8 @@ void Config_init(void) CONFIG.no_range_check = 0; + CONFIG.zero_len_is_dir = 0; + CONFIG.insecure_tls = 0; CONFIG.refresh_timeout = DEFAULT_REFRESH_TIMEOUT; diff --git a/src/config.h b/src/config.h index dc7a4e5..f416c63 100644 --- a/src/config.h +++ b/src/config.h @@ -65,6 +65,8 @@ typedef struct { struct curl_slist *http_headers; /** \brief Disable check for the server's support of HTTP range request */ int no_range_check; + /** \brief Treat zero length file as directory */ + int zero_len_is_dir; /** \brief Disable TLS certificate verification */ int insecure_tls; /** \brief Server certificate file */ diff --git a/src/link.c b/src/link.c index 7a69ceb..e852072 100644 --- a/src/link.c +++ b/src/link.c @@ -452,7 +452,12 @@ void Link_set_file_stat(Link *this_link, CURL *curl) lprintf(error, "%s", curl_easy_strerror(ret)); } if (cl <= 0) { - this_link->type = LINK_INVALID; + if (CONFIG.zero_len_is_dir) { + this_link->type = LINK_DIR; + } else { + lprintf(info, "Zero length file: %s\n", this_link->f_url); + this_link->type = LINK_INVALID; + } } else { this_link->type = LINK_FILE; this_link->content_length = cl; @@ -1074,7 +1079,7 @@ long Link_download(Link *link, char *output_buf, size_t req_size, off_t offset) if (offset + req_size > link->content_length) { lprintf(info, - "requested size too larger than remaining size, req_size: %lu, recv: %ld, content-length: %ld\n", + "requested size larger than remaining size, req_size: %lu, recv: %ld, content-length: %ld\n", req_size, recv, link->content_length); req_size = link->content_length - offset; } @@ -1088,8 +1093,9 @@ long Link_download(Link *link, char *output_buf, size_t req_size, off_t offset) /* The extra 1 byte is probably for '\0' */ if (recv - 1 == (long int) req_size) { recv--; - } else if (offset + req_size < link->content_length) { - lprintf(error, "req_size: %lu, recv: %ld\n", req_size, recv); + } else { + lprintf(error, "req_size != recv, req_size: %lu, recv: %ld\n", + req_size, recv); } memmove(output_buf, ts.data, recv); diff --git a/src/main.c b/src/main.c index 2dde953..bc3fd85 100644 --- a/src/main.c +++ b/src/main.c @@ -225,6 +225,7 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc) { "refresh-timeout", required_argument, NULL, 'L' }, /* 25 */ { "http-header", required_argument, NULL, 'L' }, /* 26 */ { "cache-clear", no_argument, NULL, 'L' }, /* 27 */ + { "zero-len-is-dir", no_argument, NULL, 'L' }, /* 28 */ { 0, 0, 0, 0 } }; while ((c = @@ -339,6 +340,9 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc) case 27: CacheSystem_clear(); break; + case 28: + CONFIG.zero_len_is_dir = 1; + break; default: fprintf(stderr, "see httpdirfs -h for usage\n"); return 1; @@ -416,6 +420,7 @@ HTTPDirFS options:\n\ --user-agent Set user agent string (default: \"HTTPDirFS\")\n\ --no-range-check Disable the built-in check for the server's support\n\ for HTTP range requests\n\ + --zero-len-is-dir If a file has a zero length, treat it as a directory\n\ --insecure-tls Disable licurl TLS certificate verification by\n\ setting CURLOPT_SSL_VERIFYHOST to 0\n\ --single-file-mode Single file mode - rather than mounting a whole\n\