Skip to content

Commit

Permalink
added the option zero-len-is-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
fangfufu committed Nov 17, 2024
1 parent 43569de commit 9e750b9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 10 additions & 4 deletions src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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\
Expand Down

0 comments on commit 9e750b9

Please sign in to comment.